Claude Code Secrets Leak: One Click, 31,088 Keys Exposed

By 12 min read
Claude Code secrets leak through the settings.local.json approval file on public GitHub

A single button in Claude Code has put tens of thousands of real passwords on public GitHub. When a developer picks “Yes, and don’t ask again”, the tool remembers the whole command, password and all, in a small project file that people then commit, ship in Docker images and publish to npm.

The Claude Code secrets leak works like this: the approval option writes the exact approved command into .claude/settings.local.json, so any credential in that command is stored in plain text. GitGuardian counted 31,088 distinct secrets in public copies of that file, and 5,343 of them still worked when found. Anthropic changed the behaviour in Claude Code 2.1.323 on 12 November 2026, but every secret already pushed has to be rotated by hand.

Three headline figures: 31,088 secrets found, 5,343 still valid, and 1,379 in current copies.
The two main studies measure different slices of the same problem, so their totals differ by more than twenty times (Data: GitGuardian, Apiiro via The Hacker News).

What is the Claude Code secrets leak?

It is the accidental publication of credentials that Claude Code saved as permission rules. Claude Code is Anthropic’s AI coding agent: it proposes shell commands, and the developer approves or rejects each one.

The permission prompt offers a third choice, “Yes, and don’t ask again”. According to Claude Code’s settings documentation, choosing it on a shell command saves an allow rule to .claude/settings.local.json, the “project local” settings file meant for one person in one project.

The rule is the command exactly as typed. If the agent ran psql with a password on the command line, or curl with an API key in a header, the secret is now in a JSON file inside the repository folder. The researchers reproduced the behaviour with current models, The Hacker News reports, so it is a product behaviour, not a quirk of one model.

Why a permission file is a dangerous place for secrets

A permission rule is a security control, not a secret store. Nobody treats it like a .env file, scanners do not expect it to hold passwords, and developers copy whole project folders without looking inside .claude/.

How does a secret get from one click to the internet?

The leak needs only ordinary habits. The steps below are the chain the researchers describe.

Five-step flow from an approved command with a password to public exposure on GitHub, Docker Hub or npm.
Nothing in the chain is an attack: a convenience click plus a normal commit, build or publish is enough (Sources: Claude Code docs, Apiiro, GitGuardian, Check Point).
  1. The agent proposes a command with a credential inline, for example a database connection string.
  2. The developer, tired of prompts, picks “don’t ask again”.
  3. Claude Code writes the full command into the local settings file.
  4. The file travels: a git add ., a COPY . . in a Dockerfile, or an npm publish.
  5. It becomes public, and stays in git history and forks even after deletion.

Does Claude Code gitignore the file?

Partly. The documentation says that the first time Claude Code writes the file in a git repository that does not already ignore it, it adds the path to your global git excludes file. It does not change the project’s own .gitignore.

That protects one machine. It does not cover another clone, a teammate’s laptop, a file created by hand, or tools that ignore git rules. Boris Cherny, head of Claude Code, argued on Hacker News that exposed copies were therefore created manually and checked in, iTnews reports. The Docker and npm evidence below shows other routes too.

How big is the leak? Three studies compared

Three research teams have measured the problem, each from a different angle. Their numbers should not be added together.

Study Date Where they looked Headline finding
Check Point (via IT Brief) 23 Apr 2026 About 46,500 npm packages 428 packages shipped the file; 33 files in 30 packages held credentials
Apiiro (via The Hacker News, iTnews) 5 Nov 2026 104,185 current copies on GitHub 1,122 files with 1,379 secrets; 2,539 secrets across 1,994 repos in all files studied
GitGuardian 9 Nov 2026 Every public GitHub push, Jan 2025 to 7 Nov 2026, plus Docker Hub 31,088 distinct secrets in 23,276 repos, 5,343 valid

GitGuardian says both its numbers and Apiiro’s are right but answer different questions. Apiiro searched default branches in early November and ran a separate history pass; GitGuardian watches every push as it happens, including commits later deleted or force-pushed, and checks whether credentials still work.

What Apiiro found

Apiiro, as reported by The Hacker News, found secrets in about 1.1% of the 104,185 copies it located. These included 379 database passwords, 43 SSH logins for public servers, 42 GitHub, GitLab and npm tokens, and 23 AWS keys. iTnews adds 122 Supabase service-role keys.

Apiiro tied the leaks to 63 organisations, which iTnews describes as ranging from student groups to established vendors. Half of the affected repositories had kept the file on their default branch for at least 217 days. Apiiro did not test whether the credentials still worked, though one notified organisation confirmed its key had been live.

What GitGuardian found

GitGuardian’s read-only validity checks found that 67% of occurrences with a verdict were working credentials. Database connection strings dominate.

Bar chart of valid leaked secrets by type, led by 1,955 Postgres connection strings.
Working database credentials are the largest group of valid leaked secrets, ahead of cloud and AI keys (Data: GitGuardian).

GitGuardian also found 139 distinct Anthropic API keys in these files, 28 of them valid. In 263 repositories, the commit that leaked the file was authored by Claude’s own noreply address.

Why did common secret scanners miss so many?

