Keys and incidents

Claude Code saved your token in settings.local.json. Is it public?

When you pick “Yes, and don’t ask again” on a Claude Code permission prompt, it saves the whole command as an allow rule in .claude/settings.local.json. If you typed a token or password into that command, it’s now in that file in plain text. Claude Code tries to keep the file out of git, but that protection has gaps, and npm doesn’t use it at all. Run the checks below on every repo you’ve used Claude Code in.

TL;DR

  • Apiiro reported on 5 November 2026 that 1,122 public copies of the file held at least one real secret (1,379 distinct). Counting git history and transcripts, it found 2,539 secrets in 1,994 public repos.
  • Check Point found the file in 428 of about 46,500 npm packages it monitored, and credentials in 33 of those files.
  • Claude Code adds the file to your machine’s global git excludes. That doesn’t help if git already tracks the file, on another machine, or with npm publish.
  • We tested npm 11.19: it ships the file unless package.json has a files list or an ignore file names it. A .npmignore also switches off .gitignore.
  • Fix: rotate the credential, delete the rule, and pass secrets through environment variables so the saved rule holds $TOKEN, not the token.

This guide is for anyone building an app with Claude Code, including founders who use it to work on a Lovable, Bolt or Supabase project they exported. The research figures below come from news coverage of Apiiro’s and Check Point’s reports; we couldn’t reach Apiiro’s original post, so treat the exact counts as theirs, not ours. How Claude Code handles the file comes from Anthropic’s settings documentation. The git and npm behaviour in the gaps section we tested ourselves on 14 November 2026.

How a secret gets into the file

Claude asks before it runs a shell command. If you choose “Yes, and don’t ask again”, Claude Code writes that command into the project’s local settings file as an allow rule, so next time it runs without asking. The rule is the command text. Suppose you pasted a token into a curl to test an API, or a database password into psql. The file now looks like this (made-up values):

.claude/settings.local.json
{
  "permissions": {
    "allow": [
      "Bash(npm run test *)",
      "Bash(curl -H \"Authorization: Bearer 9f2c7d1e8a4b6f03c5e9d2a7b1f4c8e6\" https://api.example.com/v1/orders)",
      "Bash(PGPASSWORD=Wq8zL2mPx91kTr psql -h db.abcdefghijklmnop.supabase.co -U postgres)"
    ]
  }
}

Nothing is wrong yet: the file is on your laptop. It becomes a leak when the file leaves it. The shared .claude/settings.json has the same problem with its env block. That file is meant to be committed, and Apiiro found secrets in 298 of 76,011 public copies of it.

What the research found

ReportWhat it counted
Apiiro, 5 Nov 2026 (GitHub)104,185 public copies of settings.local.json in 103,617 repos. 1,122 held at least one real secret, 1,379 distinct secrets. With git history, the shared file and agent transcripts: 2,539 secrets across 1,994 repos.
Check Point, April 2026 (npm)About 46,500 npm packages monitored, 428 with the file, credentials in 33 files across 30 packages: npm tokens and logins, GitHub tokens, Telegram bot tokens, Hugging Face tokens and bearer tokens.
CaveatApiiro’s coverage notes the research doesn’t prove Claude wrote every secret it found. Some people edit the file by hand. Either way, a secret in that file is exposed.

Why “Claude Code keeps it out of git” isn’t enough

When Claude Code first writes the file in a git repo, it adds **/.claude/settings.local.json to your global git excludes file (usually ~/.config/git/ignore). That rule lives on your machine, not in the repo, and only git reads it. We tested each gap below with git and npm 11.19.0:

SituationWhat happens
Git already tracks the file
tested
Ignore rules don’t apply to tracked files. We committed the file, added the exclude, then changed it: git status still showed it as modified, ready to commit. This is how a file created by hand, or one committed before Claude Code wrote the rule, keeps leaking.
npm publish, no ignore rule
tested
npm ignores your global git excludes. A package with no files list shipped .claude/settings.local.json, even with a .gitignore that didn’t name it.
npm publish with a .npmignore
tested
Once a .npmignore exists, npm stops reading .gitignore. A package whose .gitignore listed .claude/ still shipped the file, because its .npmignore didn’t.
A files list in package.json
tested
Only the listed paths ship. The file stayed out.
Another machine, a zip, a Docker image
by design
The exclude rule exists only on the machine Claude Code wrote it on. A teammate’s laptop, a CI box, a zip you upload, or COPY . . in a Dockerfile (which reads only .dockerignore) doesn’t have it.

