Claude Code GitHub Secret Leak: How to Check Your Repositories and Protect Your API Keys
A small convenience feature in Claude Code may have exposed sensitive credentials in thousands of GitHub repositories. The issue centers on the “Yes, and don’t ask again” option, which lets developers permanently approve shell commands. While useful, that approval could save the entire command into a local settings file, including any passwords, tokens, API keys, database credentials, or SSH details included in the command.
Anthropic released an update on November 12 to reduce the risk for new approvals, but the fix does not remove secrets that were already saved or pushed to GitHub. If you use Claude Code, now is the time to check your repositories, rotate exposed credentials, and clean up your Git history properly.
How Claude Code credentials ended up on GitHub
Claude Code asks for approval before running shell commands. When a developer chooses to permanently allow a command, Claude Code stores that rule in this file:
.claude/settings.local.json
The problem is that older versions saved the full command exactly as approved. If a developer approved a command containing a secret, such as a database password in a psql command or an API key in a curl request, that secret was written to the settings file in plain text.
The file was intended to remain local. Claude Code attempted to protect it by adding it to the user’s global Git excludes file. However, that protection only applied to the developer’s own machine. It did not automatically follow the repository to another computer, a CI environment, or a teammate’s setup. As a result, many developers unknowingly committed and pushed the file to GitHub.
The scale of the Claude Code settings.local.json leak
Security researchers found that the issue was far from isolated. A large scan of GitHub repositories found more than 31,000 distinct secrets inside Claude Code settings files across more than 23,000 repositories.
More concerning, thousands of those exposed credentials were still valid when discovered. The leaks included database passwords, cloud access keys, API tokens, and other sensitive command-line secrets.
The number of exposed secrets reportedly peaked in April 2026, then declined in later months. However, the risk remains because removing the file from a repository does not erase it from Git history, forks, cached copies, package releases, or container images.
What Anthropic changed in Claude Code version 2.1.323
Anthropic addressed the issue in Claude Code version 2.1.323, released on November 12. According to the release notes, if a “don’t ask again” approval appears to contain a secret, or if it would be saved to a settings.local.json file tracked by Git, Claude Code now keeps the rule for the current session only instead of saving it permanently.
The update also improves how the file is ignored when a folder later becomes a Git repository or is used on a new machine.
However, this update does not remove secrets that were already saved in existing settings files. It also does not revoke exposed credentials. If a secret was pushed to GitHub, it should be treated as compromised.
To check your Claude Code version, run:
claude –version
To update Claude Code, run:
claude update
How to check if your GitHub repositories are affected
The fastest place to start is GitHub code search. Search your personal account or organization for Claude Code settings files.
For a personal account, search:
path:.claude/settings.local.json user:YOURNAME
For an organization, search:
path:.claude/settings.local.json org:YOURORG
You should also search for the shared settings file:
path:.claude/settings.json
Although settings.local.json is the main concern, secrets have also been found in settings.json files.
GitHub code search only shows the current state of a repository. That is not enough. A file may have been deleted from the latest version while still remaining in the commit history.
To check the full Git history of a repository, clone it locally and run:
git log –all –full-history — .claude/settings.local.json
If any commits appear, inspect the old versions of the file carefully. Look for passwords, tokens, keys, database URLs, cloud credentials, and any commands that include authentication details.
Secret scanning tools can help, but do not rely on them alone
Tools such as Gitleaks and TruffleHog can scan repository history for exposed credentials. For example, you can run:
gitleaks git .
These tools are useful, but they may miss secrets embedded inside ordinary command lines. A password passed into a database command may not always match a known API key pattern. Some scanning modes also focus on verified secrets, which can cause generic passwords to be skipped.
GitHub also scans public repositories for many known token and key formats, including repository history. Push protection can block certain secrets before they are uploaded. However, generic passwords are harder to detect reliably, and the absence of an alert does not guarantee that nothing leaked.
What to do if you find a secret in .claude/settings.local.json
The most important step is to rotate the credential first. Do not start by deleting the file. If a secret was public, assume it was copied.
Replace exposed credentials in this order:
First, revoke or rotate active API keys and access tokens.
Next, change database passwords and application secrets.
Then, replace SSH keys if they appeared in the file.
Finally, review logs for suspicious activity connected to the exposed credentials.
Only after the old secrets are revoked should you focus on repository cleanup.
Deleting the file is not enough
If .claude/settings.local.json was committed, simply deleting it from the latest commit does not remove it from the repository’s history. Anyone with access to the old commit can still retrieve it. Forks and local clones may also preserve the file.
To remove the file from Git history, GitHub recommends using git-filter-repo. A typical cleanup command looks like this:
git filter-repo –sensitive-data-removal –invert-paths –path .claude/settings.local.json
After rewriting history, you will need to force push the cleaned repository. Be careful: rewriting history can disrupt collaborators, open pull requests, and forks. Coordinate with your team before doing this.
After cleaning history, remove the file from version control if it is currently tracked:
git rm –cached .claude/settings.local.json
Then add it to the project’s .gitignore file:
.claude/settings.local.json
Confirm that Git is ignoring it:
git check-ignore -v .claude/settings.local.json
If your project publishes packages or container images, also exclude the file from those build outputs. Add it to .npmignore for npm packages and .dockerignore for Docker images.
Best practices to prevent future AI coding assistant secret leaks
The safest rule is simple: never put passwords, tokens, or private keys directly into commands that an AI coding agent may save, repeat, or approve permanently.
Use environment variables instead of inline secrets. For example, avoid commands that include a password directly. Store the value in an environment variable or a secure password manager and reference it indirectly.
Prefer narrow approval rules. Instead of permanently approving a full command containing sensitive values, approve a safer pattern such as:
Bash(npm run test:*)
Avoid approving broad command patterns that could allow unexpected behavior.
Review agent-generated files before committing. AI coding tools can create configuration files, permission files, logs, and local settings that developers may not notice before pushing.
Add sensitive assistant files to .gitignore at the project level, not just global Git excludes. Project-level ignores travel with the repository and help protect teammates, CI systems, and new development machines.
Watch other AI coding tools too
This issue is not limited to Claude Code. Other AI coding assistants also store command approvals, permissions, or rules in local or project-level files.
OpenAI Codex stores user-level rules in:
~/.codex/rules/default.rules
Cursor supports per-project permission files, and teams may choose to commit those files so everyone shares the same rules. That can be useful, but it also means anything sensitive inside the file may be published with the next push.
GitHub Copilot, Gemini CLI, and other coding assistants have their own approval and configuration systems. Developers should understand where each tool stores trusted commands and whether those files can accidentally become part of a repository.
The key takeaway
If you used Claude Code’s “don’t ask again” feature before version 2.1.323, check your repositories now. Search for .claude/settings.local.json, inspect Git history, rotate any exposed credentials, and remove sensitive files from version control.
The update helps prevent new leaks, but it cannot undo secrets already pushed to GitHub. Treat every exposed credential as compromised, replace it immediately, and make sure AI coding assistant settings files are excluded from future commits.






