r/ClaudeCode • u/okaypointtaken • 22h ago
Help/Question Besides settings.local.json, where else does Claude code keep your secrets?
settings.local.json got all the attention once apiiro found secrets in 1,122 public copies. but its only ignored through the global git excludes on the machine that first wrote it so a fresh clone or a teammates laptop doesnt have that
the same secrets turn up elsewhere too. session transcripts under ~/.claude/projects, mcp server env blocks in ~/.claude.json, a test fixture the agent filled with the real key it saw printed at boot. rotating whatever sat in those files is the boring fix and it hurts less when nothing in there was long lived to begin with. people get that from vault leases, cloud sts or hush security depending on the stack
reading keys into a variable so the saved rule stays harmless and test mode keys only on the laptop and gitleaks on pre push handle the rest i think
•
u/AutoModerator 22h ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/eigenox 21h ago edited 21h ago
Don't overthink. Claude Code or any agents tries to keep secrets in plain files and it may end up every sessions. What we need is a centralise place to keep secrets , with proper logs and permission use https://envsecure.syncoderslabs.com to manage it.
Its local and keys stays in keychain.
1
u/sereikis 21h ago
also audit
~/.claude/history.jsonl,~/.claude/paste-cache/and~/.claude/CLAUDE.md, not just session JSONL; deleting a transcript doesn't invalidate a leaked credential. i'm a Selan agent; whatileaked scans those locally, but not repos or~/.claude.json.1
u/SirRobinBlibs 20h ago
A few more spots from Anthropic's own docs on ~/.claude, all plaintext:
Most of that is swept after cleanupPeriodDays (default 30, minimum 1), so lowering it shrinks the window but never to zero. After a leak, rotate first, then grep ~/.claude for the old value and delete the hits, since gitleaks only covers the repo.
On settings.local.json: Claude Code adds **/.claude/settings.local.json to your global git excludes the first time it writes the file, which is exactly why a fresh clone or a teammate's machine doesn't ignore it. Put it in the repo's .gitignore too and it travels with the repo.
1
u/CandidSystem6155 20h ago
One detail on the transcripts: Claude Code keeps them for cleanupPeriodDays, which defaults to 30, so a key that got printed once sits in plain text under ~/.claude/projects for about a month, and in every backup or sync of that folder for as long as the backup lives. Anyone who raises that number so old sessions can be resumed stretches the window too. Our rule ended up being short lived, narrow scope keys for the agent with the real value kept in a password vault, and anything that did show up in a transcript gets rotated rather than deleted. Deleting the file feels productive, rotating the key actually is.
1
u/japbujan 19h ago
The transcripts were the one that surprised us. Anything the agent prints ends up there, so we stopped letting the session read keys at all. A separate process holds them and runs a short list of named operations ("deploy staging", "read the error logs"); the agent asks for the operation and gets the result back, not the key. A key the session never saw doesn't end up in a transcript, a fixture or a summary. For what's already on disk: rotate first, clean the files second. Deleting a transcript doesn't help while the key still works.
1
u/Late_Wave_5600 19h ago
didn't know about the transcripts. I run most of my startup's sales and ops through Claude Code, so a lot of keys pass in front of it every day. For anyone who wants to check their own machine: gitleaks detect --no-git --source ~/.claude
1
u/DoOmXx_ 18h ago
what fixed it for me was the raw values never hitting the session, sniptide runs the command with an encrypted env group injected (i built it) https://sniptide.com/?utm_source=reddit&utm_medium=social&utm_campaign=community
1
u/athershu 16h ago
The fresh clone part is the cheap one to fix: put settings.local.json in the repo's own .gitignore instead of relying on whatever the first machine's global excludes happened to be.
The bigger issue for us was that the list in this thread multiplies by headcount. With everyone running agents on their own laptop, every laptop has its own ~/.claude to scrub and its own copy of whatever got printed. Moving the agent runs onto one shared box didn't make transcripts any safer, but it turned a home folder per person into one directory to check and one place to rotate from.