Claude Code autocompact at 400K: why 1M models compact earlier and how to change it
Since v2.1.334 Claude Code compacts near 400K tokens even on 1M models. What it does to cost, how to go back to 1M, and when to do it.
On Claude Code with a 1 million token model, autocompact (the automatic summarizing of the conversation) now triggers by default around 400K tokens, not 1M. According to Anthropic's documentation, this is a setting called auto, tuned per model "for the best cost and performance", and it applies to the Fable models, Sonnet 5 and later, Haiku 5.5 and Opus 4.7 and later. You change it with /autocompact 1M, a setting or an environment variable.
In sintesi
- Since v2.1.334 (December 1, 2026) the default auto-compact window on models with a native 1M window is
auto, which means 400K: compaction runs at about 367K tokens. With/autocompact 1Mit runs at about 967K. - The stated reason is cost: after a compaction the following requests are smaller, so long sessions use fewer tokens.
- Per the documentation, sessions on versions before v2.1.334, scheduled tasks (Desktop and cloud) and self-hosted environments stay at 1M.
- For an organization, set the value in
modelSettingsin managed settings. Behind a gateway with a 200K limit you needCLAUDE_CODE_AUTO_COMPACT_WINDOW=200000. - Rayo's rule: keep
autofor daily work and switch to 1M only for tasks that really need the whole context at once.
What changed and since when
The Claude Code changelog says for v2.1.334 (December 1, 2026): "Changed auto-compact's per-model auto setting to near 400K on most current 1M models, -p and SDK runs too (rolling out; on now with third-party providers or telemetry off)". So the change arrives in waves: it is already on with third-party providers or with telemetry off, and it is spreading to the rest.
The affected models are those with a native 1M window. According to the model configuration page, these are the Fable models, Sonnet 5 and later, Haiku 5.5 and Opus 4.7 and later, which use 1M by default with no [1m] suffix. Opus 4.6 and Sonnet 4.6 reach 1M only through the [1m] variant and compact at 200K without it.
You can tell whether your session is on the new value from a notice: "This session is on auto, which now autocompacts near 400k tokens instead of 1m to lower the cost of long sessions. To opt out, run /autocompact 1m." To check the current window, run /autocompact with no value.
Why compacting earlier costs less
Compacting earlier costs less because every Claude Code request sends the whole conversation back to the model. The prompt caching page explains it: the model remembers nothing between requests, so Claude Code resends the system prompt, project context, every message and every tool result. The longer the conversation, the more tokens are re-read on every turn, even at cache prices.
The calculation below is mine, not Anthropic's. It takes the cache read prices from the pricing page and assumes 100 consecutive requests with the context near the limit and the cache always warm. It is an upper bound, because in a real session the context starts small after each compaction and grows.
| Model | Cache read | 100 requests at about 367K | 100 requests at about 967K | Difference |
|---|---|---|---|---|
| Claude Opus 5.5 | $0.20 / MTok | $7.34 | $19.34 | $12.00 |
| Claude Sonnet 5.5 | $0.10 / MTok | $3.67 | $9.67 | $6.00 |
The math is 0.367 MTok × price × 100, and 0.967 MTok × price × 100. It leaves out cache writes, output tokens and the cost of the compaction request itself, which Anthropic describes as a separate request carrying the same history plus a summarization instruction.
Haiku 5.5 has a different twist. Per the pricing page, a request with a prompt over 100,000 tokens pays higher rates (input $0.50 instead of $0.10 per MTok), and the count includes cache reads and writes. With Haiku, staying at 1M therefore has a per-token cost unlike the other models.
The price you pay: lossy compaction
Compacting earlier means summarizing more often, and a summary loses detail. Thariq Shihipar's post on session management and 1M context (Anthropic, April 15, 2026) is clear: compaction is lossy, bad compacts happen when the model cannot predict where your work is heading, and "the model is at its least intelligent point when compacting". The same post describes context rot, the drop in performance as context grows, which exists at 1M too.
These are two opposite effects, and the documentation gives no measurement of how much each weighs on your tasks. Anthropic only writes that auto is "tuned per model" and may change for future models. That is why Rayo's view is practical: measure on your own workload and do not trust a number meant for everyone.
How to change the window
There are five ways, in order of reach. Accepted values are 100K tokens or more, as a plain integer, with a k or M suffix, or a number from 100 to 1000 meaning thousands. Claude Code always caps the value at the model's window.
# For the current model, saved for later sessions
/autocompact 1M
/autocompact 500k
/autocompact auto # back to the value Anthropic tuned
# For one launch
claude --autocompact 500k
# For scripts and cloud environments (beats command, flag and setting)
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000
{
"autoCompactWindow": 200000
}
Watch one detail from the documentation: CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens, while /autocompact 200 means 200,000. Claude Code warns and uses the 100K minimum.
To keep 1M across an organization, add a modelSettings entry for each model version in managed settings, for example "claude-opus-5-5": { "autoCompactWindow": 1000000 }. Per the documentation, the managed entry replaces the value a developer saved, and the developer can still override it with --autocompact or the environment variable.
Where the window stays at 1M and where it does not
The documentation lists the cases where a session can run past 400K. Here they are in a table.
| Case | Window used |
|---|---|
| More than about 180K tokens of system prompt, tools and instruction files on every request | Raised for that conversation |
Session resumed with claude --resume already past 400K | 1M until the next compaction |
| Desktop scheduled task, cloud scheduled task, self-hosted environment | 1M |
| Claude Code older than v2.1.334 | 1M |
If you see the notice Raised this conversation's auto-compact window, Anthropic recommends using fewer tools or shorter instruction files, because a smaller window can refill right after each compaction.
Two cases need action. The first is the gateway: if ANTHROPIC_BASE_URL points to a gateway that rejects requests above 200K, Claude Code cannot know, and the documentation tells you to set CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000. The second is anyone who wants to force 200K: with CLAUDE_CODE_DISABLE_1M_CONTEXT=1, native 1M models behave like 200K models.
A conversation left idle can compact below the threshold you chose. To prevent that, set idleCompaction to false (requires v2.1.290 or later).
What to do now
- Update Claude Code and run
/autocompactwith no value to read which window your session uses. - If you work in a large repository and the summary makes you lose the thread, try
/autocompact 1Mfor a week and compare cost and quality with/usage. - If you run a team, decide the value in
modelSettingsin managed settings, one model at a time, instead of leaving each developer to choose. - If you go through a gateway, check the gateway's real limit and set the window accordingly.
- Compact yourself at a natural break with
/compactand a description of the next step, instead of waiting for automatic compaction mid-task. More ways to cut consumption are in the article on saving tokens in Claude Code.
Sources
- Model configuration, Extended context and Context window and auto-compaction sections, Anthropic documentation, read on December 4, 2026
- Claude Code changelog, version 2.1.334 of December 1, 2026
- Explore the context window, Anthropic documentation
- How Claude Code uses prompt caching, Anthropic documentation
- Claude model pricing, Anthropic documentation
- Using Claude Code: session management and 1M context, Thariq Shihipar, Anthropic, April 15, 2026
FAQ
At how many tokens does Claude Code compact on a 1M model?
By default on auto it compacts near 400K, about 367K according to the documentation. With /autocompact 1M it compacts at about 967K. You can lower the value down to 100K.
How do I go back to the previous 1M behavior?
Run /autocompact 1M in the session: the value is saved for that model version. In an organization, use modelSettings in managed settings. For scripts, set CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000.
Why does my session still compact at 1M? It may be a Claude Code version older than v2.1.334, a scheduled task or a self-hosted environment, or a session resumed already above 400K. The gradual rollout also matters, since the changelog speaks of a rollout in progress.
Should I keep the window at 400K or move it to 1M?
It depends on the task. At 400K requests are smaller and cost less, but the summary comes sooner and can lose detail. For refactors that need many files read together, 1M can be worth the cost. For everyday work, auto is the starting point Anthropic recommends.
Does it apply to Bedrock, Google Cloud and Foundry?
The changelog says the change is already on with third-party providers. Behind a custom gateway, Claude Code may not recognize the model ID and assume a different window: the documentation explains how to correct it with CLAUDE_CODE_MAX_CONTEXT_TOKENS.