Skip to content

Configuration & troubleshooting

Claude Code Auto Compact Window: 400K Default, Settings, and 1M Fix

Claude Code v2.1.334 cut the default auto-compact window on most native 1M-context models from 1M to 400K tokens, moving automatic summarization down to roughly 367K tokens across terminal sessions, claude -p, and Agent SDK runs. Restoring the full 1M window takes one setting—unless a higher-precedence scope, idle compaction, or a new model release overrides it.

By AgentsPulse Editorial Team 16 min read Published December 5, 2026 Updated December 5, 2026
Review scope Anthropic Claude Code documentation (model-config, settings-reference, env-vars, context-window, statusline, sub-agents, changelog v2.1.334–v2.1.337) · Anthropic API pricing table · Lydia Hallie's Dec 2, 2026 rollout post · GitHub issues #113413, #113638, #113724, and #114063, verified Dec 5, 2026

Threshold numbers (~367K, ~967K, 180K fixed-overhead floor, 200K idle minimum), precedence rules, and release fixes come directly from Anthropic's current Claude Code documentation and changelog. Anthropic has not published an empirical task-success benchmark comparing 400K against 1M; community failure modes (Remote Control max_tokens, post-compaction cache misses, and status-line math) are cited from open GitHub issues as user reports.

Bar chart comparing Claude Code auto-compact trigger points inside a 1M context window: default auto at 400K compacts near 367K tokens with a 33K buffer, /autocompact 1M compacts near 967K tokens, and idle compaction still fires from 200K tokens after one hour idle

Claude Code v2.1.334 lowered the default Claude Code auto compact window from 1M to 400K tokens on most native 1M-context models, compressing long sessions near 367K tokens instead of 967K. Shipped on December 1, 2026, the change covers interactive terminal sessions, claude -p, and Agent SDK runs—rolling out gradually to standard accounts and taking effect immediately on third-party providers or when telemetry is disabled.

Anthropic engineer Lydia Hallie announced the rollout on December 2, 2026, explaining that compacting earlier reduces cumulative token usage in long sessions while letting users opt out through /autocompact 1m or /config. That single command only pins the current model version on the local machine; teams running multiple models, CI jobs, subagents, or long-idle sessions also run into five override precedence tiers, idle compaction at 200K, and a status-line denominator change shipped two days later.

Claude Code auto compact window default: 400K vs 1M

On auto, Claude Code v2.1.334 defaults current native 1M models—Fable models, Sonnet 5 and later, Haiku 5.5, and Opus 4.7 and later—to a 400K auto-compact window that triggers at roughly 367K tokens. Switching to 1M moves the trigger back to roughly 967K tokens, leaving about 33K tokens of buffer headroom in either mode.

Sessions on the 400K default print this startup 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.

Older 200K setups—Sonnet 4.6 and Opus 4.6 without extended context, plus any 1M model run with CLAUDE_CODE_DISABLE_1M_CONTEXT=1—still compact at the 200K boundary. Even on native 1M models left on auto, Anthropic documents four cases that bypass 400K by default:

Session condition Default window on auto Behavior
System prompt, tools, and instruction files exceed ~180K tokens per request Automatically raised for that conversation Prints Raised this conversation's auto-compact window so compaction does not immediately thrash
Resuming a conversation already past 400K tokens (claude --resume) 1M until next compaction Avoids forcing an immediate summary on resume
Desktop scheduled tasks, cloud scheduled tasks, or self-hosted environments 1M Automated scheduled and self-hosted runs retain the full 1M window
Claude Code older than v2.1.334 1M The Desktop app’s Code tab bundles its own Claude Code binary, which can lag the terminal version

When the one-time Autocompact now defaults to 400k tokens prompt appears, each choice writes a distinct config state. Apply (all models) moves all native 1M models back to auto and erases previously saved sizes. Apply for the current model switches only the active model to auto while saving 1M for other models that were on auto. Keep retains saved sizes and writes 1M for models currently in /model, whereas any model version Anthropic releases later has no saved override and starts on auto (400K). Closing the prompt leaves auto models at 400K.

Routing multiple 1M models. Because the 400K default applies immediately on third-party endpoints across Opus 5.5, Sonnet 5.5, Fable 5.2, and Haiku 5.5, teams switching between Claude models and other providers in CI or local agents can route requests through a shared gateway such as PackyAPI as an option.

