[BUG] Autocompact triggers at 17% on 1M context model (effectiveWindow likely capped at 200k)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Auto-compaction triggers at ~17% context usage on the Opus 4.6 (1M context) model, rendering ~830k tokens effectively unusable.
Evidence from statusline debug logs
I instrumented the statusline to capture context_window data from the Claude Code API. Here are real sessions on claude-opus-4-6[1m]:
| Session | used_percentage | current_usage total | context_window_size |
|---------|----------------|--------------------|--------------------|
| ce85b6 | 15% | ~148k | 1,000,000 |
| 186445 | 17% | ~171k | 1,000,000 |
| 1376de | 21% | ~207k | 1,000,000 |
| 54f9ba | 34% | ~340k | 1,000,000 |
Session 186445 was observed compacting at 17% (screenshot available). The API correctly reports context_window_size: 1000000 and used_percentage: 17, yet compaction triggered.
Raw debug log (session that compacted at 17%)
{
"model": { "id": "claude-opus-4-6[1m]", "display_name": "Opus 4.6 (1M context)" },
"context_window": {
"total_input_tokens": 8556,
"total_output_tokens": 62054,
"context_window_size": 1000000,
"current_usage": {
"input_tokens": 3,
"cache_creation_input_tokens": 2458,
"cache_read_input_tokens": 169011
},
"used_percentage": 17,
"remaining_percentage": 83
}
}
Root cause hypothesis
From deobfuscated source (referenced in #31806):
function getAutoCompactThreshold(model) {
let effectiveWindow = getEffectiveWindow(model);
let defaultThreshold = effectiveWindow - 13000;
// ...
}
If getEffectiveWindow() returns 200k (not 1M) for the 1M model, then:
defaultThreshold = 200,000 - 13,000 = 187,000- 187k / 1,000,000 = 18.7% — matches observed behavior exactly
Expected Behavior
Compaction should trigger relative to the actual context_window_size (1M), not a hardcoded or capped effective window of 200k. At minimum, getEffectiveWindow() should return the real context window size reported by the API.
Actual Behavior
Compaction triggers at ~170-190k tokens regardless of the 1M context window, wasting ~80% of available context.
Is this a regression?
Unknown — behavior has been consistent since I started using the 1M model.
Environment
- Claude Code version: latest (March 2026)
- Model: claude-opus-4-6[1m] (Opus 4.6 with 1M context)
- OS: Windows 11 Pro
- Plan: Max (1M context enabled)
Related issues
- #31806 —
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEcannot raise threshold above default (~83%) due toMath.minclamp - #35296 — 1M context window advertised capability concerns
- #28728 — Auto-compact threshold should be configurable
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