> ## Content Index
> Fetch the complete content index at: https://blog.netpy.in/llms.txt
> Use this file to discover other available public pages before exploring further.

# Your agent's permission file is a secrets ledger
- URL: https://blog.netpy.in/claude-code-settings-secrets-rotation/
- Published: 2026-11-22T18:41:09.000Z
- Updated: 2026-11-22T18:41:09.000Z
- Description: Apiiro and GitGuardian found thousands of live credentials in .claude/settings.local.json on public GitHub. Why deleting the file fixes nothing, and the rotation order that does.
- Author: Netpy Technologies
- Tags: Security, AI, Dev Tooling, Secrets, Engineering

A developer needs to check staging. The agent proposes `PGPASSWORD=hunter2 psql -h staging-db.internal -U app -c "select count(*)"`, and they answer **"Yes, and don't ask again"** because they will be doing this all afternoon.

That click writes the entire command — password included, plain text — into `.claude/settings.local.json`. The file is JSON, it sits next to the code, and it is one `git add .` away from permanent.

Two studies have now measured what happens next.

## What the studies found

Apiiro scanned public GitHub and found **104,185 copies of that file across 103,617 repositories**. About 1.1% — 1,122 files — held at least one secret, 1,379 in total. More than a third open a database directly (379 database passwords), plus 43 SSH logins, 42 GitHub, GitLab and npm tokens and 23 AWS keys, across 63 organisations. One affected file held the owner password of a medical-records database. The median leaking file had sat on its default branch for **217 days**.

GitGuardian ran the wider query: continuous monitoring from January 2025 to 7 November 2026 found **31,088 distinct secrets in the same file across 23,276 repositories**, 5,343 still valid at detection — 17%. The live bucket is mundane: 1,955 distinct valid Postgres connection strings, 941 Google API keys, 186 DeepSeek keys.

Apiiro counted what is exposed today without testing validity; GitGuardian counted everything ever pushed. The second number is your rotation backlog.

## The protection is machine-local

Claude Code is not careless by accident. The first time it writes the file inside a git repository, it adds the path to the **user's global git excludes**. Git on that laptop then ignores the file everywhere.

That is where it stops. The rule is not in the repository's own `.gitignore`, so nothing travels with the project. A folder that becomes a repo later, a fresh clone on a colleague's machine, a file committed before the rule existed — none inherit it. In 539 of the 1,105 repositories Apiiro traced, Claude was a co-author on the commit that changed the file.

Boris Cherny, who leads Claude Code, says the team is investigating and that exposed copies were likely committed by hand. GitGuardian's rebuttal: across roughly 3,000 occurrences, every secret sat in an allow rule of the exact shape the permission prompt writes.

## Deleting the file fixes nothing

Deleting the file does not un-leak a single credential. Old versions sit in git history — 734 further secrets across 509 repositories — and in **211 forks of 74 repositories**. Rewriting history does not reach forks, and it never reaches a container registry.

Docker is the quiet third exit. GitGuardian found 109,284 occurrences inside public Docker Hub images across 7,625 tags, 72% under `/app`, `/workspace` or `/usr/src`. `COPY . .` copies the working tree, not the index, so a file git ignores still ships unless `.dockerignore` lists `.claude/`. One valid Cloudflare token appears in 559 tags of a single image.

## Why your scanner stayed quiet

Generic scanners look for shapes: `AKIA` prefixes, PEM blocks, JWTs, high entropy. On the 1,122 leaking files, gitleaks flagged 564 and TruffleHog 643, and **215 were flagged by neither**. A password after `PGPASSWORD=` has no provider prefix; it is an ordinary word in an ordinary command line.

GitGuardian's placement data maps onto that gap. `curl` is half of all occurrences — mostly bearer tokens, low validity. The credentials that still work cluster where format scanners read worst: `psql`, `mysql` and `mongosh` rules valid more than half the time, `sshpass -p` at 54%.

## The gateway key is the expensive one

`.claude/settings.json` is the file teams commit on purpose. A quarter of its leaking versions carry an `env` block pointing Claude Code at a third-party Anthropic-compatible gateway — `ANTHROPIC_BASE_URL` plus `ANTHROPIC_AUTH_TOKEN` aimed at DeepSeek, OpenRouter, Z.ai, MiniMax or Kimi. The credential that leaks is the gateway's: 205 valid DeepSeek keys, 62 OpenRouter, 50 MiniMax. Real Anthropic keys are rare in both files.

That is a billing risk before it is an access risk — someone else's token bill, someone else's rate limits, and a request log you will be explaining to a client.

## What we changed ourselves

We run coding agents on our own repositories daily, so this is our hygiene problem too. The reframe that stuck: **a permission file is production state with a lifetime**, and git ignoring it on the machine that created it is not a control — the same lesson as the [agent attack surface](https://blog.netpy.in/ai-agents-attack-surface/) and the [canary work on AI routers](https://blog.netpy.in/ai-router-prompt-leakage-canaries/).

Second, separate revocation from cleanup. Rotating a key finishes in one API call; removing a file is a promise about copies you do not control. Reverse the order and you will feel done while a fork still holds the credential. We also treat `.claude/`, `.cursor/`, `.codex/`, `.mcp.json` and `CLAUDE.md` as secret-bearing: GitGuardian found 6,155 distinct secrets in `CLAUDE.md` alone, 2,537 valid.

## The checklist

1. Search every repo for `.claude/settings.local.json` and `.claude/settings.json`, including deleted files in history.
2. Rotate every credential those files ever held — before touching git.
3. `git rm --cached .claude/settings.local.json`, then add it to the repo's own `.gitignore`.
4. Add `.claude/` to `.dockerignore`; check images already in the registry.
5. Delete every local rule containing a secret — `/permissions` lists them.
6. Reference secrets as variables (`$DATABASE_URL`), so the rule records the name, not the value.
7. Approve narrow patterns (`Bash(npm run:*)`), never `Bash(curl:*)`, which green-lights any curl a prompt injection writes.
8. Teach scanners rule grammar: a `VAR=value` prefix, a password flag or userinfo in a URL is a finding at any entropy.
9. Audit `settings.json` env blocks for gateway tokens and cap their spend.
10. Prefer auto mode with sandboxing over permanent approvals — Anthropic's guidance, and what [90% agent-written code](https://blog.netpy.in/anthropic-verification-loop-90-percent/) requires.

None of this argues against the tools. It is the pattern from every agent finding this year: permission state, transcripts, memory files and handoff notes were convenience features first, and they are now where credentials live.

*Header photo: Rawpixel, CC0 1.0.*