When Claude Code deletes transcripts: the cleanupPeriodDays default and how to change retention
Claude Code stores transcripts in plain text under ~/.claude. What cleanupPeriodDays does (default 30 days, minimum 1), what the sweep deletes and skips, and how to stop writing.
Contents
Claude Code writes the whole conversation, every message, tool call, and tool result, to ~/.claude/projects/<project>/<session>.jsonl in plain text. If a tool reads .env, its contents land there. If a command prints a token, so does the token.
In short: retention is controlled by cleanupPeriodDays in settings.json, with a default of 30 days. You can shorten it to reduce exposure, and there are ways to stop writing transcripts altogether.
KEY POINT
What you will learn
- The default and minimum for
cleanupPeriodDays, and why 0 is rejected - Which files the sweep deletes and which it leaves alone
- How to stop transcripts being written, and how to purge one project
How cleanupPeriodDays works
| Item | Value |
|---|---|
| Default | 30 days |
| Type | whole number, minimum 1 |
Setting 0 | fails validation |
| Where | any settings file; the highest-priority layer that sets it wins |
| When it runs | a background sweep after a session starts |
{
"cleanupPeriodDays": 7
}
There is no "never delete" value. For long retention, use a large number such as 3650.
用語解説
Retention sweep: the background deletion that runs after a session starts. If Claude Code cannot safely determine the retention period, for instance because a settings file cannot be read or parsed, it pauses the sweep, and shows a warning in /status when the broken settings explicitly set cleanupPeriodDays. When managed settings provide the value, the sweep runs at that value regardless.
What gets deleted and what does not
Paths removed once they are older than cleanupPeriodDays:
Under ~/.claude/ | Contents |
|---|---|
projects/<project>/<session>.jsonl | the full conversation transcript |
projects/<project>/<session>/subagents/ | subagent transcripts, removed with the parent |
feedback/drafts/ | queued /feedback drafts, after cleanupPeriodDays or 30 days, whichever is shorter |
todos/, statsig/, logs/ | legacy directories; contents and then the empty directory are removed |
Not covered by the sweep:
history.jsonl: every prompt you typed, used for up-arrow recall andCtrl+R; kept until you delete it- auto memory:
projects/<project>/memory/is not deleted; the directory goes only if it stayed empty for the whole period - Claude Desktop and Cowork sessions: kept at any age by default;
desktopSessionCleanupPeriodDaysadds a limit (v2.1.248 or later) stats-cache.json: the aggregates shown by/usage
desktopSessionCleanupPeriodDays deletes a transcript only when it is older than both that value and cleanupPeriodDays, so with the default 30 a value of 7 still keeps them 30 days.
Not writing transcripts at all
Beyond shortening retention, you can stop the recording itself.
CLAUDE_CODE_SKIP_PROMPT_HISTORY=1 claude
The .claude directory page says this variable skips writing transcripts and prompt history in any mode. The environment variables page describes it as disabling loading of prompt history from disk, so the two descriptions differ. In non-interactive mode you can instead pass --no-session-persistence alongside -p.
Bare mode, -p with --bare, does not run the sweep in that session at all.
Keep credentials out in the first place
A short retention period still leaves plain-text files on disk until they age out. Deny reads of .env and key files before relying on retention. The rules are covered in Keeping secrets away from AI coding tools.
Purging one project
claude project purge deletes the state Claude Code holds for a single project in one go. Data use for training is a separate question from local retention; local context management in general is covered in Managing context in Claude Code.
Summary
- Transcripts are stored in plain text under
~/.claude/projects/and deleted aftercleanupPeriodDays(default 30, minimum 1) 0is rejected; use a large value such as3650for long retentionhistory.jsonl, auto memory, and Desktop/Cowork sessions are outside the sweep; Desktop gets its own keyCLAUDE_CODE_SKIP_PROMPT_HISTORY=1stops writing;--no-session-persistencedoes the same for-p- Deny credential reads up front, and use
claude project purgeto wipe one project
FAQ
- Can I set cleanupPeriodDays to 0 to keep transcripts forever?
- No. 0 fails validation. Use a large value such as 3650 for long retention. The minimum is 1.
- Are transcripts encrypted?
- No. OS file permissions are the only protection. A .env a tool read, or a credential a command printed, is stored as is.
- When does deletion run?
- As a background sweep after a session starts. A settings error that prevents determining the retention period pauses the sweep.
Primary sources
This article was drafted by AI from official documentation and reviewed by the site operator before publishing. Found a mistake? Let us know via the contact page.