Allow users to control session retention (disable automatic pruning)
Problem
Claude Code automatically prunes session .jsonl files at a hardcoded limit of ~32 per project directory (~/.claude/projects/<encoded-path>/). When a new session is created beyond this limit, the oldest session file is silently deleted.
This is destructive for users who rely on --resume to return to sessions containing carefully curated context for specific problems. Named sessions (via sidecar tooling) become orphaned references pointing to deleted files. There is no warning, no configuration, and no way to opt out.
Concrete impact: I name important sessions to preserve investigation context (debugging sessions, infrastructure buildouts, multi-day ticket work). 9 of my 20 named sessions have already been deleted by automatic pruning. That context -- tool call history, investigation state, decisions made -- is gone and cannot be reconstructed.
Requested Behavior
A configuration option (in ~/.claude.json or settings.json) to control session retention:
{
"sessionRetention": {
"maxSessions": 0,
"prunePolicy": "manual"
}
}
Where:
maxSessions: 0(ornull/-1) means unlimited -- the user is responsible for pruningmaxSessions: Nsets the cap (current default would be 32)prunePolicy: "manual"disables automatic deletion entirelyprunePolicy: "auto"preserves current behavior (default)
Alternatively, even a simple boolean like "autoDeleteSessions": false would solve the problem.
Why This Matters
Sessions are not throwaway artifacts. For users working on infrastructure, multi-day investigations, or complex debugging:
- Sessions contain curated context that took significant effort to build (tool calls, file reads, investigation paths, decisions)
--resumeis the primary mechanism for continuing work across restarts- Automatic silent deletion works against the user, not for them
- Disk space is cheap; lost context is expensive
Users who want cleanup can run claude sessions prune or equivalent tooling. Users who want to keep their sessions should be able to.
Current Workaround
There is no reliable workaround. Options under consideration (all have drawbacks):
chflags uchg(macOS immutable flag) on session files -- may cause Claude Code errors- Hardlink archiving via cron -- data survives but
--resumecan't find archived sessions - Periodic backup -- race condition between backup interval and deletion
Environment
- Claude Code CLI (macOS)
- Session files:
~/.claude/projects/<encoded-path>/<uuid>.jsonl - Observed limit: 32 sessions per project directory
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