Claude Code's settings.local.json can hold your API keys in plain text: how to check and clean it
· PlugLeak
Claude Code can save an approved shell command, inline API key included, in .claude/settings.local.json. How to grep the file, rotate the key, keep it out of git, and what a live-URL scan cannot see.
.claude/settings.local.json is Claude Code's project-local settings file. A standing approval for a shell command is saved there as an allow rule (Settings). The settings and permissions docs describe that save. They do not describe a step that strips a secret out of the command text.
The Hacker News (7 November 2026), reporting Apiiro's research, says that when the prompt offered one exact command, a password or token typed into it was stored in plain text. The counts in this guide are the ones The Hacker News published from that research.
What the file is, and where it lives
Claude Code has separate settings files. The project-local one applies to you, in this project only (Settings files and precedence):
| File | Who it affects |
|---|---|
~/.claude/settings.json | You, in every project on this machine. On Windows, ~/.claude is %USERPROFILE%\.claude. |
.claude/settings.json | Everyone working in the project, once it is committed. This is the shared team file. |
.claude/settings.local.json | You, in this one project. Personal overrides, and the file Claude Code writes when you give a standing approval. |
In a git repository, Claude Code reads and writes .claude/settings.local.json at the repository root, including when you start it in a subdirectory. A worktree uses the file at the main checkout's root. The same page lists cases where the file stays next to .claude/settings.json instead: outside a git repository, when the repository root is your home directory, on Windows, or when the repository root or its .git or .claude entry is not owned by your user.
Before v2.1.211, Claude Code kept the file in the directory where the session started. It still reads a copy an older version left there, alongside the root file. Check both paths if you have used Claude Code in a subdirectory.
Installing Claude Code does not create the file. It is written the first time you give a standing approval, such as "Yes, and don't ask again" for a Bash command. A few /config options, including Show tips, also save there.
How an approved command lands in the file
By default, Claude Code asks before it runs a Bash command that is not in its built-in read-only set. Choosing "Yes, and don't ask again" saves an allow rule in .claude/settings.local.json. Later sessions in that repository run a matching command without asking (Configure permissions).
The rule covers what the prompt offered. A rule with no * matches one exact command, written as Bash(…). A * matches any text in its place, so Bash(npm run *) is a pattern for a family of commands. The permission dialog writes that space-separated form when you approve a command prefix. When you approve a compound command, Claude Code saves a separate rule for each subcommand that needed approval, up to five.
The settings and permissions pages do not say that Claude Code removes a secret from the text it saves. The Hacker News, reporting Apiiro, says the researchers found saved commands that still contained the secret, and that they reproduced the behavior: when the prompt offered one exact command, a password or token typed into it was saved in plain text. A pattern such as npm test * is the other case, and that pattern need not contain a key.
An approval of a command like this is the exact-command case:
curl -H "Authorization: Bearer sk-..." https://api.example.com/v1/modelsThe permissions docs write an exact command as Bash(the command). With the report above, the saved rule has this shape. The block is an illustration. sk-... is a placeholder.
{
"permissions": {
"allow": [
"Bash(curl -H \"Authorization: Bearer sk-...\" https://api.example.com/v1/models)"
]
}
}In the CLI, Claude Code writes that rule to your local file. In the VS Code extension, the approval card lets you pick the destination file, including the project's shared .claude/settings.json, which is the file teams commit (Settings).
What The Hacker News reported
The Hacker News, citing Apiiro's write-up, reported a search of public GitHub: 104,185 copies of .claude/settings.local.json in 103,617 repositories. About 1.1% of them, 1,122 copies, held at least one secret, 1,379 distinct secrets in total.
A value counted as a secret when it matched a known key format, or when a password or token sat beside the address of a public server, and an AI reviewer also agreed. Apiiro did not test whether the secrets still worked. The Hacker News says the researchers do not claim anyone has used them, and that one company they notified confirmed its key had been live.
The same article says older versions of the file held 734 more secrets across 509 repositories that no longer have them in the current copy, and that 298 of 76,011 public copies of the shared .claude/settings.json also held secrets, mostly inside allow rules. Including history, the shared file, and saved agent chat logs, the reported total is 2,539 secrets across 1,994 repositories. Those figures are Apiiro's, as The Hacker News reported them.
The article also says that in 539 of 1,105 repositories the researchers traced, a commit listing Claude as a co-author changed the file, and that the researchers take that to mean Claude often commits the file. That is their reading of the co-author line.
Check the file
From the repository root, search the local file and the shared file. Include a copy in the directory where you start Claude Code if that path is different.
grep -nE 'sk-|sk_live_|sk-ant-|ghp_|AKIA|service_role|sb_secret_|Bearer' \
.claude/settings.local.json .claude/settings.jsonRun it on your machine. Do not paste the file, or a matching line, into a website or a chat.
A hit on those prefixes is a credential-shaped string in a settings file. Read the line before you rotate. A placeholder or an example in a comment is still just text until you confirm it is a key you issued. The Hacker News, reporting Apiiro, says many of the secrets were passwords typed inside a command, such as after PGPASSWORD=, sshpass -p, or mysql -p, and that those strings lack a known key prefix. The grep misses that shape. Open the allow array and read every command.
/permissions lists the rules and which settings file each one comes from.
Clean the file, and rotate the key
If the value is a real credential, revoke or rotate it at the provider before you treat an edit as the fix. GitHub's remediation tutorial says you should consider any leaked secret immediately compromised. Removing it from the codebase, pushing a new commit, or deleting and recreating the repository does not prevent it from being exploited (Remediating a leaked secret).
The same tutorial says that if taking the app down is the problem, you can generate the replacement first, point the app at it, and then revoke the old value. GitHub automatically revokes GitHub personal access tokens leaked in public repositories. For other providers, revoke the key in that provider's own console. Deleting the JSON line is not the revocation.
The Hacker News says the researchers' advice is to rotate every password, token, and key the files have ever held, including a copy that never left your computer, and then delete the rules. The file is plain JSON in the project folder.
- Revoke or rotate the key at the provider. If the app must stay up, create the replacement, switch the app to it, then revoke the old key.
- Delete every
allowrule that contains the secret, in.claude/settings.local.jsonand in.claude/settings.jsonif the shared file has it./permissionscan remove a rule. Settings files are strict JSON: a trailing comma or a comment is a syntax error. - Run the grep again, and read the remaining
allowentries. Put the new key in an environment variable or a secrets manager. Do not approve a new command that contains the new key, and do not write it back into this file.
Keep the key out of the command
The shell expands a variable when the command runs. The allow rule stores the text you approved. A command that references $DATABASE_URL saves that name. A command that contains the password saves the password. The Hacker News reports the researchers' advice: refer to secrets as variables from a secrets manager, such as $DB_URL, and approve a pattern such as Bash(npm run:*) when the command itself has no secret in it.
A broad pattern is a different risk. Bash(curl *) matches every curl. The permissions docs say to put the * after the subcommand you mean to allow, and that a rule matches the command text Claude writes, not every other way to run the same program.
Keep the key out of the env object in settings.local.json and settings.json. The settings reference says values there are plain text in the settings file, and that they are passed to every subprocess Claude Code starts (All settings). For the credential Claude Code itself sends to the model API, that page points to apiKeyHelper: a command you supply, for a short-lived token fetched from a vault. The helper's script is still a file on disk. The secret stays in the vault, or in your shell environment.
Claude Code's own API key can also come from the ANTHROPIC_API_KEY environment variable (Environment variables). Export it from your shell or your secrets manager. Writing the same value into a settings file puts it back in plain text.
Make sure the local file is gitignored
The first time Claude Code writes .claude/settings.local.json in a git repository that does not already ignore it, it adds **/.claude/settings.local.json to your global git excludes. That file is core.excludesFile when your global git config sets it to an absolute or ~-prefixed path. Otherwise it is $XDG_CONFIG_HOME/git/ignore, or ~/.config/git/ignore when XDG_CONFIG_HOME is unset. If you created the settings file by hand, the docs say to add it to .gitignore yourself.
A global exclude applies to your git, on that computer, in every repository. The Hacker News, reporting Apiiro, says Claude Code does not add the path to the project's .gitignore, so the protection does not travel with the repo, and it does nothing for a file that was already committed.
See which rule is ignoring the file, whether git is tracking it now, and whether history ever contained it:
git check-ignore -v -- .claude/settings.local.json
git ls-files -- .claude/settings.local.json .claude/settings.json
git log --all --oneline -- .claude/settings.local.json .claude/settings.jsongit check-ignore -vprints the file and the pattern that ignore it. A path under your home directory orcore.excludesFileis the per-machine exclude. A.gitignorein the repository is the rule that clones get.git ls-filesprints a path that is tracked in the index now. No output means it is not tracked in this checkout.git loglists commits that touched the path, including commits from before the file was deleted.
Add the local file to the repository .gitignore and commit that line:
.claude/settings.local.jsonLeave .claude/settings.json tracked if the team uses it. That file is meant to be committed. What must stay out of it is the secret. If git ls-files prints .claude/settings.local.json, stop tracking the current file without deleting your copy:
git rm --cached -- .claude/settings.local.jsonCommit that removal together with the .gitignore change. git rm --cached does not rewrite old commits.
If it was committed, rotate, then purge history
A path in git log means the file was committed, even when git ls-files is empty now. Rotate or revoke every credential those commits contain before you rewrite anything. GitHub's history-rewrite guide says the same thing first: once the secret is revoked, it can no longer be used, and rewriting history may not be warranted. A file that was pushed still needs the revoke. The rewrite is how you remove the copy from the repository history (Removing sensitive data from a repository).
GitHub's procedure uses git-filter-repo 2.47 or later, which has --sensitive-data-removal. To drop this file from every ref in a fresh clone:
git-filter-repo --sensitive-data-removal --invert-paths --path .claude/settings.local.jsonIf the file ever lived at another path, GitHub says to pass that path too. If the secret also sits in .claude/settings.json, which you still want to keep, use the guide's --replace-text form to replace the secret string rather than deleting the whole file. Then force-push the rewritten history. GitHub warns that this changes commit hashes, needs a force push, and can be undone by a teammate who pulls the old history and pushes it back. Forks, other clones, and cached views on GitHub can keep the old commits. You cannot delete a fork you do not own. GitHub Support is who removes cached views, and the guide says Support helps when rotating the credential is not enough to address the risk.
The Hacker News says removing the file from the project does not undo a leak, because older versions stay in git history and in forks. Rotate first. Purge second.
Deny reads of .env files and ~/.ssh
Anthropic's settings example denies reads of .env and .env.* from user settings, so Claude Code's file tools stay off those files. The permissions page uses Read(~/.ssh/**) as a deny that still matches when a symlink points at a key under that directory.
Read rules use gitignore pattern syntax. A bare name matches at any depth under the current directory, so Read(.env) matches a file named .env in nested folders. The settings example's Read(./.env) is the copy in the current directory. Read(*.env), which the permissions page discusses, matches names that end in .env, including .env. Names such as .env.local need .env.*. .env.* requires the extra dot, so keep the .env rule beside it. Deny rules are evaluated before allow rules. An allow rule cannot carve an exception out of a deny.
{
"permissions": {
"deny": [
"Read(.env)",
"Read(.env.*)",
"Read(~/.ssh/**)"
]
}
}Put that in ~/.claude/settings.json for every project on this machine, or in the shared .claude/settings.json when the whole team should get it. The shared file is committed, so the deny list can live there. Leave every secret out of that file.
The permissions page warns about the reach of these rules. They apply to Claude Code's file tools, to Bash commands it recognizes, such as cat, head, tail, sed, and tee, and to redirections such as < file. A command that reads a file without naming it, such as grep -r pattern . from the directory that holds the file, falls outside them, and so does a Python or Node script that opens the file itself. For a block that applies to every process, that page says to enable the sandbox.
A key in the repo can also ship in the live app
settings.local.json is a file on disk, and a committed copy is a file in the repository. The site you deploy is a separate copy of whatever the client bundle contains. A key that was pasted into a command can also be pasted into frontend code, or read from a public env prefix that the bundler inlines. NEXT_PUBLIC_ and VITE_ are that case. The NEXT_PUBLIC_ and VITE_ guide is which names end up in the browser.
Cleaning the settings file does not rewrite JavaScript that is already deployed. Search the live site after you rotate. Anyone who can open the URL can save the scripts it sends.
PlugLeak's free scan checks that public URL. It is a passive GET of the page and same-site JavaScript, and it stops at 25 files or 12 MB. It checks /.env, /.git/config, security headers, and TLS. In what the site serves, it detects Stripe, OpenAI, Anthropic, and AWS keys, GitHub tokens, PEM private keys, sb_secret_ keys, and service_role JWTs.
It cannot see your local Claude Code files. It does not read .claude/settings.local.json, on your laptop or by requesting that path. It does not test Row Level Security, auth, grants, or storage, query a database, log in, or crawl. A clean scan means those public responses did not match. It says nothing about the settings file on your machine.
Run it at https://plugleak.com/#scan. The fix report, for findings from that public URL, is $9, or $29 for 10. Prices are on the pricing section. How the free scan works lists every request.
FAQ
Where does Claude Code store settings.local.json?
In a git repository it is .claude/settings.local.json at the repository root, and a worktree uses the file at the main checkout's root. Anthropic's settings docs list exceptions: outside a git repository, when the repository root is your home directory, on Windows, or when the repository root or its .git or .claude entry is not owned by your user, the file stays beside .claude/settings.json instead of always at the git root. Versions before 2.1.211 kept it in the directory where you started Claude Code, and current Claude Code still reads a file an earlier version left there. Your user settings, which apply in every project, are a different file: ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude).
Does "Yes, and don't ask again" always save my API key?
It saves an allow rule for what the prompt offered. Anthropic's permissions docs say a rule with no * matches one exact command, and a rule with * is a pattern, such as Bash(npm run *). A pattern can be free of secrets. The Hacker News, reporting Apiiro's November 2026 research, says that when the prompt offered one exact command, a password or token typed into that command was saved in plain text. Those docs do not describe a step that strips a secret out of the saved rule. Open the file and read the allow list. A current install can still hold rules written earlier.
Claude Code already keeps settings.local.json out of git. Is that enough?
It covers one machine. The first time Claude Code writes the file in a git repository that does not already ignore it, it adds **/.claude/settings.local.json to your global git excludes, not to the project's .gitignore. That exclude stays in your git config on that computer. It does nothing for a file that is already tracked, for a clone on another machine, or for a teammate. Add .claude/settings.local.json to the repository .gitignore and check git ls-files and git log.
I deleted the line from settings.local.json. Is the key safe?
Deleting the line removes it from the current file. It does not revoke the key at the provider, and it does not remove a copy already committed. GitHub's leaked-secret tutorial says to treat a leaked secret as compromised: removing it from the codebase, pushing a new commit, or deleting and recreating the repository does not revoke it. Rotate or revoke it with the provider. If git log shows the file, history and any fork or old clone can still hold the value. The Hacker News also says the plaintext file matters even when it never reached GitHub, and the researchers' advice is to rotate every key the file has held, then delete the rules.
Can PlugLeak's free scan see my settings.local.json?
No. The scan at https://plugleak.com/#scan is a passive GET of the public page and same-site JavaScript (max 25 files / 12 MB). It checks /.env, /.git/config, security headers, and TLS, and it detects Stripe, OpenAI, Anthropic, and AWS keys, GitHub tokens, PEM private keys, sb_secret_ keys, and service_role JWTs in what the site serves. It does not read local files, including .claude/settings.local.json. It does not test Row Level Security, auth, grants, or storage, query a database, log in, or crawl. The fix report is $9, or $29 for 10, and it covers findings from that public URL. Prices are on /#pricing.
Sources
- The Hacker News: Claude Code's "Don't Ask Again" file exposes passwords and keys in 1,122 public copies on GitHub (7 November 2026). Figures in this guide are taken from this article's account of Apiiro's research.
- Apiiro: Coding agents leaking secrets to GitHub via "Don't Ask Again". The post URL is the write-up cited for this research. Its body did not load for this guide (the site returned a bot check), so no sentence here is sourced only from that page.
- Claude Code: Settings files and precedence
- Claude Code: Configure permissions
- Claude Code: All settings (
env,apiKeyHelper) - Claude Code: Environment variables
- GitHub: Remediating a leaked secret
- GitHub: Removing sensitive data from a repository
Check your app now — free, passive, about 20 seconds.
Same scanner as the homepage scan. Paste the live URL. It reads what a visitor already downloads. It does not log in or query your database.
Related guides
- GitHub token in the frontend
- Stripe secret key in the frontend
- CheckVibe alternatives
- OpenAI API key in the frontend
- Bolt environment variables vs Secrets
- v0 app security checklist
- Cursor app security checklist
- NEXT_PUBLIC_ and VITE_ API keys
- Lovable app data exposure check
- Supabase 42501 permission denied
- Supabase RLS checklist
- Bolt Supabase API key visible
- Supabase service_role key exposed
- Lovable app security check
- Is my vibe-coded app secure?
Scan by builder