Check your repos in two minutes

Run these from the root of each repo where you’ve used Claude Code.

  1. Does git track it, now or ever? Any output from these two commands means the file is, or was, in your history:
terminal
git ls-files '*.claude/settings*.json'
git log --all --oneline -- '*.claude/settings.local.json' '*.claude/settings.json'
  1. What’s in it? Look for tokens, passwords and credentials in URLs. Paste the file into the free key check, which runs in your browser and masks what it finds, or search it here:
terminal
grep -nE 'Bearer |Basic |PASSWORD=|SECRET=|TOKEN=|API_?KEY=|--(token|password)|://[^ "]+:[^ "@]+@|sk-|ghp_|github_pat_|npm_|sk_live_|xox|(KEY|TOKEN|SECRET|PASSWORD)": "' .claude/settings*.json
  1. Would npm ship it? If you publish a package, list what goes in it, then check versions you’ve already published:
terminal
npm pack --dry-run 2>&1 | grep -i '\.claude'
npm pack your-package@1.2.3 --dry-run 2>&1 | grep -i '\.claude'
  1. Or run all of it at once. The open-source patchlabs CLI reads both settings files, reports secrets in allow rules and env values (critical if git tracks the file), and warns when npm publish would ship the local file. It reads text only and runs nothing from your repo:
terminal
uvx --from git+https://github.com/manra399/patchlabs-cli patchlabs scan .

If you found a secret

  1. Rotate first. If the file was ever committed to a public repo, zipped, shared or published, assume the secret was copied. Revoke it at the service and issue a new one (where to rotate each kind of key). Deleting the line doesn’t un-copy it, and a published npm version is effectively permanent.
  2. Delete the rule. Open the file and remove the line, or replace it with a wildcard rule that holds no secret, such as "Bash(curl *)".
  3. Stop git tracking it and ignore it in the repo itself, so every clone and CI machine has the rule:
terminal
git rm --cached .claude/settings.local.json
echo '.claude/settings.local.json' >> .gitignore
git commit -m "Stop tracking Claude Code local settings"
  1. Clean the history only after rotating; rewriting history doesn’t reach forks or clones that already have it (how to remove a key from git history).
  2. Fix the package. Add a files list to package.json (for example "files": ["dist"]), or add .claude/ to .npmignore, check with npm pack --dry-run, then publish a new version.

Stop it happening again

  • Never type a secret into a command. Export it in your shell, or keep it in an ignored .env file, and refer to it by name. The saved rule then holds $API_TOKEN, which is harmless.
  • Approve patterns, not one-off commands. A rule like Bash(npm run test *) saves fewer surprises than approving each full command line.
  • Read the allow list now and then. It’s plain JSON. Anything with a long random string in it is worth a second look.
  • Keep secrets out of the shared file. Values in the env block of .claude/settings.json reach everyone who clones the repo. Put only non-secret settings there.

You can also ask Claude Code to do the clean-up. It will still need you to rotate the keys:

prompt for Claude Code
Check this repo for secrets saved by Claude Code permission approvals.
1. Read .claude/settings.local.json and .claude/settings.json. List every allow, ask or deny rule and env value that contains a token, password, API key or credentials in a URL. Show each one masked (first 4 and last 4 characters only). Don't print full secrets.
2. Run: git ls-files '*.claude/settings*.json' and git log --all --oneline -- '*.claude/settings.local.json'. Tell me if the file is or was tracked.
3. If package.json exists and is not private, run npm pack --dry-run and tell me if .claude/ would be published.
4. Replace each rule that contains a secret with a wildcard rule that contains none, and change any command we use often to read the secret from an environment variable instead.
5. Add .claude/settings.local.json to .gitignore and, if it is tracked, run git rm --cached on it. If we publish to npm, add a "files" list to package.json.
6. List which services I need to rotate keys for. Don't rewrite git history yourself.

Sources

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Are any of these keys also in your code?

Paste code, a .env or your built JavaScript bundle into the free key check. It runs in your browser: no request is sent and nothing is stored. It flags secret keys (AI providers, Stripe, AWS, GitHub, database URLs), tells a Supabase anon key from a service role key, and links to where to rotate each one.

Open the free key check

Free, no sign-upNothing leaves your browserSee a sample result

Written by Manraj Singh Dhillon. Last checked 14 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.