r/ClaudeCode • • 7d ago

Discussion Agent transcripts are the new .env

https://kosem.ai/blog/agent-transcripts-are-the-new-env
196 Upvotes

18 comments sorted by

•

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

37

u/defeatedsnowman 7d ago

I need vibe coders to continue to commit their transcripts so I can read them and laugh my ass off though.
https://www.reddit.com/r/BetterOffline/comments/1xrcwam/the_absolute_state_of_vibecoding/

39

u/Starks1293 7d ago

the boring fixes cover most of it

  • deny reads on the secret files so the value never enters the transcript in the first place. permissions.deny with Read(./.env) and Read(./.env.*) in .claude/settings.json, same for any secrets folder
  • run things through op run or doppler run so the process gets the env at runtime and the agent only ever sees the reference, not the value
  • the transcripts are plain jsonl under ~/.claude/projects, so point gitleaks or trufflehog at that folder once. whatever it finds already leaked, rotate it
  • cleanupPeriodDays in settings controls how long they hang around (30 days by default), drop it if u dont need old sessions
  • keep ~/.claude out of dotfile repos and anything that syncs off the machine

and +1 to the rotate on confession rule above, its cheap and it builds the habit

6

u/here_we_go_beep_boop 7d ago

Yep, if you have the discipline to rotate on key spill, you'll quickly engineer things so they don't happen often, cos they're a PITA 

3

u/Usharani-Wiencke 6d ago

denying `Read` only gets you halfway if the agent still has bash access and decides to just `cat` or `grep` the file when it gets stuck

1

u/Starks1293 6d ago

yea fair, u and another commenter both caught that. a deny rule is a speed bump not a wall, bash can cat it and python can open it. the real fix is the second bullet, dont keep the value anywhere the agent can reach and inject it at run time instead

7

u/Far_Reindeer8428 7d ago

we hash and strip on the way into the transcript, the raw tool output never lands on disk. the cost is you cannot replay the exact session later

6

u/here_we_go_beep_boop 7d ago edited 7d ago

Write tools that agents can run so they literally can't see the secrets. Local .env files are so last year. 

In our org it's a key rotation incident if an agent confesses to seeing a key, and the org wide agents.md prompts for immediate disclosure. There's also a shared skill that lodges the incident report and so on.

Not ironclad but works in practice, we aren't defense or finance or anything sensitive but our customers would be pissed and we'd be very embarassed by a spill

3

u/DoOmXx_ 7d ago

+1 on permissions.deny for .env. the other half is not having real values sitting in a file at all, inject them at run time with op run or doppler, sniptide env does the same. then a leaked transcript mostly has variable names in it

2

u/karol207 7d ago

For a key that leaked before expiry, I'd check any audit logs for that window too. Expiry won't undo a data export that already ran.

1

u/Ok-Distance-6388 7d ago

`permissions.deny` on `.env` helps, though two leaks still slip through in practice: failed `curl` / HTTP client logs dumping `Authorization` headers into tool output, and `mcp.json` or shell history getting read when debugging a broken server.

Short-lived scoped tokens (sandbox-only or expiring in an hour) cut the blast radius way more than redaction regexes ever do.

Are you running any secret scanner on your transcript dir before backups or sync, or relying on short-lived keys?anscript dir before backups or sync, or relying on short-lived keys?

1

u/Senior-Assumption864 7d ago

denying reads on env files is such a simple fix, easy to skip though

1

u/plain_meridian 6d ago

Not only .env either, my agent reads pages in my logged-in browser and all of that text ends up in the transcript too. Deny rules don't help there

1

u/Independent_Ad7172 6d ago

The logged-in browser case is the one deny rules can't cover. What helps is routing the agent through small scripts that return only the fields it needs as JSON, so cookies and headers never enter the transcript. Page text still does whenever it reads a whole page, so it narrows the leak rather than closing it.

1

u/BarathKanna 4d ago

Treat transcripts like logs, because that's what they are, and logs are where secrets go to retire publicly.

Three layers. Stop secrets entering the transcript at all: deny reads on .env files in the agent's permissions and inject real values at runtime from a secrets manager, so the file on disk only holds references. Scrub on the way out: a pre-commit hook running a secret scanner over any transcript or session folder, and add those folders to gitignore by default. Assume leaks anyway: short lived, narrowly scoped keys, so a leaked one is expired or useless by the time someone finds it.

And when one does leak, rotating isn't the end. Check audit logs for the exposure window, because expiry doesn't undo the export someone already ran.

1

u/keshavsm 2d ago

worth knowing where the deny rules stop. per the permissions docs they cover the read tool and the bash file commands claude code recognizes (cat, head, tail, sed, redirects). they don't cover a command that reads without naming the file, like grep -r from the project root, or a script that opens the file itself. so something like node -e 'require("dotenv").config(); console.log(process.env)' still prints the lot

also check the shell you launched claude from. if it has keys exported, every bash call inherits them and a plain env puts them in the transcript

and the old transcripts are just jsonl under ~/.claude/projects, so grep -rl 'sk-' ~/.claude/projects shows what's already sitting there from before you added the rules