[Bug] Auto-compact "context running low" warning fires at ~177k tokens in 1M-context ([1m]) sessions
Summary
In sessions using the 1M-token context window ([1m] model variant), the model-facing "context is running low — ask the user if they'd like to compact" system-reminder fires at roughly 177k tokens (~18–21% of the window). It appears calibrated to the 200k default window rather than the session's actual context size.
Crucially, **this affects only the warning, not actual auto-compaction** — real compaction is correctly window-aware (see analysis below). So the safety mechanism works fine; the advisory reminder just misfires early and prompts wrap-up/compaction when ~800k of headroom remains.
Environment
- Model:
claude-opus-4-8[1m](1M context window) - Claude Code: observed across
2.1.202→2.1.216(binary analysis below done on2.1.214) - Platform: macOS (darwin, arm64)
Observed behavior
A session reported "context is running low, consider compacting" at ~177k messages tokens / ~207k total. The statusline (which normalizes to the true window) showed ~21% used — i.e. the warning fired while the session was 4/5 empty.
Evidence
I ran a per-turn token-usage logger (a Stop hook reading usage.input_tokens + cache_creation_input_tokens + cache_read_input_tokens from the transcript) across normal work for several days. Of 19 logged 1M sessions, 7 climbed past 177k without any auto-compaction, with peaks of:
237k, 262k, 264k, 274k, 289k, 291k, 353k tokens
Reaching 240k–353k proves these are genuinely 1M-window sessions (a 200k window can't hold that) and that real auto-compaction is using the large window correctly (they never compacted at ~200k). Yet each necessarily passed through the ~177k point where the early warning fires.
Root-cause analysis (from the shipped 2.1.214 binary)
The auto-compact machinery is window-aware. Strings in bin/claude.exe:
"The actual threshold is the minimum of this setting and your model's maximum context window." "The auto setting picks a window tuned for your model…"
…so autoCompactWindow (default auto) resolves per-model and is capped to the model max — consistent with sessions correctly running to 350k on a 1M model.
However, the model-facing "context is running low / ask to compact" reminder text does not appear anywhere in the client bundle. Every other auto-compact string is present (autoCompactEnabled, autoCompactWindow, CLAUDE_CODE_AUTO_COMPACT_WINDOW, /autocompact, the "Context low (X% remaining)" UI banner, PreCompact/PostCompact hooks, etc.), but not that reminder. This strongly suggests the warning is injected server-side on a separate code path from client compaction — and that path appears to assume the 200k default rather than reading the session's context_window_size.
Expected behavior
The early-warning reminder should scale with the session's actual context window (or reuse the same min(autoCompactWindow, model max) threshold the client already computes), so it fires at a meaningful fraction of the real window — not at ~18% of a 1M session.
Notes
- Client-side knobs (
CLAUDE_CODE_AUTO_COMPACT_WINDOW,DISABLE_AUTO_COMPACT) likely won't suppress this, since they govern compaction, not the (apparently server-injected) warning. - Low severity — the reminder is easy to ignore and real compaction is unaffected — but it produces spurious "we should wrap up / compact" behavior in long 1M sessions.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