Because the secrets sit inside shell commands, not in the neat KEY=value lines scanners are tuned for. Apiiro, as reported by The Hacker News, ran gitleaks and TruffleHog without their verification steps over the 1,122 files that held secrets: gitleaks flagged 564, TruffleHog 643, and 215 were caught by neither.

GitGuardian’s breakdown of about 3,000 occurrences explains why. Half came from curl commands, 15% from commands prefixed with PGPASSWORD= or DATABASE_URL=, and smaller shares from psql, mysql, sshpass and ssh. Generic detectors, rather than provider-specific patterns, produced 63% of all occurrences in the file.

A secret scanner is a tool that searches code and history for strings that look like credentials. If it only knows the shape of an AWS key, it will miss psql postgres://admin:hunter2@db.example.com.

Who is affected and how do you check your exposure?

Anyone who used Claude Code’s permanent approvals with credentials in commands, then shared the project folder. GitGuardian’s author data shows most leaks come from personal accounts, but it also counted 5,924 secrets tied to 3,338 corporate email domains, 1,499 of them valid.

It is not only GitHub

GitGuardian found the files in 543 Docker Hub image repositories across 7,625 tags, holding 613 distinct secrets, 99 of them valid. Its explanation: a COPY . . instruction copies the working tree and ignores .gitignore. One valid Cloudflare token appeared in 559 image tags.

Check Point’s earlier npm research, reported by IT Brief, found npm auth tokens, GitHub personal access tokens, Telegram bot tokens and Hugging Face tokens inside published packages. npm tarballs are effectively permanent once published.

Quick exposure check

  • Search every repository you own, including full history and forks, for .claude/settings.local.json and .claude/settings.json.
  • Search container images and published package versions for the same paths.
  • Open the file on your own machine, even if it was never committed, and read every allow rule.
  • Also review CLAUDE.md: GitGuardian counted 6,155 distinct secrets in those files, 2,537 valid.

How do you detect leaked Claude Code secrets?

Treat AI agent folders as secret-bearing, exactly like .env. This is the core advice from Apiiro, GitGuardian and Check Point.

  • Pre-commit and CI scanning. Add .claude/, .cursor/, .gemini/, .codex/, .specstory/, .mcp.json and CLAUDE.md to the paths your scanner always reads, and scan full history, not just the latest commit.
  • Rules for inline credentials. Add patterns for VAR=value prefixes, URL userinfo such as user:pass@host, password flags and authorisation headers inside command strings.
  • Registry scanning. Scan built images and package tarballs before publishing, since ignore files do not protect them.
  • Prioritise reachable secrets. Apiiro and GitGuardian both suggest putting credentials paired with a public hostname or IP at the top of the queue.
  • Watch credential use. For any database, SSH or cloud key found in these files, review login and API logs for access from unfamiliar addresses since the file was first committed.

This is a leak, not malware, so there are no attacker indicators or MITRE ATT&CK mappings in the sources. The closest technique is attackers harvesting unsecured credentials from public code, which is why time to rotation matters more than anything else.

What should developers and security teams do now?

Rotate first, clean second. Deleting the file does not remove it from history, forks, images or package mirrors.

  1. Rotate every credential the file ever held. Assume anything that touched a public copy is compromised, whether or not a scanner flagged it.
  2. Update Claude Code to 2.1.323 or later. The changelog says rules that look like secrets, or that would be saved to a tracked file, now last only for the session.
  3. Untrack the file. Run git rm --cached .claude/settings.local.json, add it to the project .gitignore, and add .claude to .dockerignore and .npmignore.
  4. Delete secret-bearing rules locally. Your uncommitted file is still a plain-text store on disk.
  5. Use variables, not literals. Reference $DB_URL from a secrets manager and approve narrow patterns such as a specific script, not exact commands with values in them.
  6. Add the file to organisation templates. Put it in default .gitignore templates and scanner configs so new projects start safe.

Has Anthropic fixed it?

Partly, and later than the first reports. The Hacker News traced complaints back to a GitHub issue filed on 11 August 2025, which a bot closed as “not planned” after 60 days of inactivity, along with four related reports. It also says the researchers’ bug reports got no reply.

After the research went public, Cherny told Hacker News readers, as iTnews reports, that “Historically Claude Code has not done secret scrubbing”. He said the team was prototyping built-in secret scanning and catching such commands in auto mode, while warning these might not fully solve it.

Timeline from the August 2025 bug report to the Claude Code 2.1.323 release in November 2026.
Fifteen months passed between the first public bug report and a release that stops saving secret-looking rules (Sources: The Hacker News, IT Brief, GitGuardian, npm registry).

What changed in Claude Code 2.1.323

The Claude Code changelog for 2.1.323 lists three relevant changes. “Don’t ask again” no longer saves a rule that looks like it holds a secret, or one headed for a git-tracked settings.local.json. The global ignore entry is now also added when a folder becomes a git repository later or on a new machine. And shell prompts stop offering “don’t ask again” for commands that write to sensitive paths such as .git or .claude.

The npm registry shows 2.1.323 was published on 12 November 2026, a week after Apiiro’s research. None of the news coverage we read mentions this release, and the changelog does not link it to the research.

