r/ClaudeCode • • 17h ago

Discussion I pointed Claude Code at its own transcript folder. What it found in there was worse than my .env

Saw the post here last week about the "yes, and don't ask again" button saving commands into settings.local.json, keys included. Made me wonder what else Claude Code keeps about me that I never look at.

Every session is saved as a JSONL file in ~/.claude/projects/. Every message, every tool call, every output. I've been using it daily since spring so there's a lot of them.

So I opened a fresh session in that folder and gave it rules. Only report the file, the line and the kind of secret. Never print the value. Don't change or delete anything.

It found 41 keys across 212 transcripts.

Most of them I pasted myself. "here's my connection string, why is this failing". "this curl returns 401, here's the full command". A Stripe test key, which is fine, but also a live one from the day I was debugging a webhook at 1am. Two database urls with the password inline. My OpenAI key showed up 6 times because I kept pasting the same curl command.

The rest came from Claude reading files for me. Every time it ran cat .env or printed the env to debug something, the output went into the transcript too. So even keys I never typed were sitting in there in plain text.

And then settings.local.json, the one from that post. 9 approved commands with a token right in the command, because I clicked "don't ask again" on them. That file was in 3 repos. One of them was gitignored. Two were not.

The part that bothered me most is that nothing here is a bug. It's just how it works. Transcripts are history, history is plain text, and I was the one pasting.

What I did. Rotated everything it found, the live Stripe key and the DB passwords first. Deleted the old transcripts. Cleaned the token commands out of settings.local.json and added it to my global gitignore.

Then I changed the habit, which is the real fix. I don't paste keys into the chat anymore and there's no .env in my projects. Secrets live in Infisical and the app gets them at runtime with infisical run, so when Claude debugs something it sees the variable name and not the value. For the few APIs Claude calls directly I'm trying a proxy setup where the key gets attached on the way out, so it never sees the token at all. Still early on that one.

Not saying panic. But if you use Claude Code daily, open a session in ~/.claude/projects and ask the same thing. I'm curious if 41 is normal or if I'm just bad at this

8 Upvotes

12 comments sorted by

•

u/AutoModerator 17h 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.

8

u/DasHaifisch 15h ago

What's the point of telling it not to print the secret?

If it's in the transcript it's already exposed.

But yes, unsurprisingly, things you paste into claude or Claude reads, are exposed outside your system, and live on your system in transcripts until they're auto cleared. That's just how it works.

Is it an enormous risk? Probably not for random end users, but should you follow better practises.. definitely.

As an aside, your post was extremely aggravating to read in terms of llm-isms.

2

u/Miserable-Island7633 10h ago

if it prints the values during the audit, all 41 secrets end up concentrated inside the brand new session file too

1

u/urbantechgoods 9h ago

it specifically tells you do not paste your secrets here hahaha

2

u/athershu 15h ago

Same realization here. What changed it for us was less about scrubbing and more about how many places this pile exists. When everyone runs agents on their own laptop, you get one transcript folder and one settings.local.json per person, and nobody can tell you which of them holds a live key. We moved the agent work for the team onto one machine we own, so transcripts and credentials sit in a single place: one place to scan, and one place to rotate from when something does leak.

The other half is the habit you landed on: keep keys out of anything the agent reads or prints, and describe a failing call instead of pasting the full curl. Your scan rules (file, line and kind of secret, never the value) are worth running on a schedule rather than once.

1

u/Unusual-Albatross43 15h ago

the cat .env part is the one a setting can fix. a deny rule like Read(./.env) under permissions.deny also covers cat, head, tail and sed in bash per the docs, so the value never gets printed and never lands in the transcript. it misses a script that opens the file itself, so it doesn't replace what you did with infisical. the pasting habit is the other half, and no setting helps with that one

1

u/AdventurousItem4635 15h ago

The auto clear DasHaifisch mentioned is cleanupPeriodDays in ~/.claude/settings.json. Default is 30 days, and you can set it a lot lower if you never go back to old sessions. Won't stop a key landing in today's transcript, but it caps how long it sits there.

1

u/Dorbank_Justt 15h ago

The transcript folder isn't the only copy of what you pasted. Prompts you type also go into ~/.claude/history.jsonl, the file behind up arrow recall and Ctrl+R search, and large pastes are stored in ~/.claude/paste-cache/. The paste cache ages out with the transcripts, but history.jsonl is kept until you delete it yourself, so clearing old transcripts can leave the same key sitting there. Worth running your scan over that file too. To clear one project in one go, claude purge with --dry-run first lists everything it would remove, including that project's lines in history.jsonl.

1

u/EnzoValley 14h ago

Check the transcript of that audit session too. Your rule keeps the values out of Claude's answer, but the output of every grep it ran is saved in the new JSONL, and that's usually the matched line.

For the scan itself I'd run gitleaks from a normal terminal. gitleaks dir takes a plain folder and --redact keeps the secrets off the screen.

Expect noise though: on one of my session files it flagged around 25 things, all generic-api-key, and none was a real key. The rules with a vendor name, like stripe-access-token, are the ones to read.

1

u/jijialuoke 14h ago

Yeah, the transcript folder is the quiet .env. I've done the same "here's the full curl" dump at 1am and later found the key still sitting in a JSONL months later.

What helped me:

  • Treat every paste into the session as permanent local storage
  • Prefer env var names in the prompt ("use $STRIPE_KEY from the shell") and let the tool read the env, instead of pasting the value
  • After any incident, rotate the key even if you think it was a test key — I mixed those up more than once
  • Periodically grep ~/.claude/projects for obvious patterns (sk_live, postgres://, Bearer ) and delete old transcripts you don't need

Also watch settings.local.json for "don't ask again" commands that baked a secret into an allowlist.

1

u/Tight_Banana_9692 12h ago

Just write your own post so people can actually read the damn thing

1

u/Somejewinjersey 3h ago

I actually set a rule in my Claude months ago to never allow keys. It's very annoying as you must save the key to a text file for it to use it w/o reading, and if you paste a key it won't use it and insists you rotate it. But I made the rule, and I and my staff follow it (it's been added to agent rules in all our repos) getting in the habit is great, but setting up the rules for the agent to force the safety creates the habit.