Auto-compact fails to trigger on Sonnet 4.6, session grows past 200K limit and becomes unrecoverable
Description
Auto-compact failed to trigger during a Sonnet 4.6 session. The context grew past the 200K limit (reached ~246K) without auto-compact firing. Once over the limit, manual /compact also failed with:
Error: Error during compaction: API Error: Usage credits required for 1M context · run /usage-credits to turn them on, or /model to switch to standard context
This left the session completely unrecoverable without switching to Opus 1M context (which requires usage credits or a manual model switch).
Expected behavior
Auto-compact should fire before the session reaches the model's context limit (200K for Sonnet 4.6), preventing the session from becoming unrecoverable.
Actual behavior
Auto-compact did not trigger. Session grew to ~246K (past the 200K limit). Manual /compact then failed because compaction itself requires 1M context to process the oversized session.
Environment
- Claude Code version: 2.1.162
- Model: Sonnet 4.6 (200K context)
- Session size when issue occurred: ~246K tokens
- OS: macOS
Notes
This behavior was not observed in older versions of Claude Code (pre-v2.1.113). The issue may be related to the switch from Node.js to a compiled Bun binary at v2.1.113, which changed how context tracking and auto-compact thresholds are calculated.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