brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: cleanupPeriodDays decides how long Claude Code keeps your old sessions

Claude
~/tips/tip-claude-code-cleanup-period-days

// ~/.claude/settings.json

Sets how many days Claude Code keeps transcripts and other session files before deleting them.

Claude Code quietly deletes your old sessions after 30 days. No warning, no prompt. One day a session you wanted to pick up is simply missing from the /resume picker. The setting behind that is cleanupPeriodDays, and I think it’s worth setting on purpose instead of living with the default.

After a session starts, Claude Code runs a background sweep over ~/.claude/ and removes everything older than the retention period. That covers the conversation transcripts in projects/<project>/<session>.jsonl, but also the file snapshots that /rewind uses, plan files from plan mode, debug logs and large pastes. Put the number of days in your user settings:

// ~/.claude/settings.json
{
  "cleanupPeriodDays": 90
}

Want to keep things for years? Use a big number such as 3650. Zero doesn’t work: the minimum is 1, and 0 fails validation. A broken value doesn’t fail quietly either, Claude Code tells you that it expected a number.

Retention cuts the other way too. A transcript holds every message, every tool call and every tool result. If Claude read a config file with a password in it, that password now sits in a plain JSONL file in your home folder. A long retention period means those files pile up. On a work laptop, or anywhere you care about that, a shorter period like 7 or 14 days is a reasonable trade, as long as you accept that older sessions can’t be resumed.

One more detail: sessions you started or last continued in Claude Desktop or Cowork follow their own rule. Since v2.1.248 Claude Code keeps those past this period by default, and a separate key, desktopSessionCleanupPeriodDays, sets their age limit.

Further reading: cleanupPeriodDays in the Claude Code settings reference, What Claude Code cleans up automatically

More Claude tips /recap /focus /skill-doctor /autocompact 500k claude purge ~/work/my-repo --dry-run All Claude tips (83) All topics

Link