Auto-compact Earlier
By default, Claude Code compacts when the conversation reaches the model’s context limit. On a 1M-token model that means a very long time between compactions, and quality degrades well before the window is actually full.
You can set a fixed window instead.
Recommended setting
Section titled “Recommended setting”{ "autoCompactWindow": 200000}Or from inside a session, which saves the same value to your user settings:
/autocompact 200kAccepted values run from 100K to 1M tokens, as a plain count (200000), with a suffix (200k, 1M), or a bare number meaning thousands (200). Claude Code caps the value at the model’s context window. /autocompact auto returns to the default tuned for your model.
Why a fixed window
Section titled “Why a fixed window”- Long-context retrieval gets worse as the window fills. A smaller working set keeps rules and earlier decisions reachable.
- It makes compaction predictable across models instead of depending on each model’s limit.
- Compaction is cheap compared to a session that has quietly stopped following instructions.
Other ways to set it
Section titled “Other ways to set it”claude --autocompact 200kfor one launch, without changing the saved setting.CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000in scripts and cloud environments. While set, it overrides the command, the flag, and the setting.
About CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
Section titled “About CLAUDE_AUTOCOMPACT_PCT_OVERRIDE”This older variable still exists, but it only lowers the trigger as a percentage of the auto-compact window, and it only applies in sessions that already compact before the model’s limit (cloud sessions, models with a 200K boundary, and similar). For most local sessions on a 1M model it does nothing, which is why autoCompactWindow is the better tool.
Defaults without a window set
Section titled “Defaults without a window set”- Most models: compact at the model’s context limit.
- Cloud sessions: compact as the conversation approaches the limit.
- Models running with a 200K window (for example on Bedrock, Google Cloud, or Microsoft Foundry, or with
CLAUDE_CODE_DISABLE_1M_CONTEXT=1): compact at the 200K boundary.
Pair this with a status line that shows context usage, and with /context when you want to see what is filling the window.