Disclosure: this page contains an affiliate link. If you sign up through it, we may earn a commission at no extra cost to you.

Claude Code auto compact window setting: precedence and how to keep 1M

To pin 1M permanently across all models—or lock a custom threshold between 100K and 1M—pick the setting layer that matches your scope. Claude Code resolves five layers top-down and caps the winning value at the active model’s context window.

Five-layer precedence stack for Claude Code auto-compact window settings: P1 CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable, P2 claude --autocompact CLI flag, P3 higher-priority settings scope (managed, local, project), P4 user settings modelSettings over top-level autoCompactWindow, P5 built-in model auto default Configuration precedence for the Claude Code auto-compact window, from environment variable override down to the built-in v2.1.334 default. Based on Anthropic Claude Code documentation (Dec 2026).

Five configuration layers in precedence order

Priority Lever Scope Covers future models? Syntax rules
1 (Highest) CLAUDE_CODE_AUTO_COMPACT_WINDOW Shell, CI, -p, SDK, cloud env Yes Integer >= 100000; k/M suffixes need v2.1.304+
2 claude --autocompact <size> Single launch Yes (for that launch) Accepts 200000, 500k, 1M, or bare 100–1000 (thousands)
3 Managed / Local / Project settings.json Org or repository Top-level key yes; modelSettings per version Managed modelSettings replaces user-saved model sizes
4a /autocompact <size> or /config row Current model in user modelSettings No (model-version specific since v2.1.288) Run /autocompact with no value to inspect active window
4b Top-level autoCompactWindow in ~/.claude/settings.json Every model without a modelSettings entry Yes Plain integer in JSON, e.g. 1000000

Inside Priority 4, /autocompact 1M and the Auto-compact window row added to /config in v2.1.334 save under modelSettings.<model>.autoCompactWindow (behavior introduced in v2.1.288). Because a per-model entry beats the top-level key in the same file, running /autocompact 1M only protects the model version you are currently using.

To keep 1M across every current and future 1M model on one machine, place a top-level autoCompactWindow key in ~/.claude/settings.json (clearing any conflicting per-model entries) or export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000:

{
  "autoCompactWindow": 1000000
}

For enterprise fleets using managed settings, Anthropic’s model-configuration docs specify adding per-model entries under modelSettings (such as "claude-opus-5-5": { "autoCompactWindow": 1000000 }). On Desktop hosts without existing managed settings, include "parentSettingsBehavior": "merge" so Desktop keeps applying its own host policy. In cloud sessions, commit modelSettings to .claude/settings.json or set CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 in cloud environment variables; threads inside Claude Code Projects retain their own window settings.

Subagents support a lower-only override: setting autoCompactWindow: 200000 in a subagent’s YAML frontmatter (v2.1.296+) forces that subagent to compact earlier than the parent session. Since v2.1.312, Claude Code picks the lowest of the frontmatter value, the model’s context window, and CLAUDE_CODE_AUTO_COMPACT_WINDOW. The field does nothing when the agent runs as the main session via --agent.

Claude Code auto compact window not working: traps and fixes

