Auto-compact Earlier
By default, models with a native 1M window (Sonnet 5, the Fable models, and Opus 4.7 and later on the Anthropic API) compact at about 967K tokens. That is a very long time between compactions, and quality degrades well before the window is that 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. The command and the --autocompact flag require v2.1.221 or later.
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. The variable accepts a plain token count only:200kis read as 200 and clamped to the 100K minimum.
About CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
Section titled “About CLAUDE_AUTOCOMPACT_PCT_OVERRIDE”This older variable still exists. It can only lower the trigger, as a percentage of the auto-compact window, and only in sessions that compact before the model’s context limit. Values above the default percentage are ignored. autoCompactWindow is the simpler tool because it takes an absolute token count.
Defaults without a window set
Section titled “Defaults without a window set”- Native 1M models on the Anthropic API: compact at about 967K tokens.
- Other models: compact at the model’s context limit.
- Cloud sessions: compact as the conversation approaches the limit.
- Models running with a 200K window: compact at the 200K boundary. That covers Opus 5 and Opus 4.8 on Amazon Bedrock, Google Cloud’s Agent Platform, or Microsoft Foundry, the 4.6 models without extended context, and any native 1M model with
CLAUDE_CODE_DISABLE_1M_CONTEXT=1.
Pair this with a status line that shows context usage, and with /context when you want to see what is filling the window. One catch: the status line’s used_percentage always measures against the model’s full context window, so with a 200K window set on a 1M model, compaction runs at about 20%, not near 100%.