[BUG] CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 does not trigger autocompact — context reaches 100% requiring manual /compact
Status Open
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 11 comments · opened Apr 23, 2026
Bug
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE set to 50 in settings.json does not trigger automatic compaction. The context window reaches 100% and Claude Code shows the hard limit prompt (Context limit reached · /compact or /clear to continue), requiring manual /compact every time.
Version
Claude Code v2.1.118, Sonnet 4.6 (200k context), macOS Darwin 25.4.0
Reproduction
Settings (~/.claude/settings.json)
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
}
}
Steps
- Start a Claude Code session with the above setting
- Run a moderately long session with multi-agent tasks and file reads (e.g., 5–10 subagent spawns)
- Observe that autocompact never fires at 50% — context grows to 100%
- Claude Code shows:
Context limit reached · /compact or /clear to continue - Must manually type
/compactto continue
Expected behavior
Autocompact should trigger when context usage reaches 50%, preventing the hard limit.
Actual behavior
Autocompact never fires. Context reaches 100% regardless of the configured threshold.
Notes
- Related to #42394 (same env var unreliable, but that report is about firing too early; this is the opposite: never fires)
- The
PreCompacthook (~/.claude/hooks/pre-compact.sh) runs correctly when manual/compactis executed, confirming the hook setup itself is not the issue - The problem appears to be that
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEis not being read or applied at all in v2.1.118 for Sonnet 4.6 sessions
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Running into the same territory from the opposite end — we want frequent compactions (our sessions average 59+ per run) and had to build our own compaction lifecycle management because relying solely on
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEwas unreliable.Two things we found:
PreCompacthook. Before compaction (whether manual or auto), we save a full session checkpoint (active task state, calibration, mental state). After compaction, we restore from that checkpoint. This makes compaction safe regardless of when it fires, which is arguably more important than controlling when it fires.The deeper issue is that compaction timing and compaction safety are conflated — if compaction were always safe (preserving identity, task state, and relational context), the threshold would matter less. We documented our approach to making compactions non-destructive in NEXO Brain (open-source MCP server) — see the
PreCompact/PostCompacthook system and the checkpoint/diary machinery.Ran into the same frustration with unreliable autocompact thresholds. Cozempic's guard daemon bypasses this entirely — it monitors the session JSONL directly and applies 18 pruning strategies at 4 progressive thresholds before context ever hits 100%. No reliance on CLAUDE_AUTOCOMPACT_PCT_OVERRIDE.
pip install cozempic && cozempic init— hooks wire via SessionStart. https://github.com/Ruya-AI/cozempicConfirming this regression persists in v2.1.138 on Linux (Ubuntu, kernel 6.17, bash) — 20 patch releases past the v2.1.118 originally reported, same behavior with
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40. Tested in v2.1.133, .136, .137, .138 — env var is correctly visible to hooks (process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE === "40") but auto-compaction does not fire until ~78–85% regardless.Binary MD5s of v2.1.136/.137/.138 differ (genuine new builds), but no v2.1.123→v2.1.138 release note mentions auto-compact behavior.
Sibling issues still OPEN that share this root cause: #18264 (autoCompact:false ignored, fires ~78%), #18152 (off-flag won't allow continue), #19018 (hard "Context limit reached"). Closed-without-fix priors: #36381, #31806, #56666.
Local mitigation: Stop hook reads CC's native
context_window.used_percentagefrom the hook stdin payload and emits a manual-compact prompt attarget − 2pp. The native field is the only reliable signal source we've found.Might be useful.
I had my CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=55 set for a few weeks and working. Changed it to 80 recently and never worked thereafter. Even setting back to 55, restarting sessions, new sessions. Everything fires at 100% now, full 1M tokens to trigger autocompact. All I did was change the value.
use "CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000" this sets and unsets auto compaction... hope that helps
usage
export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=80 <-- set to whatever you want...
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 <-- must exist
Thanks brother. The CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 sets the ceiling which I just set to 550000 and works. Will have to test to the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE={value}. May not work anymore. This setting appears to be demoted to TestPCT. Manually setting the window does work though as a workaround.
We hit the same 'override is ignored, context just climbs to 100%' issue and worked around it in cozempic (github.com/Ruya-AI/cozempic): rather than relying on the native auto-compact threshold, its guard daemon prunes + reloads at configurable token thresholds, so you get a reliable early trigger regardless of whether the override is honored. Open-source, auto-runs (
pipx install cozempic). Would love feedback if you give it a shot — does it give you the early-compaction behavior the override was supposed to?Cozempic, keep the code lean, love it.
Just as Sn3th said, both values have to be set. I had a few issues using only. CLAUDE_CODE_AUTO_COMPACT_WINDOW=550000 (55%).
Instead I've been testing
CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000
along with
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=55
and it seems to be working reliably to achieve autocompacts. Still some loose issues there, when it actually honors this, before the session starts, after a compact, etc, but better.
Thanks @WillyDrucker — 'keep the code lean' is the whole ethos (zero deps, stdlib only), so that means a lot. And yeah, the env-var dance is exactly what the guard sidesteps: it prunes + reloads at its own thresholds, so you get the early trigger regardless of whether
AUTOCOMPACT_PCT_OVERRIDE/AUTO_COMPACT_WINDOWare honored that session. If you end up running both, genuinely curious which feels more reliable for you.Same here on v2.1.187 (headless
claude -p/ SDK path): withCLAUDE_AUTOCOMPACT_PCT_OVERRIDEset alone, autocompact never fires and context runs to the limit.The override reaches the subprocess -- it echoes inside tool calls -- but the autocompact logic never acts on it. Set, visible, no effect.
What does work: setting
CLAUDE_CODE_AUTO_COMPACT_WINDOWalongside it. The pct override does nothing on its own. Once the window var is set, the pct is applied as a multiplier -- effective trigger ~= WINDOW x (pct/100). WithWINDOW=500000and pct60I get a deterministic compact at ~300k tokens.One caveat worth documenting: if the effective trigger falls below the session's baseline injected context, autocompact compacts, the context immediately refills past the limit, and the built-in thrash guard aborts the whole turn:
So the window var is a real lever, and it can be set too low.
Summary: the pct override being silently ignored on its own is the bug. The window var is the current workaround.