Claude Code deletes transcripts after 30 days: cleanupPeriodDays and keeping your history
Published · Updated · Checked against Claude Code 2.1.319
Unless you change a setting, Claude Code removes session transcripts under ~/.claude/projects/ once they are 30 days old. The setting is cleanupPeriodDays in ~/.claude/settings.json. Put a large number there, such as 3650, and also copy the folder elsewhere on a schedule, because the setting is not always honoured.
What the docs say
The claude-directory page is explicit. Claude Code deletes the files below once they are older than cleanupPeriodDays; the default is 30 days, the minimum is 1, and 0 fails with a validation error.
Path under ~/.claude/ | What it holds |
|---|---|
projects/<project>/<session>.jsonl | The conversation transcript |
projects/<project>/<session>/subagents/ | Subagent transcripts, removed with the parent |
projects/<project>/<session>/tool-results/ | Large tool outputs spilled to files |
file-history/<session>/ | Pre-edit file snapshots used for checkpoint restore |
plans/, debug/, paste-cache/ | Plan files, debug logs, large pastes |
Some things the sweep leaves alone. history.jsonl, the prompts you typed with timestamp and project path, is trimmed by age only when a HIPAA configuration applies. Auto memory in projects/<project>/memory/ stays. Claude Desktop and Cowork transcripts have had their own setting, desktopSessionCleanupPeriodDays, since v2.1.248; earlier versions deleted them after cleanupPeriodDays.
The sweep is skipped for claude -p --bare runs, and it pauses when Claude Code cannot work out the retention period safely, for example when a settings file will not parse.
The deletion is documented, the warning is not
anthropics/claude-code#62476 asks for a first-run disclosure, a trash folder and a /config entry, and it is open. A maintainer reply on 17 August 2026 says they reproduced the behaviour on 2.1.233: a transcript backdated 40 days was deleted with default settings and kept with cleanupPeriodDays set to 3650. The sweep runs in the background a few seconds after startup. The maintainer called the deletion the documented default, not a malfunction, and left the warning and /config requests open as feature requests. In 2.1.233 the setting could only be set in settings.json.
The consolidation thread anthropics/claude-code#59248 is also open, and its commenters report things the docs do not mention. These are user analyses, not maintainer statements. Deletion keys on the file's modification time rather than the last timestamp inside the transcript, so a restore without -a, a sync client or anything else that rewrites mtimes can make a live session look old. Large values are reportedly ignored when settings load in some modes, such as --setting-sources local or an SDK call with an empty settingSources, which brings back the 30-day default. And deleting the parent .jsonl can leave orphaned subagents/ and tool-results/ folders.
Sources do disagree in one place. #90371 reports transcripts gone after about 9 days with the setting unset; no maintainer answered, and the bot closed it as not planned on 30 October 2026. The docs say 30 days, and a shorter period could be neither reproduced nor confirmed. If you see it, suspect the mtime explanation first.
Raise the limit
Edit ~/.claude/settings.json:
{
"cleanupPeriodDays": 3650
}
Then check that it was read. /status lists the settings files that loaded, and claude doctor lists entries Claude Code rejected. Settings files are strict JSON, so one trailing comma gets the whole file skipped and the default applies.
On a managed machine an administrator can set cleanupPeriodDays in managed settings, and your value will not win. /status shows whether a managed source applies.
Keep a copy outside ~/.claude
A mode, a managed policy or a bug can override a setting, but a copy outside ~/.claude cannot be overridden. Transcripts are append-only JSONL, so a plain copy is lossless. The one rule is not to mirror deletions.
mkdir -p ~/claude-sessions-backup
rsync -a ~/.claude/projects/ ~/claude-sessions-backup/projects/
rsync -a ~/.claude/history.jsonl ~/claude-sessions-backup/
With no --delete, a file the sweep removes from the source stays in the copy, and -a preserves modification times. To run it daily:
crontab -e
# add:
17 3 * * * rsync -a ~/.claude/projects/ ~/claude-sessions-backup/projects/
To restore one session, copy the file back into the matching projects/<project>/ folder; where Claude Code stores sessions explains how the folder name is built. For rsync, git and encrypted archives compared, see backing up Claude Code and Codex sessions.
When the transcript is already gone
Claude Code unlinks the file. There is no trash and no archive, so nothing inside the tool brings it back. These are worth trying, in this order.
- Look for set-aside copies. The docs list
<session>.orphaned-<timestamp>-<suffix>.jsonland<session>.jsonl.superseded-<timestamp>files, older transcripts that Claude Code kept instead of overwriting. They are swept on the same schedule. - Read
~/.claude/history.jsonl, which keeps your prompts but not Claude's replies. - Restore from Time Machine, Windows Volume Shadow Copies (Previous Versions), or a snapshot of your home folder.
- Check any copy you made yourself, or a backup tool that watched the folder.
If a resume error is what sent you here, read Claude Code "session not found" on resume.
Sealkeep and the sweep
Sealkeep leaves cleanupPeriodDays alone. It copies each session as it finishes, encrypts it on your machine and uploads it to your own storage, so the original can be swept without losing the history. sealkeep search <query> --content searches sealed sessions, and sealkeep recover <id> <dest> restores the original bytes.
It cannot recover a transcript deleted before you installed it, and it does not stop Claude Code from deleting. Install with curl -fsSL https://sealkeep.spala.ai/install.sh | sh (needs Node 22.15 or newer), or npm install -g sealkeep && sealkeep start.
FAQ
Does the setting also protect Claude Desktop sessions?
Not on its own. From v2.1.248, Desktop and Cowork transcripts are kept at any age unless you set desktopSessionCleanupPeriodDays. Managed settings or a HIPAA configuration switch them back to cleanupPeriodDays.
Will history.jsonl let me rebuild a deleted session?
No. It holds the prompts you typed, with a timestamp and project path, and none of the replies, tool calls or tool results.
Is deleting ~/.claude/projects the same thing?
Yes, and worse. The docs say deleting it loses resume, continue and rewind for past sessions, and auto memory for every project.
Docs read 10 November 2026; they reference releases up to v2.1.314, and the local install is 2.1.319.