claude-code - 💡(How to fix) Fix Allow users to control session retention (disable automatic pruning) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48025Fetched 2026-04-15 06:35:29
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Root Cause

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.

Fix Action

Fix / Workaround

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

Code Example

{
  "sessionRetention": {
    "maxSessions": 0,
    "prunePolicy": "manual"
  }
}
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

Implement a configuration option to control session retention, allowing users to opt out of automatic pruning or set a custom session limit.

Guidance

  • Consider adding a sessionRetention object to the ~/.claude.json or settings.json file, with properties maxSessions and prunePolicy to control session pruning behavior.
  • Evaluate the proposed configuration options, such as setting maxSessions to 0 for unlimited sessions or prunePolicy to "manual" for disabling automatic deletion.
  • Assess the feasibility of implementing a simple boolean flag like "autoDeleteSessions": false as an alternative solution.
  • Investigate the potential drawbacks of the proposed workarounds, such as using chflags uchg or hardlink archiving via cron, and consider their impact on Claude Code functionality.

Example

{
  "sessionRetention": {
    "maxSessions": 0,
    "prunePolicy": "manual"
  }
}

This example configuration would allow users to opt out of automatic pruning and retain all session files.

Notes

The proposed solution relies on modifying the Claude Code configuration file, which may require updates to the application's codebase. Additionally, the effectiveness of the workarounds depends on the specific use case and may not be suitable for all users.

Recommendation

Apply a workaround by implementing a configuration option to control session retention, such as the proposed sessionRetention object, to allow users to opt out of automatic pruning or set a custom session limit. This approach addresses the user's need for control over session retention while minimizing potential disruptions to the application's functionality.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Allow users to control session retention (disable automatic pruning) [1 comments, 2 participants]