Keep your agent logs longer than your agent does
Claude Code deletes a session's log after 30 days by default, with its subagents' work. Gemini CLI does too. Why I keep a year, how to do it yourself, and how to keep the keys out.
On this page
Claude Code deletes a session's log 30 days after its last write. That is the default, and it takes the helper agents' transcripts, the saved tool output, the plans and the file snapshots with it. After day 30 I can't check what an agent did, why a change happened, or show anyone else.
I keep a year instead. My rule is simple: keep the logs, cleanse the keys. Logs are the only record of what an agent did, and they do hold secrets, so the answer is to take the keys out and not to delete the record. Here is what each agent deletes, what that costs you, and how to cleanse a long record.
What Claude Code deletes
Claude Code removes files under ~/.claude/ once they are older than cleanupPeriodDays. The default is 30, the minimum is 1, and 0 fails validation. The Claude Code docs list what goes:
- the session transcript,
projects/<project>/<session>.jsonl - the subagents' transcripts, which are removed with the parent
- large tool outputs saved beside the session, in
tool-results/ - pre-edit file snapshots, in
file-history/, which hold only the 100 most recent checkpoints - plan files and debug logs
Your typed prompts in history.jsonl stay until you delete them. Everything else in that list does not.
Most of what a session leaves is not the transcript. On my Mac, ~/.claude/projects held 325 session transcripts, 2,069 subagent transcripts and 779 saved tool outputs when I counted on November 25. If you only copy the .jsonl files at the top, you miss most of it.
What the other agents keep
I only list what I could find in the vendors' own pages.
| Agent | What I found |
|---|---|
| Claude Code | Deletes after 30 days by default. Docs |
| Gemini CLI | Session cleanup is on by default. sessionRetention.maxAge defaults to "30d". Docs |
| Codex | I found no setting that deletes sessions by age in the config reference. It has history.max_bytes, which caps history.jsonl by dropping the oldest entries. I did not read every key on the page. On my Mac Codex keeps older sessions as .jsonl.zst files. |
| GitHub Copilot CLI | Keeps a session's record under ~/.copilot/session-state/. I found no expiry in GitHub's docs. Sessions also sync to your GitHub account by default. |
| Cursor | I found no documented retention period. A Cursor staff reply on the forum says there is no automatic retention or eviction for old agent sessions. Other users report history lost after an update. |
So "your agent keeps its logs" depends on the agent, and on the version. Two of the five delete by age, and I found no promise from any of them that a record is kept for you.
What you can't do without the log
After the log is gone you can't:
- Check what an agent did. The transcript is the only record of the commands it ran and the files it read. Reading it by hand only works while it exists.
- Explain a change. A bug in March, traced to a commit in February, written by a session in January. The commit message says "fix". The session said why.
- Show anyone. A reviewer, a client or an auditor can't take your word for what happened.
Why a year
Recall and debugging. I look things up in old sessions more than I expected. What did I tell it to do? Which approach did it try first?
Reviewing agent work. The tests passed. The patch looks fine. The log shows whether the agent edited the test to get there. In the review gap, several outside studies found that passing tests overstated correctness. A review that can read the log catches more than one that reads only the diff.
Client and team audit. If an agent changed a client's system, "I can show you the session" is a better answer than "I think it was a script."
Compliance evidence. Be careful here, because the rules are narrower than the marketing.
- The EU AI Act requires automatic logging and a retention period of at least six months, for high-risk AI systems only. Article 12 covers logging, Article 19 covers providers keeping logs, and Article 26 covers deployers. The Act's own site gives 2 December 2027 for the Annex III duties. A coding agent is not automatically a high-risk system, and I am not saying yours is.
- ISO/IEC 42001 has an event-log control, A.6.2.8. The standard is paywalled. From a summary, you decide at which life-cycle phases logging is on, and at minimum when the system is in use.
- SOC 2 is the AICPA's criteria set. I could not read the criteria PDF, which needs a free account. Vendor write-ups say an auditor wants evidence of who requested and approved a change, such as Teleport's. Teleport also recommends keeping logs for at least a year. That is a vendor's advice, not a rule.
None of these says to keep Claude Code transcripts for a year. They do ask for a record of what happened, kept for as long as someone may ask about it. A log you kept is something you can offer. A deleted log is not.
Patterns over months. What does each of my agents get wrong again and again? You can't see a pattern in 30 days that took six months to form.
The tension: logs hold secrets
Shorter retention is one way to shrink that risk, and it is the one the vendor's docs name. My guides now say to rotate the key and take it out of the log instead. Claude Code's docs say transcripts are not encrypted at rest, and a key an agent read or a command printed is in there. Backslash, a security vendor, reports that about 3 in 4 secrets in the session histories it studied came from the agent's own work.
Shorter retention means a smaller pile of exposed keys. It also means no record. I want the record, so I keep it under three conditions (see the Claude Code logs guide and the keys post):
- It stays on your Mac, compressed, readable only by you. Owner-only permissions, on a disk that is encrypted.
- Any copy that leaves is encrypted before it leaves. Not after, and not by a service you hope is careful.
- You get the keys out of the logs and rotate them. A key that has been replaced at its provider is harmless in an old log. Find them without printing them, replace them at the provider first, then take the keys out of the logs and keep the logs. Excellent's Remove keys from the logs does that for supported key formats in the logs it can edit, and it can't be undone. By hand, edit the matching lines out of each file. The keys doc covers it.
Those three make a long record safe enough to keep. Skip them and you have a year of plain-text keys.
Do it yourself, without Excellent
Two steps. Raise the setting, and copy the files before anything else deletes them.
In ~/.claude/settings.json:
{
"cleanupPeriodDays": 365
}That makes Claude Code itself keep its files for a year. A copy still protects you from a setting that gets reset, a managed policy or a bug. Make a folder only you can read and copy into it:
mkdir -p -m 700 ~/agent-log-archive
rsync -a ~/.claude/projects ~/.claude/file-history ~/.claude/plans ~/.claude/tasks ~/agent-log-archive/claude/
rsync -a ~/.codex/sessions ~/.codex/archived_sessions ~/agent-log-archive/codex/Don't add --delete. Without it, a file stays in the copy after the agent removes the original. Run it at least every two weeks, because a log is deleted 30 days after its last write. Don't copy ~/.claude/.credentials.json or ~/.codex/auth.json. Those are your sign-ins.
One more catch. file-history can hold a snapshot of a .env file the agent edited, and the snapshot's name doesn't say so. Treat that folder as sensitive.
If a copy ever leaves your Mac, encrypt it first. A tool like age does that:
tar -c -C ~/agent-log-archive . | age -p -o agent-logs.tar.ageWhat Excellent does
Excellent's Keep a year of agent logs does the copy for you. It shipped in 1.0.4. It is free, off until you turn it on, and it uploads nothing. In Settings, under Agent logs, turn on the switch.
- It keeps a compressed copy for a year. On six large Claude Code sessions from my Mac, 558 MB became 115 MB.
- It copies the subagents' transcripts and what a session leaves beside the transcript, and Codex's logs too.
- Folders are owner-only. It never copies sign-in files or
.envfiles. - A copy stays after the agent deletes its log.
Its Remove keys from the logs fix rewrites supported key formats in the logs Excellent can edit, in place, and it can't be undone. Rotate the key first. Since Mac 1.3.0 the archive takes the keys Excellent recognizes out as it copies, and the fix cleans the archive's own copies too; the doc says what it covers.
It has limits. It has no search yet, so you open the folder in Finder. It doesn't copy logs outside your home folder. The doc lists them.
Mac 1.2.0 keeps copying with Excellent closed: a login item copies every hour and when you log in. With the archive on, it also raises Claude Code's cleanupPeriodDays to match the archive. It never lowers it, and it puts it back when you turn the archive off.
Encrypted backup is a separate switch for a copy off your Mac. It is locked on your Mac before it leaves, with a key that stays on your Macs, so Excellent can't read it. API keys and tokens in your logs are replaced before anything leaves your Mac. You get 5 GB free, then $12 a year per 50 GB, plus any tax. It shows you a recovery key once. If you lose it and no signed-in Mac has the key, nobody can restore the backup, Excellent included.
Run the free scan to see what your logs hold today.
Sources checked on November 29, 2026. The agents' retention settings change between versions, so check your own version's docs.