When a session ignores your setting or still compacts well below 1M, check /autocompact with no arguments first (after one reply in a resumed session) to see the active token limit and its source, then rule out five documented traps:

  1. Bare-number parsing differences (200 vs 200000): /autocompact 200 and claude --autocompact 200 interpret bare integers from 100 to 1000 as thousands (200,000). CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 parses 200 literally as 200 tokens, logs reads as 200 tokens, so Claude Code treats it as the 100k minimum, and clamps the window to 100K. Subagent YAML frontmatter is stricter still—200k parses as 200 and gets ignored silently (check claude --debug for invalid autoCompactWindow). Use plain integers such as 200000 or 1000000 in JSON, YAML, and older environment configs.
  2. Idle compaction firing from 200K despite a 1M window: Since v2.1.290, idleCompaction defaults to true. On interactive terminal, VS Code, and local/SSH Desktop sessions using the 1-hour prompt cache TTL, leaving a session idle for about an hour once context reaches CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS (default 200000, minimum 100000) triggers compaction before the cache expires—even when autoCompactWindow is 1000000. Turn it off via "idleCompaction": false in settings.json (or /config on v2.1.302+), or raise CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS.
  3. CLAUDE_AUTOCOMPACT_PCT_OVERRIDE changing the base window: This percentage variable (1–100) can only trigger compaction earlier than the default ceiling. Anthropic’s environment-variable docs also specify that on native 1M models outside cloud sessions, setting CLAUDE_AUTOCOMPACT_PCT_OVERRIDE makes the default base window 1M instead of 400K. A leftover CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 in ~/.zshrc therefore compacts near ~500K on 1M rather than 50% of 400K.
  4. Locked environment variables and unrecognized gateway IDs: When CLAUDE_CODE_AUTO_COMPACT_WINDOW is exported in a shell or settings.json env block, /autocompact only prints that the variable takes precedence and refuses to save. On custom ANTHROPIC_BASE_URL gateways with unrecognized model IDs, Claude Code compacts against an assumed window until you run claude update, map the alias with modelOverrides or modelPicker (behavesAs), append [1m], or set CLAUDE_CODE_MAX_CONTEXT_TOKENS (which needs CLAUDE_CODE_DISABLE_1M_CONTEXT=1 for unrecognized [1m] IDs and DISABLE_COMPACT=1 for recognized Claude IDs).
  5. Disabling auto-compact without hitting prompt is too long: "autoCompactEnabled": false or DISABLE_AUTO_COMPACT=1 disables automatic and idle compaction while keeping manual /compact (DISABLE_COMPACT=1 disables manual /compact and rewind summarization too). Without automatic compaction, hitting the API ceiling stops the turn with a prompt is too long error until you run /compact, /rewind, or /clear.

Claude Code autocompact threshold: status line math, costs, and what survives

Lowering the threshold from ~967K to ~367K changes three operational details immediately: status-line percentages, per-turn cache-read bills, and which workspace files survive each summary.

Status line used_percentage denominator shift (v2.1.336)

Starting in v2.1.336 (December 3, 2026), Claude Code computes context_window.used_percentage and remaining_percentage in statusLine JSON against the active auto-compact window instead of context_window_size, matching /context. Before v2.1.336, used_percentage divided by context_window_size (1,000,000).

Scripts that print used_percentage next to context_window_size now show visually mismatched numbers—such as 92% (435k/1.0M) documented in GitHub issue #114063 (where 82,878 tokens against a 470K window gave used_percentage: 18 beside context_window_size: 1000000). To plot usage against the full 1M model window, calculate total_input_tokens * 100 / context_window_size inside your status-line script.

Token cost mechanics at 400K vs 1M

Cached input tokens cost a fraction of fresh input, yet every turn before compaction still pays cache-read rates and draws down five-hour and weekly plan limits. On Anthropic’s listed API pricing (verified December 5, 2026), prompt-cache reads cost $0.20 / MTok on Opus 5.5 and Fable 5.2 (0.05× and 0.025× base input) and $0.10 / MTok on Sonnet 5.5, while Haiku 5.5 jumps 5× above 100K tokens ($0.05 vs $0.01 / MTok cache read; $0.50 vs $0.10 / MTok base input). Claude 4.7 and newer models also use a tokenizer that Anthropic notes emits roughly 30% more tokens for the same text than 4.6 models.

A single turn at 900K tokens reads roughly 2.5× as many cached tokens as a turn at 360K tokens. For per-task budget comparisons across Claude tiers and tool setups, see our analyses of Claude Opus 5.5 pricing per task, Claude Fable 5.2 pricing and benchmarks, and Claude Code Code Mode token savings. Net session savings still depend on whether earlier summaries trigger extra file re-reads; Anthropic has not published an evaluation comparing task completion rates or total token spend at 400K versus 1M.

What survives compaction at ~367K

More frequent summaries make Claude Code’s documented retention rules matter much earlier in a session:

