Claude Code Secrets Leak on GitHub

· Security Engineering · By Hassan Nazir

Apiiro found plaintext passwords and keys in over a thousand public Claude Code settings files, all written by one convenience click. Here is how the leak works, why scanners missed hundreds of the files, what is still unverified, and the exact cleanup order I would follow.

If you have ever typed a password into a terminal command and then told an AI coding agent "yes, and don't ask again", this one is for you. Security firm Apiiro published research in the first week of November 2026 showing that Claude Code's "don't ask again" option can write the full approved command, secret included, into a project file. A lot of those files then got pushed to public GitHub repositories.

I find this more interesting than most breach stories because nobody broke into anything. There is no attacker in the middle of it. A product default, a human habit and a scanner blind spot lined up, and the result is a pile of live credentials sitting on the open internet.

A note on sourcing first. The primary source is Apiiro's own research. I could not open that page directly in this run, so I am relying on three independent write ups that all describe it in consistent detail: The Hacker News, a DEV Community analysis, and Privacy Affairs. Most of the coverage is one study retold, so treat the numbers below as Apiiro's numbers, not as something I measured myself.

What happened

Claude Code asks permission before it runs shell commands. When you approve one, you can pick "Yes, and don't ask again". The agent then saves an allow rule so it never asks about that command again. The rules live in a file called .claude/settings.local.json inside your project.

The catch is how the rule is written. If you approve an exact command that has a password in it, the whole command goes into the file as plain text. Something like this, with a made up value:

{
  "permissions": {
    "allow": [
      "Bash(PGPASSWORD=hunter2 psql -h db.example.com -U app -c 'select 1')"
    ]
  }
}

Pattern style approvals do not have the problem. A rule like Bash(npm test:*) stores no secret because there is none in it. The trouble only shows up when the approved text is a literal command that carries a credential.

The numbers

Per Apiiro, as relayed by the outlets above, a GitHub search on November 1 to 3 turned up roughly 104,000 copies of the local settings file across about 103,600 public repositories. About 1,122 of those copies, around 1.1 percent, held at least one secret. In total that was 1,379 distinct secrets in the local file alone.

Pull in older commits, forks, the shared .claude/settings.json, and saved agent logs, and the headline figure grows to 2,539 secrets across 1,994 repositories.

What was foundCount reported
Public copies of the local settings fileabout 104,000
Copies containing a secret1,122
Database passwords379
Supabase service role keys122
SSH logins43
GitHub, GitLab or npm tokens42
AWS keys23
Organizations affected63

Two details bother me more than the totals. First, the secrets were not hiding in old history only. Reports say the affected files were still on the default branch, and about half had been sitting there for at least 217 days. Second, in 539 of 1,105 traced repositories, a commit co-authored by Claude changed the file. So in many cases the agent did not just write the file, it helped commit it.

Why the built in protection did not save people

Claude Code does try to keep the file out of git. It adds the local settings file to your global git excludes. That is a sensible idea with three holes in it.

The global exclude lives on your machine, not in the repository. A teammate, a CI runner or a fresh clone does not inherit it. It also does nothing for a file git already tracks, because ignore rules only apply to untracked files. And it does not touch the project's own .gitignore, so the protection does not travel with the code. Privacy Affairs adds that npm packages use their own ignore logic, which means a .claude folder can ride along inside a published package.

My take: a safeguard that only works on the machine of the person who already made the mistake is not much of a safeguard. It is a seatbelt that only fastens when you are not in an accident.

Why the scanners missed so many

This part is the lesson for anyone running secret scanning as their main defense. Gitleaks flagged 564 of the 1,122 files and TruffleHog flagged 643. Between them, 215 files were caught by neither.

The reason is how these tools work. They hunt for known shapes: an AWS key prefix, a GitHub token format, a Stripe style marker. A database password typed after PGPASSWORD= has no prefix and no shape. It is just a string. Most of the 215 misses were exactly that, per the DEV Community analysis.

So the failure is not that the scanners are bad. It is that a plain password inside a command line is outside what pattern matching can recognize, and agents are now producing a lot of command lines.

What is confirmed and what is not

  • Confirmed by multiple outlets: the mechanism, the file name, the headline counts and the scanner results, all attributed to Apiiro.
  • Confirmed once: one notified organization said its exposed key was live. Apiiro did not test the rest, so I cannot tell you how many of the 1,379 still work.
  • Unverified: whether Anthropic has changed the behavior. Coverage mentions a bug report about plaintext credentials in approved commands that was closed by an automated process as not planned, and I found no statement from Anthropic in the pieces I read. Check the current release notes yourself before assuming it is fixed.
  • Unverified: any claim that attackers have already used these keys. I saw no evidence of that in the coverage.

What I would do today

Order matters here. Rotate first, clean up second. A leaked secret stays leaked even after you rewrite history, because forks and clones keep their copies.

  1. Search your own repositories, including history, for the settings files. Anything under .claude/ deserves a look, and so do similar folders from other agents.
  2. Open every allow list and read it. You are looking for passwords, tokens, connection strings and auth headers inside rule text.
  3. Rotate every credential you find, starting with anything that reaches a public server directly: database passwords, SSH logins, cloud keys.
  4. Untrack the local file (the cached option of git rm does this without deleting it), add it to the project .gitignore, and delete the bad rules.
  5. Check what you publish. If you ship npm packages, run a pack dry run and look at the file list for agent folders.

A quick way to hunt through history on your own machine:

# does any commit ever touch the file?
git log -p .claude/settings.local.json

# find inline passwords that scanners will not recognize
git log -p -G "PASSWORD=|TOKEN=|Authorization" .claude

For teams, the fixes are more structural:

GapControl I would add
Agent folders are not treated as sensitiveTreat .claude and similar folders like .env files in review and in org gitignore templates
Scanners only know provider formatsAdd a custom rule for passwords inside commands, and scan history, not just the tip
Humans approve literal commandsApprove patterns, and pass secrets through environment variables or a secrets manager
Credentials are long livedMove to short lived, scoped credentials so a leak expires on its own

My take

The easy reaction is "AI tools are unsafe". I do not think that is the right lesson. The right lesson is that agent configuration is now a place where secrets accumulate, and almost nobody has put that folder on their threat model yet.

Think about how the click feels. You are in flow, the agent asks about a command, and "don't ask again" is the polite, productive answer. The cost of that choice is invisible at the time it is made. Defaults like that should be built so the safe path is also the lazy path: store a pattern, never the literal command, and warn loudly when the command contains something that looks like a credential.

Until the tools do that, the burden sits with us. Do not type passwords into commands you plan to approve permanently. Put secrets in the environment. And assume that any file an agent writes might get committed by an agent too.

Key Takeaways

  • Approving an exact command with "don't ask again" can store that command, password included, in plain text in a local settings file.
  • Apiiro reports 1,122 public copies of that file with at least one secret, 1,379 distinct secrets, and 2,539 secrets across 1,994 repositories once history, forks and related files are counted.
  • Gitleaks and TruffleHog together still missed 215 files, mostly passwords with no recognizable format.
  • The global git exclude Claude Code adds does not protect clones, teammates, CI or files already tracked.
  • Rotate first, then untrack and clean up. Approve command patterns, not literal commands, and keep secrets in a secrets manager.
  • Whether Anthropic has fixed the behavior is unverified in the sources I read.

Sources

Related field notes