31,088 secrets in Claude Code's local settings fileAudit the rules. Rotate what leaked.
Claude Code saves an approved command word for word, and a command with a password in it saves the password too. Two November reports count the result on public GitHub. Rotate first, because deleting the file leaves the commit.
-
01
Approval
Saved rule
Don't ask again stores the exact command, secret included
settings.local.json -
02
Channel
Git or image
The ignore rule lives on one machine, outside the repo
global excludes -
03
Exposure
31,088 secrets
Distinct secrets in public commits of the file
5,343 valid
TL;DR· the answer, in twenty seconds
What happened: Claude Code saves a command approved with "Yes, and don't ask again" as a literal allow rule in .claude/settings.local.json. GitGuardian counted 31,088 distinct secrets in public commits of that file, 5,343 of them valid when detected. Apiiro counted 1,379 still on default branches.
The minimum fix: Rotate every flagged credential, untrack the file, add it to the repo's .gitignore and .dockerignore, then delete the rule.
The lesson: A saved approval is a stored copy of the command. If the secret lives in the command string, the secret lives in the saved rule.
When you answer "Yes, and don't ask again" to a Claude Code prompt, the tool saves that exact command to .claude/settings.local.json, and GitGuardian has now counted 31,088 distinct secrets in public commits of that file.
Apiiro published its count on November 5 and GitGuardian followed on November 9. The headline numbers differ by a factor of about 22 because they answer different questions. This guide covers which one to act on, how a prompt answer reaches a public commit, and how to audit your own machines with a script I tested on synthetic data. If you have used Claude Code on a project with a database password, run the audit before you read the analysis.
What the two counts measure
| Apiiro | GitGuardian | |
|---|---|---|
| Published | November 5, updated November 8 | November 9 |
| Scope | Default branches, searched November 1-3 | Every public commit, January 2025 to November 7, 2026 |
Secrets in settings.local.json |
1,379 distinct | 31,088 distinct |
| Where | 1,122 files, out of 104,185 public copies | 23,276 repos, 11,336 commit authors |
| Validity | No credential tested | 5,343 distinct valid at detection (17%, a floor) |
Apiiro measures what GitHub serves on default branches today. GitGuardian scans history, so it also sees secrets that someone pushed and later deleted. GitGuardian draws the same line and calls its figure the one to have rotated. I agree. Deleting the file from main leaves the commit reachable, and Apiiro's own history pass found 734 more secrets in 509 repos that appear in no current copy. That pass covered 43,120 repos, so treat it as a floor too.
Apiiro's wider total is 2,539 distinct real secrets in 1,994 repos once you add history, the shared settings.json, committed transcripts and handoff notes. "Real" there means a recognized format or a public host. GitGuardian's validity checks go further: where a check returned a verdict, 67% of occurrences in settings.local.json were valid.
The valid set tells you what this leak is. GitGuardian lists 1,955 Postgres connection strings, 941 Google API keys, 355 Telegram bot tokens and 292 SSH passwords among the valid secrets in the local file. It found 139 distinct real Anthropic keys, 28 valid. The agent's own key is the minor case. The exposed credentials belong to whatever the agent touched while working.
Discount both reports for the sale. Apiiro sells application security tools and GitGuardian sells ggshield AI Hooks. Neither report documents an attacker using one of these secrets. Apiiro notified 63 organizations and says one confirmed its key had been live.
GitGuardian's monthly count starts at 256 in June 2025, peaks at 12,535 in April 2026 and falls to 959 in October, a 92% drop. GitGuardian does not know why and has not ruled out detector changes. I found no Claude Code changelog entry that explains it. A falling inflow does nothing for the backlog: the median file in Apiiro's set was first committed 217 days before November 2, and 118 repos had held one for over a year.
How a prompt answer becomes a public key
Anthropic's permissions docs say Bash approvals persist per repository and command, and that a rule with no * matches one exact command. The approved string becomes the rule. If the command carried a password, the rule carries it as well:
{
"permissions": {
"allow": [
"Bash(PGPASSWORD=hunter2-example psql -h db.internal.example -U app -c \"select 1\")",
"Bash(curl -H \"Authorization: Bearer hunter2-example-token\" https://api.internal.example/v1/jobs)"
]
}
}
GitGuardian sampled about 3,000 occurrences. Every secret it could place sat in an allow rule or an env block, and none in a deny rule. curl accounted for 50%, VAR=value prefixes for 15% and export for 5%. Validity rose with the command: 29% for VAR=value, over 50% for psql, mysql, mongosh and redis-cli, and 54% for sshpass and ssh.
Claude Code has a guard. The settings docs say that the first time it writes the file in a git repository that doesn't already ignore it, it adds **/.claude/settings.local.json to your global git excludes file. That entry lives in one machine's git config, and no clone carries it. Apiiro names the gaps: a folder that becomes a repo after the file exists, a clone on another machine, and a file already committed.
I reproduced the git half on macOS with git 2.54.0 and synthetic values. I did not run Claude Code for this test. The write behavior comes from Anthropic's docs and from Apiiro, which reproduced it with Opus 5.5 and Fable 5.1.
With the exclude present, git check-ignore -v named ~/.config/git/ignore as the source. With the same folder and no exclude, as on a copied project directory or a fresh container, git status showed ?? .claude/ and git add -A committed the file. Back on the protected machine, the tracked file kept showing M after every edit, and plain git check-ignore returned 1, since ignore rules skip tracked files. Apiiro found Claude Code's debug log saying "gitignore rules do not apply to tracked files", and reports that the user sees no warning while the next approval appends to the tracked file.
Boris Cherny, who leads Claude Code at Anthropic, wrote on Hacker News that "the files were manually created and checked in." That covers part of the set and leaves a lot out. Apiiro traced 1,105 repos and found that 539 had a commit co-authored by Claude that changed the file. Changelog entry 2.1.307 fixes self-hosted runner sessions that committed a settings.local.json left in the clone by an earlier session, which is Anthropic's own product taking this path.
One Hacker News commenter, Aurornis, argued that pressing the button exposes nothing and the commit does. That holds as far as it goes, and it misses why people commit the file. It grows without anyone reading it: Apiiro found one in ten files over 8 KB holds a secret, against under 1 in 500 for files below 500 bytes.
Docker skips git altogether. COPY . . takes the working tree, so neither the global exclude nor a .gitignore applies. GitGuardian found the two settings files in 543 Docker Hub image repositories across 7,625 tags, holding 613 distinct secrets, 99 valid. One valid Cloudflare token appeared in 559 tags of a single image. See where coding agents write on disk for the other files agents leave in the tree.
Audit one machine and every repo it touched
Save this as audit_agent_rules.py. It reads Claude Code settings files and prints the file, the entry and the reason, and it never prints the value.
#!/usr/bin/env python3
"""List Claude Code settings entries that hold a literal credential.
Prints the file, entry and reason. Never prints the value."""
import json, re, sys
NOT_LITERAL = r"(?![\"']?(?:\$|<|\*))" # skip $VAR, ${VAR}, <placeholder>, wildcards
CHECKS = [
("VAR=value prefix", re.compile(
r"\b[A-Z0-9_]*(?:PASS|PWD|TOKEN|SECRET|KEY|URL|URI|DSN)[A-Z0-9_]*="
+ NOT_LITERAL + r"[\"']?[^\s\"']{4,}")),
("password in URL", re.compile(r"://[^/\s:@]+:" + NOT_LITERAL + r"[^/\s@]+@")),
("password flag", re.compile(
r"(?:sshpass\s+-p\s*|(?:mysql|mysqldump)\b[^|;&]*?\s-p|--password[= ])"
+ NOT_LITERAL + r"[^\s\"']{3,}")),
("curl -u user:pass", re.compile(
r"\s(?:-u|--user)\s+[\"']?[^\s:\"']+:" + NOT_LITERAL + r"[^\s\"']+")),
("credential header", re.compile(
r"(?i)(?:authorization|[a-z-]*(?:api-?key|token|secret)[a-z-]*)\s*:\s*(?:bearer\s+|basic\s+)?"
+ NOT_LITERAL + r"[^\s\"',)]{8,}")),
("provider key format", re.compile(
r"\b(?:sk-[\w-]{20,}|gh[pousr]_\w{30,}|github_pat_\w{30,}|glpat-[\w-]{16,}"
r"|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]{10,}|npm_\w{30,}|sbp_\w{30,}"
r"|eyJ[\w-]{10,}\.eyJ[\w-]{10,})")),
]
def entries(cfg):
perms = cfg.get("permissions") or {}
for kind in ("allow", "ask", "deny"):
for i, rule in enumerate(perms.get(kind) or []):
yield f"permissions.{kind}[{i}]", str(rule)
for name, value in (cfg.get("env") or {}).items():
yield f"env.{name}", f"{name}={value}"
hits = 0
for path in sys.argv[1:]:
try:
cfg = json.load(sys.stdin if path == "-" else open(path))
except (OSError, ValueError) as err:
print(f"{path}: unreadable ({type(err).__name__})", file=sys.stderr)
continue
for where, text in entries(cfg):
reasons = sorted({name for name, rx in CHECKS if rx.search(text)})
if reasons:
hits += 1
print(f"{path}\t{where}\t{', '.join(reasons)}")
sys.exit(1 if hits else 0)
Sweep every settings file under your home directory, including user-level settings and folders that never became repos:
find "$HOME" -type f -path '*/.claude/settings*.json' -not -path '*/node_modules/*' -print0 2>/dev/null \
| xargs -0 python3 audit_agent_rules.py
On a fixture of 25 entries, 11 holding literal credentials and 14 clean, the script flagged the 11 and none of the 14. The clean set had $VAR references, wildcards, mysql -p with no value and ordinary content-type headers. The sweep handled paths with spaces and skipped node_modules. The fixture is mine and small, so read the result as a smoke test. The script errs toward false positives: MONKEY=banana flags because it contains KEY. Treat each line as an entry to read.
Next, check whether a given repo has a protection that travels with it:
f=.claude/settings.local.json
git ls-files --error-unmatch "$f" 2>/dev/null # exit 0 means the file is tracked
git check-ignore -v --no-index "$f" # names the file doing the ignoring
If the second command names .git/info/exclude or anything in your home directory, the protection stays on that machine. You want .gitignore in the output.
A clean working tree says nothing about history. From a repo root, this loop checks every committed version of both files:
#!/usr/bin/env bash
# Run from a repo root. Pass the path to audit_agent_rules.py.
audit="$1"
for f in .claude/settings.local.json .claude/settings.json; do
git log --all --diff-filter=AM --format=%H -- "$f" | while read -r c; do
git show "$c:$f" | python3 "$audit" - | sed "s|^-|${c:0:10} $f|"
done
done
For images, list what the build copied. I did not run this one, because the Docker daemon was unavailable on my test machine:
docker run --rm --entrypoint sh your/image:tag -c \
'find / -path "*/.claude/settings*.json" -not -path "/proc/*" 2>/dev/null'
The script reads settings files and nothing else. GitGuardian also found 6,155 distinct secrets in CLAUDE.md, 2,537 valid, plus 1,366 tokens from .claude/.credentials.json in 371 repos and 1,064 from .codex/auth.json in 536 repos. Apiiro found committed transcripts in 87 repos. Point a general scanner at those paths and keep this script for passwords inside saved commands, the gap Apiiro found in scanners.
Rotate first, then remove the rule
Order matters. Whoever fetched a public commit already has the value, and Apiiro found 211 forks of 74 of the repos in its set, so a history rewrite on your repo does not reach every copy. Rotation is the step that works without knowing who holds the value.
Once the credential is dead, stop tracking the file and put the ignore rule where a clone will find it:
git rm --cached .claude/settings.local.json
printf '%s\n' '**/.claude/settings.local.json' >> .gitignore
printf '%s\n' '**/.claude/settings.local.json' >> .dockerignore
git add .gitignore .dockerignore
git commit -m "Stop tracking Claude Code local settings"
After git rm --cached and the new line, git check-ignore -v named .gitignore as the source in my fixture and git status came back clean. Then delete the rule, in the file or through /permissions. Leaving it means the plaintext stays on disk, where the next COPY . . can take it.
When you still want the standing approval, follow GitGuardian's advice and approve a reference with a narrow prefix instead of Bash(curl:*):
# Saved word for word, with the value
Bash(curl -H "X-N8N-API-KEY: hunter2-example" https://n8n.example.internal/api/v1/workflows)
# Stores the variable name and limits the target
Bash(curl -H "X-N8N-API-KEY: $N8N_API_KEY" https://n8n.example.internal:*)
This protects the settings file and little else. The agent's shell still holds the value, and GitGuardian notes that it can reach the session transcript under ~/.claude/projects/. The settings.json hardening guide covers the deny rules worth adding next.
Here is the list to drop in a PR:
[ ] Sweep run on every machine that has used Claude Code
[ ] History loop run on every repo the sweep flagged
[ ] Every flagged credential rotated, oldest exposure first
[ ] .claude/settings.local.json untracked
[ ] Ignore rule added to the repo .gitignore and .dockerignore
[ ] Literal rules deleted, then re-approved with a reference if still needed
[ ] Published image tags checked and rebuilt where the file was copied
[ ] CI fails when the file is tracked
The CI check and a local hook both behaved as intended on my fixture. The CI step exits nonzero on any commit where the file is tracked:
test -z "$(git ls-files '*.claude/settings.local.json')"
python3 audit_agent_rules.py .claude/settings.json
The hook goes in .git/hooks/pre-commit, and it refused a file staged with git add -f:
#!/bin/sh
if git diff --cached --name-only --diff-filter=ACMR | grep -qE '(^|/)\.claude/settings\.local\.json$'; then
echo "refusing to commit .claude/settings.local.json" >&2
exit 1
fi
Keep the shared settings.json in that CI step. GitGuardian found 8,271 distinct secrets there, 1,283 valid, and a quarter of the leaking versions had an env block pointing at a third-party gateway with ANTHROPIC_AUTH_TOKEN set.
What auto mode and secret scanning leave open
Cherny's response names two remedies: "Everyone should be using auto mode instead", and enable secret scanning on your host. Both are worth doing, and I would not stop at either.
Auto mode cuts the number of prompts, so it should cut the number of saved rules. It does nothing for rules already on disk or for values already in history. A reader pointed out that the same leak can happen when auto mode asks about a sensitive command, and Cherny answered "Yeah good catch." Apiiro quotes Cherny listing "making sure auto mode catches this" and "building in basic secret scanning" as ideas to prototype. As of November 9, I found no changelog entry that keeps secrets out of saved allow rules. Entry 2.1.235 withholds the option when the prompt can't display the whole command, which solves a different problem. The approval prompts guide covers why a prompt was a weak control to begin with.
Scanning has a measurable gap on this data. Of Apiiro's 1,122 files, gitleaks flagged 564, TruffleHog flagged 643, and neither flagged 215. GitGuardian's generic detectors, the ones that fire without a provider format, produced 63% of its occurrences: 44,755 of 71,525. A scanner keyed on provider formats has nothing to match in PGPASSWORD=hunter2, and Apiiro's set holds more passwords and tokens for public hosts (743) than provider keys (636). A GitHub-side revocation also leaves the Docker Hub tag untouched, as GitGuardian points out.
The fix belongs at the write. GitGuardian proposes that Claude Code never persist an exact rule containing a VAR=value prefix, a header value, URL userinfo or a password flag, and that it offer session-only approval when one appears. That proposal is right, and the audit script above suggests why it is cheap: six patterns found every literal credential in my fixture. A false positive at that point costs the user one more prompt next session, which is a fair price compared with a key on GitHub.
Claude Code is an outlier here. Apiiro compared 16 agents and confirmed only Claude Code writing the full approved command to a project file by default. It also lists GitHub issues going back to August 2025 (#5544, #11982, #13106, #91270) with no Anthropic reply, three of them auto-closed. Cherny's comment that the team is "looking into what we can do to prevent this" came on November 7, two days after Apiiro published.
What this means for your stack
Run the sweep on every machine that has used Claude Code, rotate what it flags, and commit the ignore rule to the repo so a clone inherits it. Do those before you evaluate any tool, including the one below.
The pattern that removes this class of leak keeps the value out of the command string. A broker gives the agent a name and resolves the value when the process launches, so a saved approval stores the name, and the file can leak without giving anyone a credential. Environment variables get you part of the way. They still put the value in the agent's shell, where a transcript can catch it.
hasp is one working implementation, with a limit that matters. After hasp setup, hasp run --project-root . --env DATABASE_URL=@DATABASE_URL --grant-secret window --grant-window 15m -- npm run migrate gives the password to that migration, and approving that command saves @DATABASE_URL. Its threat model does not cover a malicious process running as the same user. Source-available (FCL-1.0), local-first, macOS and Linux, no account.
Whatever you run, treat .claude/settings.local.json as a credentials file until Claude Code changes how it writes the rule. It holds plain JSON inside your project tree, and the rule protecting it lives outside the repo.
Sources· cited above, in one place
- GitGuardian Secrets in Claude Code settings files on GitHub and Docker Hub
- Apiiro Coding agents leaking secrets to GitHub through "don't ask again"
- Hacker News Boris Cherny's response on Claude Code settings.local.json secrets
- Anthropic Claude Code settings files and precedence
- Anthropic Configure Claude Code permissions: deny rules and what runs before you trust a folder
- Anthropic Claude Code changelog
- Fair Core License FCL-1.0-ALv2 text
Stop handing the agent your real keys.
hasp keeps secrets in one local encrypted vault, brokers them into the child process at exec, and never lets the agent read the value.
- Local, encrypted vault — no account, no cloud, no telemetry by default.
- Brokered run — agent gets a reference, the child process gets the value.
- Pre-commit + pre-push hooks catch managed values before they ship.
- Append-only HMAC audit log answers "did the agent touch the prod token?" in seconds.
macOS & Linux. Source-available (FCL-1.0, converts to Apache 2.0). No account.