Skip to content
← Back to release · 2.1.325
Improvements / v2.1.325

Apply CLAUDE_CODE_MAX_CONTEXT_TOKENS more broadly

CHANGELOG · original

Changed CLAUDE_CODE_MAX_CONTEXT_TOKENS to also set the context window of unrecognized model IDs that start with claude-, such as a gateway's claude-sonnet-latest
Open official changelog ↗

Documentation

Documentation excerpt

Which IDs CLAUDE_CODE_MAX_CONTEXT_TOKENS applies to

On an LLM gateway or other custom deployment, Claude Code can assume a context window for the model ID that differs from the model's real window, whether or not it resolves the ID to a Claude model. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the window Claude Code should assume instead.

The variable works differently for an unrecognized ID, an unrecognized ID with [1m], and an ID that Claude Code recognizes:

  • If Claude Code doesn't recognize the ID and the ID doesn't contain [1m], the variable applies on its own and proactive compaction continues at the declared window. For an ID such as claude-sonnet-latest, this requires Claude Code v2.1.324 or later.

  • If Claude Code doesn't recognize the ID and the ID contains [1m], in any casing, Claude Code assumes a 1M window for it. A value under 1M in the variable doesn't apply on its own. To correct the window while keeping proactive compaction, also set CLAUDE_CODE_DISABLE_1M_CONTEXT=1. With that variable set, Claude Code sizes the ID like the same ID without [1m], so CLAUDE_CODE_MAX_CONTEXT_TOKENS applies.

    With a declared window above 200K, the warning that the 200K limit isn't enforced is expected in this configuration.

  • If the ID resolves to a model Claude Code recognizes, the variable takes effect only when you also set DISABLE_COMPACT, which disables all compaction.

    For example, an ID that contains a Claude model name that Claude Code knows, such as anthropic/claude-opus-4-8, us.anthropic.claude-…-v1:0, or the dated claude-sonnet-4-5@20250929, resolves to that model. This includes IDs that also contain [1m]: Claude Code resolves claude-opus-4-8[1m] to Opus 4.8 even with CLAUDE_CODE_DISABLE_1M_CONTEXT set.

For a model ID Claude Code doesn't recognize, set CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1 to have Claude Code compact only after the API rejects the conversation with a too-long error Claude Code recognizes. Claude Code doesn't run that recovery when a gateway rewrites the error to wording Claude Code doesn't recognize.

Documentation snapshot · 2026-11-20

Change details