Allow users to control session retention (disable automatic pruning)

Resolved 💬 3 comments Opened Apr 14, 2026 by ns-glisk Closed Apr 18, 2026

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 (or null/-1) means unlimited -- the user is responsible for pruning
  • maxSessions: N sets the cap (current default would be 32)
  • prunePolicy: "manual" disables automatic deletion entirely
  • prunePolicy: "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)
  • --resume is 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 --resume can'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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