Secrets in Claude Code transcripts: find them, rotate them, stop the leak
Published · Updated · Checked against Claude Code 2.1.319
Anything a tool reads or a command prints is written, unencrypted, to ~/.claude/projects/<project>/<session>.jsonl. Scan the folder with gitleaks, rotate whatever turns up, and cut what Claude Code can read in the first place. Redacting the files is the least important step.
What the docs say
The directory page states it plainly: transcripts and history "are not encrypted at rest. OS file permissions are the only protection. If a tool reads a .env file or a command prints a credential, that value is written to projects/<project>/<session>.jsonl." The transcript also holds the system prompt, tool definitions and the instruction files Claude Code loaded.
That file is not the only copy. The same page lists paste-cache/ (large pastes), projects/<project>/<session>/tool-results/ (large tool outputs), file-history/ (pre-edit snapshots of files Claude changed), debug/ logs, and ~/.claude/history.jsonl (prompts you typed). A heap dump from /heapdump holds the full conversation and any credentials the process held, and neither the retention sweep nor claude purge removes it.
Two upstream requests, both closed
#50014, opened 17 Apr 2026, asked for secret scrubbing and rotation of session logs. The reporter found 5 distinct secrets across 34 session files (418 MB) after about 30 days of use. The stale bot closed it as "not planned" on 16 Jul 2026.
#63593, opened 29 May 2026, asked for redaction at write time. The reporter's private dotfile-sync repo mirrored ~/.claude/ and triggered 15 GitHub secret-scanning alerts. It was closed as a duplicate of #50014 on 2 Aug 2026.
Claude Code has no documented built-in redaction of transcripts on disk. Claude Code does redact known key and token patterns in two other places, per the data usage page: error reports, and transcripts you choose to upload through the session-quality follow-up. That covers outgoing data, not your disk.
Step 1: find them
gitleaks (8.30.1 here, on macOS with Claude Code 2.1.319) scans a directory with dir:
gitleaks dir ~/.claude/projects --no-banner --redact -f json -r /tmp/findings.json
jq -r '.[] | "\(.RuleID)\t\(.File):\(.StartLine)"' /tmp/findings.json | sort | uniq -c | sort -rn | head
--redact keeps matched values out of the printed report. The report gives file and line, enough to know which session to open, and a rule name that tells you which provider to rotate with.
Expect it to be slow. Transcripts are large JSONL files with very long lines, and a 1.6 GB project folder took more than two minutes on a laptop. Start with the newest sessions or one project, then run it again on ~/.claude/paste-cache, ~/.claude/file-history and ~/.claude/debug.
TruffleHog is the other common choice:
trufflehog filesystem ~/.claude/projects --results=verified,unknown --json
Its README says it checks whether a secret is live by testing it against the provider's API, which means the candidate secret is sent to that provider. Pass --no-verification if you do not want that. The payoff is fewer false alarms, since a verified result is a live credential. TruffleHog was not run; the flags come from its README.
Neither tool finds everything. A custom internal token, a password in a connection string or a key in an unusual format can slip past, and both match patterns, so an obvious placeholder may be reported too.
Step 2: rotate
A secret in a transcript on your own laptop is a limited risk. One in a transcript that was backed up, synced, shared or committed has left. Rotate any credential that appears in a file that did leave, and anything the scanner marks as live. Rotation fixes the exposure; redaction does not, because you cannot be sure where else the file went.
Step 3: redact a copy, if you must
Work on a copy, never on the only transcript. How claude --resume reacts to an edited transcript is untested, so keep the original until you have.
cp session.jsonl session.redacted.jsonl
gitleaks dir session.redacted.jsonl --no-banner -f json -r /tmp/r.json # no --redact: the report holds the secrets
chmod 600 /tmp/r.json
jq -r '.[].Secret' /tmp/r.json | sort -u > /tmp/secrets.txt
python3 -I - <<'PY'
import pathlib
p = pathlib.Path("session.redacted.jsonl")
s = p.read_text()
for sec in pathlib.Path("/tmp/secrets.txt").read_text().splitlines():
if sec:
s = s.replace(sec, "[REDACTED]")
p.write_text(s)
PY
jq -c . session.redacted.jsonl > /dev/null && echo "still valid JSONL"
shred -u /tmp/r.json /tmp/secrets.txt 2>/dev/null || rm -P /tmp/r.json /tmp/secrets.txt
On a one-line test file with a fake GitHub token, gitleaks matched it, the replacement worked and the file still parsed. gitleaks ignored the AWS documentation example key AKIAIOSFODNN7EXAMPLE in that test, so placeholders are not always flagged. The unredacted report contains the secrets, which is why it is chmod 600 and deleted at the end.
Step 4: stop the leak
You cannot make Claude Code stop writing transcripts and keep resume, but you can reduce what gets in and how long it stays. Everything here is in the directory docs.
- Deny reads of credential files with permission rules, so
.env,~/.aws/credentialsand key files are never read. A secret that is never read is never written. - Do not print secrets.
printenv,env,cat .envandecho $TOKENput values into tool output; say so in CLAUDE.md. - Shorten retention with
cleanupPeriodDays, trading safety against lost history (Claude Code silently deletes transcripts after 30 days). - Skip persistence entirely with
CLAUDE_CODE_SKIP_PROMPT_HISTORY, or--no-session-persistencewith-pin non-interactive runs, and expect to lose resume. - Do not mirror
~/.claudeanywhere you cannot trust. That was the #63593 incident; see back up Claude Code and Codex sessions. - Encrypt at rest if the machine is shared or may be lost: encrypting coding-agent transcripts at rest.
Codex rollout files are plain JSONL too. No official Codex page covers retention or redaction, so scan ~/.codex/sessions the same way.
What Sealkeep scans
sealkeep scan <path> finds pasted secrets in sessions. sealkeep scan policy off|record|block-high sets what happens at backup time: nothing, record the finding, or block a high-severity one. In a company, an admin registers a scanner with sealkeep org scanner add <name> --policy record|block-high and attaches it to a project, and every machine sealing into that project follows it.
It does not rewrite or redact your transcripts, and scanning leaves the local original unchanged. The README says plainly that scanning reduces exposure but does not guarantee every secret is found. Sealing encrypts the backup copy; it does not stop the plaintext original on your disk from containing the secret.
FAQ
Does Claude Code redact secrets in transcripts?
Not on disk, as of 10 Nov 2026. It redacts known patterns in error reports and in transcripts you opt to upload. Requests for write-time redaction (#50014, #63593) were closed without a fix.
Are secrets in a transcript sent to Anthropic?
Everything in the conversation is sent to the model as context, so a secret that reached a tool result is part of what the model sees. That is separate from the file on disk. The data usage page covers retention by account type.
Is it safe to delete the transcript instead of redacting it?
As far as the secret goes, yes, at the price of resume for that session. claude purge <path> deletes the transcripts, memory and matching prompt history for one project, and --dry-run shows the plan first.
Do I need to rotate if the file never left my machine?
Judge by who can read the machine and its backups. If the folder was ever synced, committed, backed up to a cloud drive or shared, rotate.
Does Codex have the same problem?
Its rollout files are plain JSONL, so assume so. The Codex docs say nothing about retention or redaction.