Key takeaways

  • When you click "Yes, and don't ask again" in Claude Code, the approved shell command is saved in .claude/settings.local.json. If that command contained a password or API key, the key is saved too.
  • GitGuardian found 31,088 distinct secrets in this file across 23,276 public GitHub repositories, and 5,343 of them were still valid when detected.
  • Anthropic's Claude Code lead said the file is gitignored when Claude Code creates it, so the leaks come from copied, tracked or Docker-built files. As of the reports below, no fix has shipped.
  • Deleting the file from GitHub does not fix this. Rotate every key that was ever in it.
  • Treat all AI tool config files like .env files: scan them, ignore them, and keep secrets out of commands.

The Claude Code secrets leak in plain words

In the first half of November 2026, two security companies reported the same problem from two angles. GitGuardian published its research on 9 November, and CSO Online covered it on 11 November. A separate study by Apiiro, summarised by AI Weekly the same day, reached the same conclusion with a different sample.

Here is the problem. Claude Code asks permission before it runs a shell command. One of the answers is "Yes, and don't ask again." When you choose it, Claude Code writes an allow rule into .claude/settings.local.json so it never asks about that command again. The rule is the full command string. If you ran a command that had an API key in a header, a password in a flag or a token in a URL, the key is now stored in plain text in a project file.

Most people never open that file. They commit the project, push it to GitHub, or copy the whole folder into a Docker image. That is how secrets end up public.

This guide explains what was found, how to check your own projects in about 15 minutes, and how to stop it happening again. If you use any AI coding tool, the same habits apply. The wider risk is covered in AI coding agents are a security risk.

What the research found

These are GitGuardian's numbers, covering public GitHub data from January 2025 to 7 November 2026:

What was scannedDistinct secrets foundWhereValid when detected
.claude/settings.local.json31,08823,276 public repositories5,343
.claude/settings.json8,2716,839 public repositories1,283
Docker Hub images613543 image repositories99

Which secrets were valid? The biggest group was database identifiers, with 2,280 valid credentials, of which 1,955 were Postgres connection strings. The rest included Google API keys, SSH passwords, Telegram bot tokens, email service keys and AI provider keys.

Two details are worth knowing:

  • The trend is going down, but nobody knows why. Monthly leaks in the settings file peaked at 12,535 in April 2026 and fell to 959 in October, a drop of about 92%. GitGuardian's researcher said they do not yet know what changed.
  • Be careful with the percentages. Of the 31,088 secrets, 5,343 were valid at detection, which is about 17%. A higher figure of 67% quoted in some coverage applies only to secrets whose validity could be checked. Use the number that matches the group you are talking about.

Apiiro looked at 104,185 public copies of the same file in early November. Outlets report its totals differently (one summary gives 2,539 secrets in 1,994 repositories, and the body of the same page gives 1,379 credentials), so treat Apiiro's study as supporting evidence rather than a number to quote.

What Anthropic said, and what is still open

Boris Cherny, who leads Claude Code, acknowledged the problem and said the team is looking at it, including built-in secret scanning and an auto mode. He also said Claude Code adds the file to the gitignore list when it creates it. GitGuardian's author therefore believes many leaked copies were created or committed by hand, and that Docker builds are a second route, because COPY . . copies ignored files too.

Anthropic did not respond to CSO Online's request for comment, and the reports say no fix has shipped. Check the Claude Code release notes for changes before you rely on any built-in protection. Apiiro adds that the global ignore does not cover files that were already tracked, or folders that became repositories later.

Step 1: Find the files in your projects

Run these checks in every project where you used Claude Code, and in any project that other people touched:

git ls-files | grep -E '^\.claude/|\.mcp\.json|CLAUDE\.md'
git log --all --oneline -- .claude/settings.local.json

The first command shows whether the files are tracked in your repository. The second shows whether the settings file was ever committed, even if you deleted it later. Git history keeps old versions, so a file removed last month can still leak today.

Also check your Docker images. If your Dockerfile has COPY . . and no .dockerignore, the working folder, including .claude/, can end up inside the image and inside your registry.

Step 2: Rotate every key that was ever in the file

This is the step that matters most. Removing a file from GitHub does not take the secret back, because forks, clones, caches and old images keep copies. Treat any key that was ever approved through the "don't ask again" box as exposed:

  1. List the commands you approved. Open .claude/settings.local.json or run the permissions command inside Claude Code and read the allow rules.
  2. For every rule that contains a key, password, token or connection string, create a new credential and revoke the old one at the provider.
  3. Update your n8n credentials, server environment files and CI settings with the new values.
  4. Check the provider's access logs for use you do not recognise, starting from the first date the file was public.

