Fix secrets leaked via Claude Code .claude/settings.local.json
Updated · Applies to: Claude Code, Supabase, Postgres, AWS, Stripe, GitHub
TL;DR fix: Run git log --all --oneline -- .claude/settings.local.json in each repo. If it prints anything, open the file (and its history) and list every password, token, key, or connection string inside an allow rule. Rotate those credentials first (Supabase service_role/secret key and database password, AWS access keys, Stripe keys, GitHub/npm tokens), because forks and clones keep the old commits. Then git rm --cached .claude/settings.local.json, add it to the repo's own .gitignore, delete secret-bearing rules from your local copy, optionally purge history with git filter-repo, and from now on approve patterns like Bash(npm run *) and pass secrets as $ENV_VARS, never inline.
Steps
- Check whether the file was ever committed (2 minutes). In each repo run git ls-files .claude (is it tracked now?) and git log --all --oneline -- .claude/settings.local.json .claude/settings.json (was it ever committed, even if deleted?). Then grep the file and its history for PGPASSWORD=, sshpass -p, mysql -p, postgres:// or postgresql://, service_role, sb_secret_, sk_live_, AKIA, ghp_, npm_, and Bearer. Apiiro found common scanners miss many passwords typed inside commands, so read the allow list yourself.
- Rotate every credential the file ever held. Do this before any cleanup. Supabase: rotate the service_role/secret key and reset the database password, then update server-side env vars. AWS: create a new access key, switch to it, then deactivate and delete the old one in IAM. Stripe: rotate or expire the key in Dashboard → API keys. GitHub/npm/other tokens: revoke and reissue. SSH: change the password or remove the key from authorized_keys.
- Stop tracking the file and ignore it in the repo. Run git rm --cached .claude/settings.local.json, add .claude/settings.local.json to the project's own .gitignore, and commit both. Claude Code's docs say it adds the file to your global git excludes when it first writes it, but that protection lives on one machine and does not apply to a file git already tracks.
- Clean your local copy. Even if the file was never committed, open .claude/settings.local.json and delete every allow rule that contains a secret. Approved rules stay in the file long after the command ran, and the file can also leave your machine in a zip, Docker image, npm package, or synced folder.
- Purge history if you need to (optional, after rotation). If the repo is public or shared, rewrite history with git filter-repo --sensitive-data-removal --invert-paths --path .claude/settings.local.json, force-push, and coordinate with collaborators. GitHub's docs warn that forks, old clones, and cached views can still hold the data, which is why rotation is the step that actually ends the exposure.
- Approve patterns and reference secrets as env vars. When Claude Code asks, prefer rules like Bash(npm run *) (Bash(npm run:*) is the equivalent older form) over one exact command with a secret in it. Keep secrets in env vars or a secrets manager and let commands reference $DATABASE_URL or $PGPASSWORD, so a saved rule records the variable name, not the value. Add secret scanning in pre-commit and CI that also checks agent folders.
Why this happens in vibe-coded projects
You ask Claude Code to “check why login fails on staging” or “run the migration.” The command it proposes needs a credential, so the credential ends up in the command line:
PGPASSWORD=… psql -h db.<project>.supabase.co -U postgres -c "select …"
Claude Code asks before running it. Click Yes, and don’t ask again and, per Anthropic’s settings and permissions docs, it saves an allow rule to .claude/settings.local.json at the repo root. When the rule is the exact command, the password is saved with it, in plain text.
Anthropic’s docs say Claude Code adds **/.claude/settings.local.json to your global git excludes the first time it writes the file. That works on one laptop. It does nothing for a file git already tracks, a folder that becomes a repo later, a copy on another machine, or a file you created by hand. Apiiro also found that in 539 of 1,105 repos with a real secret it traced, a commit co-authored by Claude changed the file.
The numbers (Apiiro, data collected Nov 1-3, 2026): 104,185 public copies of the file; 1,122 held a real secret (1,379 distinct secrets), including 379 database passwords and 122 Supabase service-role keys. Gitleaks and TruffleHog together missed 215 of those files. Older versions of the file held 734 more secrets that no current copy shows. These are Apiiro’s figures, also reported by The Hacker News.
The 2-minute check
Run this in every repo where you’ve used Claude Code:
# Is it tracked right now?
git ls-files .claude
# Was it EVER committed (including deleted versions)?
git log --all --oneline -- .claude/settings.local.json .claude/settings.json
# Any secret-looking strings in the file's full history?
git log --all -p -- .claude/settings.local.json .claude/settings.json \
| grep -nE 'PGPASSWORD=|sshpass -p|mysql -p|postgres(ql)?://|service_role|sb_secret_|sk_live_|AKIA|ghp_|npm_|Bearer '
# And your local copy, committed or not
cat .claude/settings.local.json
If the git log command prints nothing and the local file has no secrets, you’re done. If it prints commits, treat everything that file ever held as exposed.
The fix
1. Rotate first. Apiiro’s and GitHub’s guidance agree on the order: revoke or rotate, then clean up.
- Supabase: rotate the
service_role/ secret (sb_secret_…) key and reset the database password; update every server-side env var and Edge Function secret that used them. See Supabase key rotation and the “Invalid API key” trap. - AWS: create a new access key, deploy it, then deactivate and delete the old one in IAM. Check CloudTrail and billing for activity you don’t recognize.
- Stripe: rotate or expire the key in Dashboard → API keys. If the same key also lived in an MCP config, follow Fix Stripe sk_live keys left in MCP or agent config.
- AI provider keys (OpenAI, Anthropic, etc.): rotate, then set spend caps. See the AI bill-spike fix.
- GitHub / GitLab / npm tokens, SSH logins: revoke and reissue; change SSH passwords or remove keys from
authorized_keys.
2. Untrack and ignore it in the repo (we tested these commands on a throwaway repo):
git rm --cached .claude/settings.local.json
echo '.claude/settings.local.json' >> .gitignore
git add .gitignore && git commit -m "Stop tracking Claude Code local settings"
git check-ignore -v .claude/settings.local.json # should print the .gitignore rule
git rm --cached keeps your local file but removes it from future commits. The old commits still hold it.
3. Delete secret-bearing rules from your local file. Open .claude/settings.local.json (or run /permissions in Claude Code) and remove every allow entry that contains a password, token, key, or connection string.
4. Purge history (optional, after rotation). For a public or shared repo, rewrite history with git filter-repo (needs v2.47+ for --sensitive-data-removal):
git filter-repo --sensitive-data-removal --invert-paths --path .claude/settings.local.json
git push --force --mirror origin
In our throwaway-repo test, this removed every commit containing the file and left the untracked local copy in place. But GitHub’s docs are blunt: forks, existing clones, and cached views can still serve the old commits, and anyone who already pulled them keeps them. Apiiro found 211 forks of 74 repos carrying the same secrets. Rotation is what ends the exposure; scrubbing just stops new people from finding it.
5. Stop putting secrets in approved commands. Keep secrets in env vars or a secrets manager and reference them, so a saved rule records the name, not the value:
# instead of PGPASSWORD=hunter2 psql -h db.example.supabase.co ...
psql "$DATABASE_URL" -c "select …"
And approve command families rather than one-off strings. Claude Code’s docs use the space-star form; :* at the end is equivalent:
{
"permissions": {
"allow": ["Bash(npm run *)", "Bash(git commit *)"],
"deny": ["Read(./.env)", "Read(./.env.*)"]
}
}
6. Scan agent folders too. Treat .claude/, .cursor/, and agent transcripts and memory files like .env. Run a secret scanner in pre-commit and CI, including history, and add a custom rule for passwords inside commands (PGPASSWORD=, sshpass -p, mysql -p, Bearer) since format-based scanners miss many of them. Don’t rely on the pre-commit hook alone: an agent blocked by it can retry with git commit --no-verify. Back it with GitHub push protection and a CI scan, and block --no-verify in your agent settings: AI agent pushed API keys to GitHub? git commit —no-verify skipped your pre-commit hook.
7. Close the other door on the same machine. The secrets your agent can read are also readable by anything that runs code on your laptop. A Vite dev server started with --host (Lovable exports do this by default) on an affected version can be made to read files and run code from the network. Check it: Is my Vite dev server exposed?
What we verified vs. what we didn’t
- Verified against primary sources on Nov 10, 2026: Apiiro’s report (figures above), The Hacker News coverage, Anthropic’s Claude Code settings and permissions docs (save location, global-excludes behavior,
Bash(npm run *)/:*syntax), GitHub’s sensitive-data removal docs, and Boris Cherny’s Hacker News comments. - Reproduced by us: the git check,
git rm --cached+.gitignore, andgit filter-repopurge, on a throwaway repo with a fake password. - Docs-based, not reproduced by us: Claude Code writing the exact approved command into the file, and the global-excludes behavior. We relied on Anthropic’s docs and Apiiro’s reproduction for these.
- Not shipped as of Nov 10: Anthropic has said it will prototype options like built-in secret scanning; we have not seen a release.
Checklist
-
git log --all -- .claude/settings.local.jsonchecked in every repo - Every credential the file ever held is rotated (Supabase, DB, AWS, Stripe, tokens, SSH)
- File untracked with
git rm --cachedand listed in the repo’s own.gitignore - Secret-bearing allow rules deleted from the local file
- History purged if the repo is public or shared (after rotation)
- Secrets referenced as
$VARS; allow rules are patterns likeBash(npm run *) - Pre-commit/CI secret scanning covers agent folders and passwords inside commands
Prompt for Claude Code, Cursor, or Codex
Audit this repo for secrets saved in Claude Code permission rules. Run:
git ls-files .claude and
git log --all --oneline -- .claude/settings.local.json .claude/settings.json
Then search the current files AND their full git history for PGPASSWORD=,
sshpass -p, mysql -p, postgres:// or postgresql:// URLs, service_role,
sb_secret_, sk_live_, AKIA, ghp_, npm_ and Bearer headers. List each finding
by file, commit and credential type, redacting values after the first 6
characters. Do NOT print full secrets and do NOT rewrite history. Then:
1) give me a rotation checklist per provider, 2) run git rm --cached on
.claude/settings.local.json and add it to .gitignore, 3) propose replacement
allow rules that use patterns like Bash(npm run *) and $ENV_VARS instead of
inline secrets. When to get help
Get help if a Supabase service_role key, database password, or cloud key sat in a public repo for any length of time, if you see unfamiliar database or cloud activity after rotating, or if you want a Rescue Report to hunt other secrets agents left in .claude/, .cursor/, transcripts, or memory files. Rotate first, and never paste the secret itself into email or chat when asking for help.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
Why did Claude Code put my password in .claude/settings.local.json?
Per Claude Code's settings and permissions docs, choosing "Yes, and don't ask again" on a Bash permission prompt saves that approval as an allow rule in .claude/settings.local.json at the repo root. Sometimes the prompt offers a pattern; sometimes it is the exact command. When it is the exact command, anything typed into it (for example PGPASSWORD=..., sshpass -p ..., or a Bearer header) is saved in plain text. Apiiro and The Hacker News describe this behavior; we have not reproduced it inside Claude Code ourselves.
Doesn't Claude Code gitignore settings.local.json automatically?
Partly. Anthropic's settings docs say that the first time Claude Code writes the file in a git repo that does not already ignore it, it adds **/.claude/settings.local.json to your global git excludes file. That protects that one machine. It does not add anything to the repo's own .gitignore, and ignore rules never apply to a file git already tracks, so a folder that became a repo later, a copy on another machine, or a hand-created file can still be committed.
How many secrets did Apiiro find?
Apiiro (published early November 2026; data collected Nov 1-3) counted 104,185 public copies of .claude/settings.local.json in 103,617 GitHub repos. 1,122 files (1.1%) held a real secret, 1,379 distinct secrets in all, including 379 database passwords and 122 Supabase service-role keys. Counting git history, the shared .claude/settings.json, and agent transcripts, the total was 2,539 distinct secrets in 1,994 repos. These are Apiiro's figures; it did not test whether the secrets still worked.
I deleted the file. Am I safe?
No. Deleting the file in a new commit leaves every older version in git history, and in any fork or clone. Apiiro found 734 secrets in 509 repos that existed only in older versions of the file. Rotate every credential the file ever held; rewriting history is cleanup, not the fix.
Would gitleaks or TruffleHog have caught it?
Not reliably. Apiiro ran both over the files: of the 1,122 files with a real secret, gitleaks flagged 564 and TruffleHog 643, and 215 were flagged by neither. The misses were mostly passwords inside commands, which have no recognizable key format. Keep a scanner in CI, but also grep for PGPASSWORD=, sshpass -p, mysql -p, connection strings, and Bearer headers.
What permission rule should I approve instead?
Approve the command family, not a one-off string with a secret in it: for example Bash(npm run *) or Bash(git commit *). Claude Code's permissions docs say a trailing :* is equivalent, so Bash(npm run:*) matches the same commands. Put secrets in env vars and reference them as $VAR so the saved rule never contains the value.
Is Anthropic fixing this?
On November 7, 2026, Boris Cherny of the Claude Code team wrote on Hacker News that Claude Code historically has not done secret scrubbing and that the team is looking into prevention, naming possible approaches such as making auto mode catch this and building in basic secret scanning, to be prototyped before shipping. As of November 10, 2026 we have not seen a shipped fix, so do the cleanup yourself.
Sources
- Apiiro: Coding Agents Are Leaking Your Secrets to GitHub (research + Nov 8 update)
- The Hacker News: Claude Code's "Don't Ask Again" File Exposes Passwords and Keys in 1,122 Public Copies on GitHub (Nov 7, 2026)
- Claude Code docs: Settings files and precedence (settings.local.json, global git excludes)
- Claude Code docs: Configure permissions (rule syntax, wildcards)
- Hacker News: Boris Cherny (Claude Code team) response, Nov 7, 2026
- GitHub docs: Removing sensitive data from a repository (git filter-repo)
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)