Re-injected automatically after compaction Summarized or truncated
System prompt, output style, project-root CLAUDE.md, unscoped rules, and auto memory Path-scoped rules (paths: frontmatter) and nested subdirectory CLAUDE.md files (reloaded only on demand)
Fresh git status snapshot and plan-mode plan file Instructions stated only in chat or injected earlier by non-compact hooks
Up to 5 most recently modified files Claude read or edited Files over 5,000 tokens return as path references (Referenced file) without contents
Skill descriptions (v2.1.304+) and invoked skill bodies Skill bodies cap at 5,000 tokens per skill and 25,000 tokens total (oldest dropped first, keeping the top of SKILL.md)
SessionStart hooks matching the compact source; background commands & subagents keep running Subagent names from before the last compaction do not survive restarts (address by agent ID instead)

Compacting more often also increases exposure to summary-driven drift: teams running request-derived permission gates should review how context compaction summaries affect agent authorization, and pair long sessions with external Claude Code verification checks or disk-backed skill workflows like Superpowers so durable constraints stay in root CLAUDE.md.

Claude Code 2.1.334 autocompact bugs and v2.1.337 fixes

Between December 3 and December 4, 2026, Anthropic shipped three rapid patch versions—v2.1.335, v2.1.336, and v2.1.337—fixing rollout bugs tied to the 400K window:

  • v2.1.335 (Dec 3): Fixed the VS Code context usage meter staying full after switching a session from 400K back to 1M, stopped the one-time 400K dialog from opening over history searches or menus, and updated the “Autocompact is thrashing” error to name oversized instruction files like CLAUDE.md.
  • v2.1.336 (Dec 3): Aligned statusLine percentages with the auto-compact window, stopped the one-time prompt from repeating on every launch when ~/.claude.json is read-only or reset, capped ignored VS Code notices at three sessions, and added an error line when automatic compaction gives up.
  • v2.1.337 (Dec 4): Fixed slow git repositories dropping branch and status metadata after compaction, improved post-compaction MCP tool tracking on third-party providers or with telemetry off, and fixed pre-compaction messages disappearing in fullscreen mode after resuming.

Three notable community issues on anthropics/claude-code remained open as of December 5, 2026:

  • Per-model opt-out friction and stale VS Code ring (#113413): Developers requested published 400K-vs-1M benchmarks and an “all models, including future ones” opt-out. One commenter reported a session compacting at 360,818 tokens before the override took effect and a VS Code context ring keeping a stale ~367K warning even with CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 active until the next compaction or model switch.
  • Remote Control reporting max_tokens: 400000 (#113638): In claude remote-control sessions running Opus 5.5, get_session returned "max_tokens": 400000, causing desktop and iOS Claude clients to label 400K as the model’s maximum context while the terminal showed 1M.
  • Cold post-compaction prompt-cache misses (#113724): A user inspecting macOS Desktop Code tab JSONL transcripts with plugins installed found zero cache misses across 103 compactions on v2.1.217–v2.1.330 (cache_read_input_tokens 29,636–56,126), versus cache_read_input_tokens: 0 on 2 of 4 compactions on v2.1.334 (the two hits occurred 22–26 minutes after an earlier compaction in the same session). This remains an unconfirmed single-user report; if widespread, cold 40K-token cache rewrites would partially erode 400K savings on sessions that compact multiple times.

If your sessions routinely hold 500K–800K tokens of active multi-file context—cross-service refactors, full-repo audits, or long -p pipelines—upgrade to v2.1.337, add "autoCompactWindow": 1000000 at the top level of ~/.claude/settings.json (plus "idleCompaction": false if you pause mid-task for over an hour), and verify with /autocompact. For shorter iterative coding loops where stale tool output bloats cache reads, leaving auto at 400K and placing durable instructions in project-root CLAUDE.md requires no maintenance.

References

  1. Anthropic — Model configuration (Context window and auto-compaction), Claude Code Docs (verified Dec 5, 2026).
  2. Anthropic — Claude Code changelog (v2.1.334–v2.1.337), Dec 1–4, 2026.
  3. Anthropic — Settings reference (autoCompactWindow, modelSettings, idleCompaction) and Environment variables, Claude Code Docs (verified Dec 5, 2026).
  4. Anthropic — Explore the context window (What survives compaction) and Status line configuration, Claude Code Docs (verified Dec 5, 2026).
  5. anthropics/claude-code GitHub issues — #113413 (Dec 2, 2026), #113638 (Dec 2, 2026), #113724 (Dec 3, 2026), and #114063 (Dec 4, 2026).