[Bug] Auto-Compact triggers prematurely on idle resumption

Status Open
Reported on v2.1.187
Maintainer reply ✓ Yes — bcherny
Activity 4 comments · opened Jun 25, 2026
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Bug Description
why dont you comapct conversations when idle. annoying it triggers just as we start again

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 2.1.187
  • Feedback ID: 4ed25ec4-098f-4244-96f6-2533a474cdc1

Errors

[]

View original on GitHub ↗

3 Comments

junaidtitan · 3 months ago

The timing is off because CC's compaction trigger fires on the first message of the new session — that's when it measures context and detects "over threshold." There's no background idle process that would compact while you're away; the measurement only happens when you send something.

The workaround is to prune the session at exit so the JSONL is already lean when you come back. cozempic guard does this: runs after Claude terminates, strips accumulated tool-result payloads and dead-weight context from the previous session, writes the smaller file before your next resume. When you return, the context loads smaller and is less likely to cross the compaction threshold on turn 1.

In most cases "idle → compaction on first message" is driven by tool output accumulation from the previous session, not actual content growth — so exit-phase pruning typically eliminates it. Won't help if the session was genuinely above-limit when it ended, but that's the less common case.

bcherny collaborator · 1 month ago

Thanks for the feedback. Auto-compaction now prepares its summary in the background before the context window fills, so when the threshold is crossed the compaction itself is much quicker than it used to be. You can also run /compact yourself at a natural pause, or raise the point at which it triggers with /autocompact (docs: https://code.claude.com/docs/en/model-config#set-the-auto-compact-window).

Compacting fully while the session is idle rather than at the start of the next message is still an open request, so leaving this open.

🤖 Generated with Claude Code

dthinkr · 1 month ago

I tested the idle-side version of this because the timing also has a large usage cost. On a 1-hour prompt-cache tier, a large session can be summarized cheaply while its prefix is still a cache read; if Claude waits until the user returns after expiry, the summary call first pays to rebuild the full prefix.

A local daemon watching the session transcript and sending /compact during a 50-to-58-minute idle window worked end to end. One real session went from 842,223 to 13,555 tokens while idle. The compaction took 3m16s, which is exactly the delay the user otherwise sees after sending the first productive message back.

The trigger needs a context floor and an upper time bound, but the experiment supports the UX requested here. Implementation and measurements: https://github.com/dthinkr/claude-code-auto-compactor

Showing cached comments. Read the full discussion on GitHub ↗