
Claude Code Leaks Passwords: “Don’t Ask Again” Saves Secrets in Plain Text to settings.local.json
You need to check a table in the staging database, so you type PGPASSWORD=<real password> psql -h db-staging... and ask Claude Code to run it. It asks whether to allow this Bash command — you click “Yes, and don’t ask again” to get on with your work, then commit and push the public repo as usual and forget all about it. Months later, someone tells you your database password is sitting in plain text on GitHub, in a file you never opened — leaked by the very “don’t ask again” button you clicked for convenience.
That file is .claude/settings.local.json. Apiiro (5/11/2026) found 1,122 public settings.local.json files on GitHub containing at least one real secret — 1,379 secrets in total. Anthropic patched the behaviour in Claude Code v2.1.323 (12/11/2026), but the patch does not clean up the past.
What Is the Claude Code Password Leak?
When Claude Code is about to run a Bash command, it shows a permission prompt: allow it once, or choose “Yes, and don’t ask again” so it runs without asking next time. According to Anthropic’s official documentation, that approval is saved as an allow rule in .claude/settings.local.json — and the rule is the verbatim command. If the string contains PGPASSWORD=..., sshpass -p ..., or a token in an Authorization header, the password and token are written into the file too, in plain text, unencrypted, unmasked. The file lives in the project directory (.claude/), not in a user- or machine-specific configuration folder, so it follows the project’s git lifecycle: track, commit, push, clone. Apiiro also found secrets in the shared settings.json and in saved transcripts, so check all three.
Diagram — How a Secret Flows from a Command to GitHub
flowchart TD
A["Bash command containing a secret"] --> B{"Permission prompt"}
B -->|"Yes, and don't ask again"| C["Allow rule = verbatim command → settings.local.json"]
B -->|"Allow once only"| Z["No rule saved"]
C --> D["Only protection: global git excludes, on the local machine only"]
D --> E1["Repo created after the file already exists"]
D --> E2["Cloned onto a new machine"]
D --> E3["File already tracked"]
D --> E4["Manual commit"]
D --> E5["Commit co-authored by Claude"]
E1 --> F["Public GitHub (including git history)"]
E2 --> F
E3 --> F
E4 --> F
E5 --> F
F --> G["Scanners missed 19.2% of files"]
C -.->|"Patch v2.1.323"| H["Sensitive rules → session-only, not saved"]
The Scale of the Leak: What Apiiro Found on GitHub
Apiiro scanned public GitHub on 1–3/11/2026 and found 104,185 public copies of .claude/settings.local.json in 103,617 repositories. Of those, 1,122 files (1.1%) contained at least one real secret — 1,379 secrets in total: 379 database passwords, 122 Supabase service-role keys, 43 SSH logins, 42 GitHub/GitLab/npm tokens, and 23 AWS keys. Extending the search to git history, shared files, and transcripts, the count rose to 2,539 secrets in 1,994 repositories, belonging to 63 organisations; 734 secrets survived only in git history, with a median exposure time of 217 days.
Why Traditional Scanners Missed Them
Gitleaks flagged only 564 of the 1,122 files (50.3%), TruffleHog 643 (57.3%), and 215 files (19.2%) were flagged by neither — the secrets sit inside a JSON allow-rule string, as passwords typed directly into a command, not in a .env file or config file that scanners target by default.
GitGuardian’s Numbers — A Separate Measurement
GitGuardian’s own follow-up scan (9/11/2026) found 31,088 distinct secrets in 23,276 public repositories; 5,343 were still active when found. Monthly leaks peaked at 12,535 cases (4/2026) and fell to 959 (10/2026). The two measurements differ in scope, window, and method — never add 2,539 and 31,088 into a single total. Apiiro’s “real secret” means a string matching a provider’s format or sitting next to a public host; Apiiro did not test live credentials, so these numbers measure exposure, not exploitation, and no report of abused credentials exists.
Why Anthropic’s git-excludes Protection Is Not Enough
The first time Claude Code writes a file in a git repository, it adds **/.claude/settings.local.json to that machine’s global git excludes — but that protection lives only on that machine, from that moment on. It does not travel with the repository and is not in the project’s .gitignore. Secrets get past it four ways: the directory becomes a repository after the file already exists; a clone onto a new machine that has no excludes; a file already tracked, since git ignore only applies to untracked files; and a manual commit by the user or the agent itself.
The fourth path is disputed: Boris Cherny, head of Claude Code, replied on Hacker News that the leaks came from manual creation and commits, yet in 539 of the 1,105 traced repositories with real secrets, a commit co-authored by Claude had touched the file. A report from August 2025 (issue #5544) was closed “not planned” by a bot after 60 days, and Cherny admitted Claude Code “historically not done secret scrubbing” with no release date committed.
Anthropic Patched It in Claude Code v2.1.323 — and the Patch’s Limits
Claude Code v2.1.323, released 12/11/2026, changed three things: an allow rule that looks like it contains a secret, or would be saved to a settings.local.json that git tracks, now applies only to that session and is not saved; the global-ignore bug was fixed — the file is now ignored globally even if the directory becomes a git repository later, or on a new machine; and the Bash prompt no longer offers “don’t ask again” for commands that write to .git/.claude.
The patch does not delete rules saved before you updated, and does not remove secrets already pushed to GitHub. Anthropic has not published the heuristic for what “looks like a secret” — you cannot rely on it as a guarantee. Checking and updating is the first step, not the last:
claude --version
claude update
claude --version
The expected output is 2.1.323 or later.
Check Your Repositories in 10 Minutes
You need read access to the repository, a terminal, git and jq (sudo apt install jq on Ubuntu/Debian, brew install jq on macOS). These are standard git/jq commands — read the output before trusting it.
Step 1 — Update Claude Code to 2.1.323 or later (claude update).
Step 2 — Read the allow rules on your machine, and search GitHub for the file in your and your organisation’s repositories, including old ones:
jq -r '.permissions.allow[]' .claude/settings.local.json
The expected output is a list of allow rules — read each line for secret-bearing patterns such as PGPASSWORD=, sshpass -p, mysql -p, or tokens in headers.
Step 3 — Check git history. The file being absent from HEAD does not mean you are safe:
git log --all -- .claude/settings.local.json
git log --all -p -- .claude/settings.local.json
The first lists commits that touched the file; the second shows what changed. Careful: the second command’s output may contain the secret itself — run it locally only, never paste it anywhere.
Step 4 — Check more broadly: the shared .claude/settings.json, saved transcripts, and any second machine or CI runner where you have run Claude Code.
If a Secret Has Leaked — Rotate First, Clean Up After
Rotate and revoke every credential you find immediately — database passwords, Supabase service-role keys, AWS keys, GitHub/GitLab/npm tokens, SSH passwords — because a secret that has been public should be treated as exposed, even if you have seen no sign of abuse.
Only then clean up the repository:
git rm --cached .claude/settings.local.json
Then add the file to the repository’s .gitignore. If the secret is already in history, rewrite history (git filter-repo or BFG) and force-push; notify collaborators first — a forked public repository’s history can never be fully recalled, which is why rotating keys must come first.
Preventing a Repeat — 4 Workflow Changes
First, use environment variables instead of typing secrets into commands — a gitignored .env, a secret manager, or PGPASSFILE — never write PGPASSWORD=... inline.
Second, approve patterns instead of literal commands, for example Bash(npm run test *); an over-broad pattern such as Bash(*) merely trades the secret-leak risk for the risk of the agent running arbitrary commands.
Third, add the file to the repository’s .gitignore and enable secret scanning that covers history; combine gitleaks/TruffleHog with manually reading allow rules via jq, since scanners miss 19.2% of files like these. Fourth, add an allow-rule review to your new-machine and new-repository setup checklist.
Technical Assessment — Claude Code After This Incident
Claude Code’s permission model is clear and allows per-command control — the problem is how approvals are stored, not the prompt itself. Patch v2.1.323 addresses the leak at the right point: session-only for sensitive rules, a fixed global-ignore, and no “don’t ask again” offer for commands writing to .git and .claude. The weaknesses are design and response: storing literal commands turns secrets into policy data, the “looks like a secret” heuristic is unpublished and unverifiable, and action came only after Apiiro published. A tool entrusted with running commands on your machine must react faster to credential-leak reports.
Comparing Claude Code with Codex, OpenCode, and Other Coding Agents
This comparison covers one scope only: where approvals are stored, and whether an agent writes the full approved command into a file inside the project by default. Per Apiiro’s documentation on 16 coding agents, Claude Code is the only agent confirmed to do so by default; what could not be verified is stated as such. Codex and OpenCode are not confirmed to behave this way by default — but their local configuration files are not therefore absolutely safe, so users should still check them.
Practical Use Cases for Each Audience
Related reading: heldkeys for auditing AI agent access, the OpenAI Codex Security scanner, and the Cloudflare security audit skill.
Developers: run the 10-minute checklist above, and never type a secret into a prompt or a command given to an agent. DevOps/SRE and IT managers: scan the whole organisation, put the file into a mandatory gitignore policy, and enable secret scanning that covers history. Businesses and homelabs: rotate by procedure, audit history, ban committing local settings files — homelabs should check old personal repositories too.
Lessons Learned
- “Don’t ask again” turns a command into stored data — never let a secret appear in anything that gets saved.
- Protection that lives only on the local machine does not protect the repository.
- A clean scanner result does not mean no leak — 19.2% of leaked files evaded both gitleaks and TruffleHog.
- Updating to the patched version does not clean up the past — rotating keys and cleaning history is still the user’s job.
- Git history remembers longer than you think — median exposure of 217 days.
Conclusion — Who Should Act Today
Act now if you ever clicked “don’t ask again” for a command containing a secret, ever pushed a public repository from a machine running Claude Code, or manage an organisation that uses Claude Code. Never used Claude Code? Still check for a settings.local.json file once — it takes less than a minute. Then update to 2.1.323 or later, run the 10-minute checklist, rotate keys if you find a secret, add .gitignore, and switch to approving patterns.
Verification Scope
Verification date: 17/11/2026. The allow-rule mechanism and the v2.1.323 patch (12/11/2026) were verified against Anthropic’s official documentation and changelog, plus four independent secondary sources. The Apiiro (5/11/2026) and GitGuardian (9/11/2026) figures are vendor-published research, not independently verified; Apiiro did not test live credentials. Not published: the “looks like a secret” heuristic. Not independently verified: the 16-agent comparison. The numbers are exposure figures, not benchmarks; the remediation commands have not been run on a genuinely affected repository.
References
- Apiiro (5/11/2026): https://www.apiiro.com/blog/coding-agents-copy-your-secrets-to-a-hidden-file-thousands-are-on-github
- Anthropic — Claude Code settings: https://code.claude.com/docs/en/settings.md
- Anthropic — Claude Code changelog (v2.1.323): https://code.claude.com/docs/en/changelog
- Hacker News (item 50407882): https://news.ycombinator.com/item?id=50407882
- NotebookCheck: https://www.notebookcheck.net/Claude-Code-How-to-check-your-GitHub-repos-for-leaked-passwords.1450533.0.html
- DevelopersDigest: https://www.developersdigest.tech/blog/claude-code-dont-ask-again-secrets-github-2026
Bình luận
Bình luận được duyệt trước khi hiển thị.Đang tải bình luận…
Để lại bình luận