If you run n8n, include your n8n API key, webhook secrets, database URLs and any provider keys you ever passed on a command line.

Step 3: Clean the rules and stop new ones

After rotating, clean up so the problem does not come back:

  • Delete every allow rule that contains a secret.
  • Reference secrets by variable name, for example $N8N_API_KEY, so the saved rule contains the name and not the value.
  • Use narrow command prefixes. A broad rule such as one that allows every curl command approves much more than you meant to.
  • Do not choose "don't ask again" for any command that contains a credential. Approve it once instead.

Step 4: Block leaks before they leave your machine

Add the AI tool folders to both ignore files, and scan for secrets automatically:

  • Add .claude/ to .gitignore and to .dockerignore.
  • Treat .claude/, .cursor/, .gemini/, .codex/, .mcp.json and CLAUDE.md as secret-bearing, in the same way as .env.
  • Run a secret scanner such as gitleaks or TruffleHog in a pre-commit hook and in CI, and scan your git history and container registry once.
  • Make sure your scanner can find passwords inside commands, not only keys in well-known provider formats. GitGuardian reports that generic detectors caught 63% of the occurrences in this file.

My own check

I checked my own projects for this problem. Here is what I found:

What I checkedResult
Projects scanned[TODO]
Projects with a tracked .claude/ file[TODO]
Rules in the settings file that contained a key[TODO]
Keys I rotated[TODO]
Dockerfiles with COPY . and no .dockerignore[TODO]

[TODO: add one screenshot of your scan result with secrets hidden, and one sentence on what surprised you.]

A second lesson: agents also make plain mistakes

The same week, a law professor reported that Claude deleted his lecture notes and syllabus while renumbering pages in an editing task. Dropbox had copies and recovered everything. The point is not that one tool is worse than another. Any agent with write access can delete files, so keep versioned backups, give agents only the folders they need, and ask for a dry run before bulk edits. The article on cognitive surrender covers review habits for coding agents, and human-in-the-loop AI explains when an approval step is worth the friction.

Common mistakes

  1. Deleting the file and calling it fixed. The key is still in history, forks and images.
  2. Rotating only the keys you remember. Read every allow rule.
  3. Ignoring the Docker side. COPY . . ships files that git ignores.
  4. Clicking "don't ask again" on commands with keys. Approve once, or move the key to an environment variable.
  5. Broad allow rules. They approve more than you intended.
  6. No scanner. Humans do not notice a key inside a long command line.

Checklist for today

  • I listed the tracked AI config files in every project.
  • I checked git history for .claude/settings.local.json.
  • I rotated every credential that ever appeared in an allow rule.
  • I deleted allow rules that contain secrets.
  • .claude/ and other AI tool folders are in .gitignore and .dockerignore.
  • Secrets are referenced by variable name, not typed into commands.
  • A secret scanner runs before every commit and in CI.
  • I checked my Docker images and registry.
  • I have versioned backups of folders that agents can write to.

Where to go next

If you give agents real access, add a second layer: a way to stop them quickly. The guide on building an AI agent kill switch shows how, and NVIDIA OpenShell explained covers sandboxing agents.

FAQ

What is the Claude Code secrets leak?

It is a problem where approving a shell command with "Yes, and don't ask again" saves the full command, including any key inside it, in .claude/settings.local.json. Researchers found tens of thousands of secrets from this file in public GitHub repositories.

Is Claude Code the only tool with this risk?

The research covers Claude Code, but other AI coding tools also keep config files such as .cursor/, .gemini/ and .codex/. Treat all of them like .env files.

Is the settings file ignored by git automatically?

According to Anthropic's Claude Code lead, Claude Code adds the file to a git ignore list when it creates it. That does not protect files that were already tracked, copied by hand, or included in a Docker build with COPY . ..

I deleted the file from GitHub. Am I safe?

No. Git history, forks, clones and Docker images can still hold the key. Rotate every credential that was ever in the file.

Has Anthropic fixed this?

As of the reports from 9 to 11 November 2026, Anthropic said it is looking into safeguards such as built-in secret scanning, and the reports do not say that a fix has shipped. Check the Claude Code release notes for the latest status.

NEXT IN SERIES

CrowdStrike Just Launched an AI Kill Switch: How to Build One for Your Own AI Agents

CrowdStrike just launched an AI Kill Switch for rogue agents. Here is what it does and a 7-layer method, with code and an n8n pattern, to build an off switch for your own chatbots and automations.

Continue Reading