SIAgentNews.com
← All news
DevelopingClaudeSecurity

Claude Code exposes secrets in public repositories via local settings

A security flaw in Claude Code's 'Don't Ask Again' feature allows sensitive credentials to be leaked into public git histories and local files.

· First reported by Infoq

Photo-style picture of a wrought iron fence for the story 'Claude Code exposes secrets in public repositories via local...'
AI-made picture for this story. No real people or products are shown.
31,088secrets found in Claude Code files on public GitHub

The short version

  • Claude Code saves 'Don't Ask Again' permissions to a local .claude/settings.local.json file.
  • The file can contain embedded credentials, production passwords, and cloud API keys from shell commands.
  • Research identified 31,088 secrets in these files on public GitHub, with 5,343 still valid.
  • Standard secret scanners often miss these leaks because the secrets are embedded inside shell commands.
  • Apiiro recommends using environment variables instead of typing secrets directly into commands.

Why it matters

This highlights a fundamental security gap in how AI agents handle user permissions. For developers, it means that a simple convenience feature could inadvertently create a roadmap for attackers to access production systems.

The 'Don't Ask Again' leak

Anthropic's Claude Code tool includes a feature designed to streamline developer workflows by remembering permissions. When a user approves a shell command and selects the 'Don't Ask Again' option, the tool saves that permission as a permanent rule. This rule is stored in a local configuration file located at .claude/settings.local.json on the developer's machine.

The security issue arises because these saved rules often contain the full text of the original command. If a developer runs a command that includes a password, an API token, or a production secret, that sensitive information becomes a permanent entry in the configuration file. Because the tool treats these as permissions, the secrets are written into the file in plain text for the system to reference later.

As infoq.com reported, researchers from Apiiro discovered that this mechanism creates a significant security vulnerability. The tool effectively creates a centralized list of systems a developer can reach and the specific passwords required to open them. This file is stored at a predictable path in every project, making it an easy target for any malware that gains access to the local environment.

How secrets reach the public

While Claude Code attempts to protect these local files by adding them to a developer's global git ignore list, this protection is often incomplete. The tool does not automatically add the file to a specific project's .gitignore. This means if a folder is converted into a repository after the file is created, or if a project is cloned to a new machine, the file can be included in the repository structure.

In some instances, the researchers found that Claude Code itself committed the configuration file to the repository. This happens when the file is already present or when the tool's automated actions move it into a tracked state. Once the file is committed, the secrets are preserved in the git history, making them accessible to anyone with access to the repository, including the public.

The scope of the exposure is significant, with 63 organizations identified as affected by these leaks. The exposed data included a variety of sensitive items, such as cloud API keys, production passwords, and npm tokens. These credentials provide direct access to internal infrastructure and private software packages, posing a high risk for unauthorized access.

Failure of standard scanners

A major complication for security teams is that generic secret scanners, such as gitleaks or TruffleHog, often fail to detect these specific leaks. These tools are typically tuned to look for standard key formats like 'AWS_SECRET_KEY' in standalone files or environment variables. However, in this case, the secrets are embedded inside the strings of shell commands within the configuration file.

Because the secrets are part of a command sequence rather than a dedicated configuration line, many scanners simply overlook them. This pattern of 'password-in-a-command' also appears in other agent-related files, including transcripts, memory files, and handoff notes. If a scanner is not specifically tuned to recognize these embedded patterns, the secrets remain hidden from automated security audits.

The research highlights a broader trend where AI tools may be ignoring basic cybersecurity principles in favor of user experience. By recording exactly what an agent ran to provide a history of actions, the tools inadvertently create a trail of sensitive data. This creates a situation where the very logs meant to provide transparency for the AI's actions become a liability for the organization's security.

Remediation and best practices

To mitigate these risks, researchers suggest that developers take immediate action to clean up their existing repositories. They recommend using the command 'git rm --cached .claude/settings.local.json' to stop tracking the file and then manually adding it to the project's .gitignore. This ensures that the file is no longer included in future commits or shared with other team members.

Furthermore, any organization that discovers a secret in these files must rotate the credentials immediately. Because the secrets are now part of the git history, simply deleting the file is not enough to secure the system. The old keys and passwords must be invalidated so that they can no longer be used by anyone who might have accessed the public repository.

For a more robust long-term solution, developers should avoid typing secrets directly into any command line prompt. Instead, they should use environment variables to inject sensitive information into their workflows. This practice ensures that the AI agent only sees the variable name rather than the actual secret value. By following this approach, developers can maintain the convenience of the 'Don't Ask Again' feature without exposing their infrastructure to the public.

What to watch

  • Whether Anthropic will release a patch to automatically include this file in .gitignore
  • How other AI agents like Cursor or GitHub Copilot handle persistent shell permissions

Try it

Check your project folders for a .claude directory and run 'git ls-files .claude/settings.local.json' to see if the file is currently being tracked by git.

Sources and links

Written by the SI Agent News Desk from the reporting above.Written with AI from the source above. Every number is checked against the source. Spot a mistake? Corrections.

Liked it? Say why

Add a line for other readers.

No account needed. We never show your email. Comments with links, ads or abuse are held and not shown. Your comment shows after a quick check.

More AI news