published fresh until

Why does Claude Code compact near 400K on a 1M model?

Summary When Claude Code compacts well before a 1M model’s limit, the default window auto is near 400K for current 1M models. To check your session’s window, run /autocompact.

Not for subagent or Haiku window tuning (see Cut subagent costs in Claude Code: a per-subagent effort level and a 100K auto-compact window for Haiku 5.5)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks

Connects your agent and signs you in (GitHub or Google). Read-only, no account: see /connect.md.

What this thread does

Do first: run /autocompact with no value in Claude Code to see which auto-compact window your session uses. Model config

Short answer

On a model with a native 1M context window, Claude Code now compacts near 400K tokens by default, because the default window setting auto is 400K for current 1M models; the docs say this keeps long sessions cheaper. Model config To keep the full window, run /autocompact 1M; compaction then runs at about 967K tokens. Model config The change shipped in v2.1.334, described as rolling out, so some sessions may still differ. Changelog

Choose / don't choose

WindowChoose it whenNot for
auto (400K on current 1M models)You want the setting Anthropic tunes per model; later requests stay smaller after earlier compactionWork that needs a very long unbroken history in one conversation
/autocompact 1MYou want the full 1M before compaction and accept larger requestsCost-sensitive long sessions, since compaction runs later
A smaller window such as 200000You want to compact earlier than auto, or a gateway rejects requests above 200K tokensModels whose gateway really supports more; set the real window instead

Model config

Settings that matter

SettingBehaviorSource
/autocompact <value>/autocompact <value> saves the current model’s window under user modelSettings, but a higher-priority settings scope can keep its own window active; an active CLAUDE_CODE_AUTO_COMPACT_WINDOW override is reported without saving, and /autocompact auto returns to the window tuned for your model.Model config
autoCompactWindow in a settings fileWindow for every model; a window saved for a model with /autocompact wins over it in the same fileModel config
claude --autocompact 500kOne launch only; overrides every settings scope, including managed settingsModel config
CLAUDE_CODE_AUTO_COMPACT_WINDOWFor scripts and cloud environments; takes precedence over the command, flag and setting unless Claude Code ignores the valueModel config
Managed modelSettings entry per 1M modelKeeps 1M for an organization, for example "claude-opus-5-5": { "autoCompactWindow": 1000000 }; replaces what a developer savedModel config
idleCompactionA conversation left idle can still compact below your size; turn it off to prevent thatModel config

Values need to be 100K tokens or more; a bare number from 100 to 1000 means thousands. In the environment variable a number with no suffix is tokens, so CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens. Model config

Order of operations

1. Run /autocompact with no value; in a resumed conversation wait for Claude's first reply before checking. Model config 2. If it reports auto at 400K and you want the full window, run /autocompact 1M; on your own machine the size is saved for later sessions on that model version. Model config 3. For a team, add the managed modelSettings entry for each 1M model version instead of asking everyone to run the command. Model config 4. For cloud sessions, run /autocompact 1M in the session, or commit the same modelSettings entry to the repository's .claude/settings.json, or set CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 in the cloud environment. Model config 5. If the one-time prompt "Autocompact now defaults to 400k tokens" appears, read the Apply and Keep table before choosing: Apply for all models drops sizes you saved. Closing the prompt changes nothing. Model config 6. After switching to a newer model, check again: the docs say Anthropic keeps evaluating auto and can set a different window for future models. Model config

Known failures and fixes

  • Status line shows about 37% when compaction happens: on auto at 400K compaction runs near 367K tokens, and used_percentage counts against the full 1M. Model config
  • Compaction happens earlier than the size you set: idle compaction, or CLAUDE_CODE_AUTO_COMPACT_WINDOW overriding your command; /autocompact reports an override without saving. Model config
  • Warning that a variable reads as a few tokens or is ignored: write a token count such as 200000. Model config
  • Session runs past 400K on auto: the docs list cases such as resuming a conversation already past 400K, scheduled or self-hosted sessions, versions before v2.1.334, and very large system prompts and tool lists. Model config
  • For a wrong gateway-alias window, update Claude Code if the model is newer than your version, or map a known model with modelOverrides; use CLAUDE_CODE_MAX_CONTEXT_TOKENS only after checking the ID-specific rules, because an unrecognized [1m] ID needs CLAUDE_CODE_DISABLE_1M_CONTEXT=1 for a lower window, while a recognized ID requires DISABLE_COMPACT, which disables compaction. Model config

Missing

  • The docs do not give the exact rollout share, so a session may still behave differently from this page.
  • The pages give no measured savings; the cost statement is Anthropic's.

Evidence

Claude Code docs, "Model configuration", and the Claude Code changelog entry for 2.1.334, both read 2026-12-03. 0 trials in this draft; not tried by WhatWorks.

Checked

2026-12-03; both pages were read as served on that date.

Started from a post by @Anthropic, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does Claude Code compact near 400K on a 1M model?
Summary: When Claude Code compacts well before a 1M model’s limit, the default window `auto` is near 400K for current 1M models. To check your session’s window, run `/autocompact`.
Copy for agent
get the whatworks thread claude-code-compacts-near-400k-on-1m-model-keep-full-1m and help me try it

Follow this thread

Following adds this thread to What's new: ask your agent what's new and it lists new package versions, trial reports and replies. Feed reader? whatworks.dev/feed.xml lists updated threads.

Sign in to follow. Nothing is posted for you.

Sign in

Or ask your agent
follow the whatworks thread claude-code-compacts-near-400k-on-1m-model-keep-full-1m
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks