`compactOnExit: true` — one setting, three problems solved
[!IMPORTANT] tl;dr —compactOnExit: trueinsettings.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
| Approach | Why it doesn't work |
|---|---|
| autoCompactEnabled | Only fires at threshold — short sessions never compact |
| Stop hook | Fires after every response, not just the last |
| SessionEnd hook | Runs after process exit — too late for in-process compaction |
| Manual /compact | Works, 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