claude-code - 💡(How to fix) Fix `compactOnExit: true` — one setting, three problems solved

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…

Root Cause

Three issues, same root cause.

Fix Action

Fix / Workaround

I'd write the patch today if the repo were open — the exit path and compaction call site are both clear. Happy to help test or spec it out if that's useful.

Code Example

// settings.json (global or project level)
{
  "compactOnExit": true
}
RAW_BUFFERClick to expand / collapse

[!IMPORTANT] tl;drcompactOnExit: true in settings.json. The compaction pipeline already exists. The exit path just needs to call it.

The auto-compact feature is genuinely one of the best parts of Claude Code. This is about closing one gap in its reach.


The problems

Three issues, same root cause.

🐌 Slow resumes

Resuming a large uncompacted session means reading and parsing the full transcript before the first prompt loads. A 3.5 GB JSONL is not the same experience as a compact summary.

🧠 Wasted context budget

Resumed sessions that never hit the auto-compact threshold load full, uncompressed history into the context window. Users burn that budget before typing a word.

💾 Disk accumulation

Uncompacted sessions write the full raw transcript to disk and leave it there. One machine: 4,850 session files, 8.9 GB, with individual sessions at 3.5 GB and 2.3 GB. Compacted sessions store a summary. Uncompacted sessions store everything.


Proposed change

// settings.json (global or project level)
{
  "compactOnExit": true
}

Runs the existing /compact logic when the session closes. Nothing else changes.

Unchanged
Compaction pipeline✅ untouched
Hook system✅ untouched
API surface✅ untouched
Session teardown logic✅ one call added

What this is not

[!NOTE] Not a request for BeforeSessionEnd hooks or a memory lifecycle API (see #39392, #47023). Those tackle a bigger problem and I hope they move forward. This is a single boolean for users who want clean resumes without building a plugin.

Users are already doing this by hand before every exit. They just can't make it automatic.


Why current options fall short

ApproachWhy it doesn't work
autoCompactEnabledOnly fires at threshold — short sessions never compact
Stop hookFires after every response, not just the last
SessionEnd hookRuns after process exit — too late for in-process compaction
Manual /compactWorks, requires discipline

Two open issues (#39392, #47023) show users pushing on this from different angles for months. This is the smallest ask that closes the gap without waiting on a broader lifecycle API.


I'd write the patch today if the repo were open — the exit path and compaction call site are both clear. Happy to help test or spec it out if that's useful.

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 `compactOnExit: true` — one setting, three problems solved