How does this compare with earlier AI tool leaks?

Secrets in tool configuration are not new, but AI agents add a twist: the tool writes the file for you, quietly. GitGuardian checked 30 types of agent configuration file and found secrets in all of them, including 1,064 tokens in Codex auth.json files across 536 repositories.

Case What leaked Who wrote the secret into the file
Claude Code settings.local.json Full approved commands with credentials The agent, after one approval click
CLAUDE.md memory files Credentials pasted into project instructions The developer, sometimes the agent
Codex .codex/auth.json Session and API tokens The tool’s own login flow
Classic .env files Environment secrets The developer, on purpose

Apiiro, as reported by The Hacker News, says that of 16 coding agents it compared, only Claude Code was confirmed to save the full approved command in a project file by default.

The pattern of AI tooling becoming a credential source runs through other recent cases: the AGENTS.md malware that instructs coding agents to run it, and the Cursor breach where a vendor key led to a trojanised Claude Code extension. Once leaked, GitHub tokens feed campaigns like PolinRider, which rewrote thousands of real repositories.

Why did leaks fall before the fix?

Nobody knows yet. GitGuardian’s monthly data shows a sharp rise and an equally sharp fall that began months before 2.1.323.

Bar chart of monthly secret occurrences peaking at 12,535 in April 2026 and falling to 959 by October.
New leaks peaked in April 2026 and fell 92% by October, before Anthropic's November change (Data: GitGuardian).

GitGuardian lists possible causes without picking one: a Claude Code change, GitHub push protection, or its own detector coverage. A falling rate of new leaks also says nothing about the thousands of older secrets still sitting in history.

Open questions

  • Apiiro’s full method. No source we read gives the exact GitHub search Apiiro used, and Apiiro’s own post did not load for us, so its figures here come from news coverage.
  • How many secrets were abused. No study reports confirmed malicious use of a credential found this way.
  • Whether auto mode leaks too. iTnews reports that Cherny acknowledged a reader’s report that auto mode has the same exposure; no follow-up fix is documented in the sources.
  • Number mismatches in coverage. InfoQ describes Apiiro’s 1,122 as secrets, while The Hacker News and iTnews say 1,122 files held 1,379 secrets.

The bottom line

The Claude Code secrets leak is not a hack; it is a convenience button that turned commands into stored credentials. With 5,343 valid secrets found by one vendor alone, the fix that matters is rotation, not deletion. Treat every AI agent folder as a secrets file, scan it everywhere code travels, and keep passwords out of commands you approve.

Sources

This article is written for defenders and authorised security testers. Only test systems you own or have written permission to assess.

Frequently asked questions

What is the Claude Code 'don't ask again' secrets leak?

When a developer approves a shell command with 'Yes, and don't ask again', Claude Code stores the full command as an allow rule in .claude/settings.local.json. If the command contained a password or API key, that secret is saved in plain text, and the file has been committed to public GitHub repositories tens of thousands of times.

How many secrets were exposed through settings.local.json?

GitGuardian counted 31,088 distinct secrets across 23,276 public GitHub repositories from January 2025 to 7 November 2026, of which 5,343 were valid when detected. Apiiro, which looked only at current default-branch copies and their history, reported 1,379 secrets in current files and 2,539 across all the files it studied.

Why do Apiiro and GitGuardian report such different numbers?

They measured different things. GitGuardian monitors every public push, including deleted and force-pushed commits, over 17 months. Apiiro searched current copies of the file in early November 2026 plus a history pass, and did not test whether the secrets still worked.

Is .claude/settings.local.json gitignored by default?

Claude Code's documentation says that the first time it writes the file in a git repository that does not already ignore it, it adds the path to your global git excludes file. That protects the machine it ran on, not other clones, Docker builds or npm packages, and it does not help if the file was created by hand.

Has Anthropic fixed the Claude Code secrets leak?

The Claude Code changelog for version 2.1.323, published on npm on 12 November 2026, says a 'don't ask again' rule that looks like it holds a secret, or would be saved to a tracked settings.local.json, now lasts for the session only. That stops new leaks of this kind but does nothing for secrets already pushed.

How do I check if my repository leaked secrets through Claude Code?

Search your organisation's repositories, including full git history, forks, container images and published packages, for .claude/settings.local.json and .claude/settings.json. Read the allow rules for inline passwords, tokens, connection strings and VAR=value prefixes, since generic scanners can miss them.

Do other AI coding agents leak secrets the same way?

GitGuardian says it checked 30 kinds of agent configuration files and found secrets in all of them, including CLAUDE.md and Codex auth files. Apiiro reported that of 16 coding agents it compared, only Claude Code was confirmed to save the full approved command in a project file by default.

Can gitleaks or TruffleHog find these secrets?

Only partly. According to Apiiro, as reported by The Hacker News, gitleaks flagged 564 of the 1,122 files that held secrets and TruffleHog flagged 643, while 215 files were missed by both, mostly because the secrets sit inside shell commands.

Keep reading

Claude Codesecrets leaksettings.local.jsonAI coding assistantssecret scanningGitHubcredential rotation