BusinessMCP

Claude Code Settings Files Expose Secrets in Public Repositories

Approved shell commands containing credentials can be stored in Claude Code’s local settings files. Separate scans found thousands of exposed secrets on GitHub and hundreds in public Docker Hub images.

BusinessMCP Newsroom4 min read
Close-up of computer code displayed in multiple colors on a black screen.
Image: Lorenzo Cafaro / stocksnap via Openverse (CC0)

Key takeaways

  • Claude Code can save exact approved shell commands, including embedded credentials, in `.claude/settings.local.json`.
  • GitGuardian found 31,088 distinct secrets across 23,276 public GitHub repositories; Apiiro separately found 1,122 public file copies containing at least one secret.
  • Docker Hub images can expose the same settings files when builds copy project directories without an appropriate `.dockerignore`.
  • Rotation should precede cleanup, because credentials can remain in Git history, forks and published images.

Developers and teams that approve Claude Code commands containing passwords, API keys, database credentials or other tokens may be storing those secrets in project settings files that later become public (CSO Online). Claude Code’s “Yes, and don’t ask again” option can save the full approved command, including credentials, in `.claude/settings.local.json`, according to CSO.

Claude Code stores approved command strings

Command approval normally occurs before Claude Code runs most shell commands. When a developer chooses the persistent-approval option, the tool creates an allow rule in the project-level settings file. If the approved command is an exact command rather than a pattern, the saved rule can contain the credential itself. A command such as an API request with a key in its HTTP header therefore leaves that key in the settings file.

BeforeAfter
Claude Code asks for approval before running a shell commandSelecting “Yes, and don’t ask again” creates an allow rule in `.claude/settings.local.json`
A command may contain a password, token or API keyAn exact approved command can be stored word-for-word, including the secret
The file is added to local Git exclusion settingsThe exclusion does not necessarily travel to another machine, repository or container build context

The file is intended to remain out of version control, but that protection is not consistent across repositories. Claude Code adds it to the user’s global Git excludes on the computer where it writes the file, rather than adding it to the project’s own `.gitignore`. A file that was already committed, or a file copied into another working directory, can therefore be published accidentally.

Two scans found different public exposure totals

GitGuardian identified 31,088 distinct secrets in `.claude/settings.local.json` files across 23,276 public GitHub repositories, with 5,343 still valid when detected, CSO reported. The scan covered database connection strings, cloud-provider tokens, SSH passwords, Google API keys and AU service credentials. GitGuardian also found that 67% of occurrences for which validity could be established were working credentials; database identifiers were the largest category, with 2,280 distinct valid credentials.

In a separate investigation, The Hacker News reported that Apiiro found 104,185 public copies of the file in 103,617 repositories. Of those, 1,122 copies contained at least one secret, representing 1,379 different secrets. Apiiro did not test whether those secrets still worked, although one company it notified confirmed that its key had been live. InfoWorld described the GitGuardian results and the Docker exposure in its account of the issue.

The two totals reflect different searches and inclusion rules, rather than a single agreed count. Apiiro’s broader total of 2,539 secrets across 1,994 repositories included older versions, forks, the shared `.claude/settings.json` file and saved agent chat logs. Its investigation also found 211 forks of 74 repositories carrying the same secrets as the originals, while 298 of 76,011 copies of the shared settings file contained secrets.

“Monthly leaks in settings.local.json peaked at 12,535 occurrences in April 2026, then fell to 959 by October, and we do not yet know what changed,” — Guillaume Valadon, GitGuardian researcher

Docker images carry a separate exposure path

GitGuardian found 613 distinct secrets in Claude Code settings files across 543 public Docker Hub image repositories and 7,625 tags; 99 were valid when detected. Docker does not automatically respect a repository’s `.gitignore` file. If a build uses Docker’s `COPY` instruction to copy the whole project directory, the Claude Code settings file can enter an image unless it is explicitly excluded through `.dockerignore`.

One valid Cloudflare API token appeared across 559 image tags. A database password appeared in 643 tags across seven image repositories. Removing the file from GitHub does not remove copies already distributed in published images, so teams must check image histories and build contexts separately from repository history.

The cleanup order starts with rotation

For developers using Claude Code, the researchers’ recommended sequence is to search repositories and organization accounts for `.claude/settings.local.json` and `.claude/settings.json`, inspect Git history even when the current files are gone, and rotate every password, token or key that those files have held. Removing a current file alone does not invalidate credentials that remain in commits, forks or images.

Teams should then stop tracking the local file, add it to the repository’s own `.gitignore`, and remove secrets from saved allow rules. The developer-tools guide is relevant to teams that want to review the configuration files created by coding assistants alongside other development assets. GitGuardian also recommends using environment variables instead of hardcoding credentials in commands, because a variable name is safer to store in an approval rule than the credential itself.

Anthropic did not immediately respond to CSO’s request for comment. GitGuardian said Claude Code lead Boris Cherny acknowledged the issue and that the company was looking into additional safeguards, including built-in secret scanning and an auto mode.

Sources

All news