Claude Code 2.1.323 1M Context: Fix Unknown Gateway Model Errors

Claude Code 2.1.323 changed the assumed context window for unrecognized model IDs from 200K to 1M, which can cause repeated failures behind smaller-window gateways. Check the newer 2.1.325 fix, set the real window with CLAUDE_CODE_MAX_CONTEXT_TOKENS, or choose a safe auto-compact threshold. Includes BetterToken setup, model-specific limits, and recovery steps.

Contents
Claude Code 2.1.323 1M Context: Fix Unknown Gateway Model Errors

Claude Code 2.1.323 changed the default context window for unrecognized model IDs from 200K to 1M tokens. If your third-party model or gateway accepts fewer tokens, Claude Code may delay compaction until requests start failing repeatedly. Update to 2.1.325 or later, then configure the model’s actual context window or an earlier auto-compact threshold.

The right fix depends on the effective limit of your model and gateway. Do not set every DeepSeek, GLM, or Kimi session to 200K automatically. Some current models support 1M tokens, and reducing their window unnecessarily discards useful working context.

This guide covers the November 12–13 release changes, the newer gateway fix, and the settings that control long sessions.

What changed in Claude Code 2.1.323, 2.1.324, and 2.1.325?

Version 2.1.323 introduced the new assumption. Versions 2.1.324 and 2.1.325 then addressed related model-ID and gateway-context behavior.

The official Claude Code changelog records these changes:

VersionContext-related changeWhat you should do
2.1.323Unrecognized model IDs now assume a 1M-token window instead of 200K.Check your model’s real limit before starting a long session.
2.1.323Smaller-window models from other vendors can fail every turn once the session fills, until /clear.Configure the window before it fills.
2.1.324CLAUDE_CODE_MAX_CONTEXT_TOKENS also applies to unknown IDs beginning with claude-.Update if your gateway uses an unknown claude- alias.
2.1.325Fixed repeated context-length errors instead of compaction on many third-party gateways and Foundry deployments.Update before applying more disruptive workarounds.

As of 2026-11-15, npm lists 2.1.325 under latest and 2.1.311 under stable for @anthropic-ai/claude-code. The stable version does not contain the 2.1.323 default change, but it also lacks the later fixes.

Check the version installed on your machine:

claude --version

For a native Claude Code installation, use the documented updater:

claude update
claude --version

If you intentionally follow the stable channel, do not assume the latest release’s behavior applies to your existing binary. Confirm your version before changing settings.

The 2.1.325 changelog says it fixes the repeated-error behavior on many gateways. It does not promise that every gateway will recover or that its reported context limit matches the upstream model.

Why can an unknown model ID break a long session?

Claude Code uses its recognized model catalog and local configuration to decide when to compact a conversation.

Compaction summarizes earlier messages so the next request fits the model’s context window. A gateway or custom model ID can prevent Claude Code from recognizing the actual model.

For example, a gateway might expose my-coding-model with a real 200,000-token limit.

Before 2.1.323, Claude Code assumed 200K for that unknown ID. Starting with 2.1.323, the same ID assumes 1M unless configuration changes the result.

The model and gateway have not gained capacity. Claude Code has only changed its estimate.

If the conversation grows beyond the gateway’s accepted window, the API may reject the request. Because the failed conversation remains in the session, the next turn can fail for the same reason.

Anthropic explicitly documented this failure mode in 2.1.323. The newer 2.1.325 fix improves recovery for many gateways, but you should still configure a smaller effective window where necessary.

Which model IDs are affected?

The risk applies when the window Claude Code assumes is larger than the window the request can actually use.

Common cases include:

  • A non-Claude model ID such as deepseek-v4.1-flash-1017 or kimi-k3.1-pro, if Claude Code does not recognize it.
  • A gateway alias such as my-coding-model, even when the upstream serves a Claude model.
  • An unrecognized ID beginning with claude-, such as claude-sonnet-latest. Version 2.1.324 changed how the window override applies to this case.
  • An ID with a [1m] suffix. This has separate override rules.

An unknown ID alone is not evidence of a context mismatch.

A model that genuinely supports 1M tokens may work with the new default. Problems arise when the gateway, deployment, or model enforces a lower limit.

A known Claude ID is also different from an unknown gateway spelling. Claude Code may recognize an Anthropic model name embedded in another provider’s ID. The override rules depend on that resolution.

See Anthropic’s custom-model window documentation before relying on a particular ID pattern.

Which context-window fix should you choose?

Use CLAUDE_CODE_MAX_CONTEXT_TOKENS when you know the effective window and your model ID supports the override. Use CLAUDE_CODE_DISABLE_1M_CONTEXT=1 for a quick 200K cap, or adjust auto-compaction when you want an earlier safety margin.

FixBest useLimit or tradeoff
CLAUDE_CODE_DISABLE_1M_CONTEXT=1Quick protection when the effective model window is at least 200K and you want the older assumption.Limits some genuine 1M-context models to 200K. Not enough by itself for smaller windows.
CLAUDE_CODE_MAX_CONTEXT_TOKENSSet the actual context window for an unknown model or gateway alias.Application depends on ID recognition, version, and [1m].
/autocompact, --autocompact, or CLAUDE_CODE_AUTO_COMPACT_WINDOWTrigger compaction earlier than the assumed window.The documented configurable range starts at 100K. Choose a threshold that fits the actual upstream limit.

These controls are not interchangeable. One sets a broad 200K restriction, another changes the assumed model capacity, and the third changes the compaction trigger.

Fix 1: Restore the 200K assumption

For a model or gateway with an effective window of at least 200K, launch Claude Code with:

export CLAUDE_CODE_DISABLE_1M_CONTEXT=1
claude

This follows the workaround named in the 2.1.323 changelog.

For persistent configuration, add the variable under env in ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1"
  }
}

Claude Code also removes [1m] variants from its model picker when this setting is active.

On models that normally use a native 1M window, auto-compaction holds the session to 200K. If auto-compaction is disabled, the session instead stops at the applicable context boundary.

There is one important exception: an unknown ID can have another setting that defeats the 200K restriction.

If you see:

CLAUDE_CODE_DISABLE_1M_CONTEXT is set, but the 200K limit isn't enforced for <model>, so this session can grow past it.

Check whether you have raised CLAUDE_CODE_MAX_CONTEXT_TOKENS or disabled unknown-model window enforcement.

Anthropic’s error reference recommends setting CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 when you need to enforce that boundary.

Do not use this fix alone when your gateway accepts fewer than 200K tokens.

Fix 2: Set the real window with CLAUDE_CODE_MAX_CONTEXT_TOKENS

This is the more precise option for a known gateway limit.

Suppose your gateway administrator confirms that a custom model route accepts 200,000 tokens. Set the value in the shell that starts Claude Code:

export CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000
claude

The number is a hypothetical gateway limit used to illustrate the configuration, not a recommended value for every model.

For an unrecognized non-claude- ID without [1m], the variable applies directly. Claude Code continues proactive auto-compaction using the declared window.

The current model configuration reference also documents two exceptions:

  • An unrecognized ID containing [1m] needs CLAUDE_CODE_DISABLE_1M_CONTEXT=1 as well when correcting its smaller window.
  • An ID that resolves to a known Claude model only applies this override when DISABLE_COMPACT is also set. That disables compaction, so it is not the preferred fix for ordinary long sessions.

Unknown claude- IDs gained direct support for this override in 2.1.324. Older builds may handle those IDs differently.

If you are using a gateway alias for a real Claude model, the documented modelOverrides or modelPicker.behavesAs settings can map that alias to a recognized Claude model. Do not map a genuinely non-Claude model to a Claude identity merely to remove a warning.

The important value is the effective limit of the selected API route, including any smaller gateway cap. Do not substitute a marketing context size for a lower enforced deployment limit.

Fix 3: Compact earlier with /autocompact

An earlier threshold gives Claude Code room to compact before the gateway refuses the request.

For a session whose real limit is confirmed as 200K, this is a conservative example:

/autocompact 150k

Run it inside Claude Code. The command saves the threshold for the current model under modelSettings and normally applies it immediately.

Read the /autocompact response to verify which threshold the session actually uses. A higher-priority settings scope, such as managed settings, can keep a different window active even after your value is saved. The command reports that override.

If managed settings prevent your chosen threshold from applying, ask your administrator to review the policy. The one-launch --autocompact flag is not preempted by managed settings, according to Anthropic’s auto-compaction configuration reference.

For a one-time launch:

claude --autocompact 150k

For scripts, containers, or other environments where a launch-wide override is easier:

export CLAUDE_CODE_AUTO_COMPACT_WINDOW=150000
claude

Both the /autocompact command and --autocompact flag accept 100K–1M tokens. The environment variable accepts token counts from 100000 to 1000000.

The environment variable takes precedence over the command, flag, and saved settings unless Claude Code rejects its value. If it is set, /autocompact reports the override instead of saving a new value.

For persistent settings across models, autoCompactWindow can be set in ~/.claude/settings.json. A per-model /autocompact value takes precedence over that key within the same settings scope.

A value such as 150k is only a safety-margin example for an upstream that accepts 200K. It does not mean 150K is suitable for a smaller model.

The configurable minimum is 100K. For models with smaller windows, check the model-override rules and the client’s effective behavior instead of assuming /autocompact 50k is supported.

BetterToken example: Configure Claude Code with DeepSeek or Kimi

BetterToken provides an Anthropic-compatible endpoint at https://bettertoken.ai for supported models. The Claude Code Base URL does not include /v1.

Anthropic’s support boundary is different from BetterToken’s integration documentation. Anthropic states in its LLM gateway documentation that it does not support routing Claude Code to non-Claude models through any gateway. BetterToken documents its own third-party integration, but that does not make non-Claude routing an Anthropic-supported configuration. Verify model compatibility, tool behavior, and gateway limits for your chosen route.

As of 2026-11-15, the current BetterToken model records and documentation support these distinctions:

BetterToken Model IDPublished model contextAnthropic Messages route
deepseek-v4.1-flash-10171M tokensListed
kimi-k3.1-pro1M tokensListed
glm-5.31M tokensNot listed for this model; its current structured entry lists OpenAI-compatible access
qwen3.8-max1,000,000 tokensNot listed for this model; its current structured entry lists OpenAI-compatible access

These published model windows are not automatically smaller than Claude Code’s new 1M assumption. Their effective limits can still differ by provider route.

A model being available through BetterToken also does not establish that every protocol supports it. Check the current model catalog before selecting a Claude Code route.

The following Bash setup uses the listed Anthropic-compatible DeepSeek model ID. It follows BetterToken’s Claude Code integration guide.

Install Claude Code first and create your own BetterToken API Key. Then run the commands in a dedicated Bash shell:

read -rs BETTERTOKEN_API_KEY && export BETTERTOKEN_API_KEY

export ANTHROPIC_BASE_URL="https://bettertoken.ai"
export ANTHROPIC_AUTH_TOKEN="$BETTERTOKEN_API_KEY"
export ANTHROPIC_MODEL="deepseek-v4.1-flash-1017"

export ANTHROPIC_DEFAULT_HAIKU_MODEL="$ANTHROPIC_MODEL"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$ANTHROPIC_MODEL"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$ANTHROPIC_MODEL"

unset CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT

claude -p "Reply with only: OK"
claude

Enter your API Key when the first command waits for input. The key is not printed or embedded in the command.

The three ANTHROPIC_DEFAULT_*_MODEL variables keep the built-in model roles on the selected BetterToken model. You can configure different supported models for those roles later.

To select Kimi instead, set ANTHROPIC_MODEL to kimi-k3.1-pro before running the three role-variable exports. If you already ran the DeepSeek setup, rerun all four exports in the same Bash shell before launching a new Claude Code process:

export ANTHROPIC_MODEL="kimi-k3.1-pro"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$ANTHROPIC_MODEL"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$ANTHROPIC_MODEL"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$ANTHROPIC_MODEL"

Changing only ANTHROPIC_MODEL after the original exports leaves the three role variables pointing to DeepSeek. BetterToken’s Kimi K3.1 Pro documentation confirms the model ID and its Claude Code integration path.

For an unrecognized ID without [1m], you can set the verified window explicitly. For a route that truly accepts 1,000,000 tokens:

export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000

Set this before launching Claude Code. For a gateway capped at a smaller window, replace 1000000 with that gateway’s confirmed token limit. Choose an earlier auto-compact threshold if needed.

Do not blindly apply the following example to DeepSeek or Kimi:

# Example only: the gateway's verified limit is 200000 tokens.
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=150000

The first value declares the effective window. The second leaves a margin before compaction. For another limit, confirm both values independently.

Verify the model and gateway route

After starting Claude Code, run:

/status

Check that the Anthropic base URL shows https://bettertoken.ai and that authentication uses ANTHROPIC_AUTH_TOKEN.

Then check the active model. If necessary, use /model to select the intended ID. If you changed model-role variables, restart Claude Code so the new process receives their values.

The earlier claude -p "Reply with only: OK" request checks basic connectivity and model access. A normal response confirms that a short request succeeded. It does not prove long-context behavior.

For a more useful coding check, ask Claude Code to read a small repository file and explain a specific function without editing it. Confirm the file named in the reply.

If the connection or authentication fails, resolve that problem separately. The Claude Code gateway 403 troubleshooting guide covers a different class of failures.

For a longer DeepSeek setup and model-selection checks, see the Claude Code and DeepSeek integration guide. For Kimi-specific model behavior, use the Kimi K3.1 Pro coding guide.

What if every turn already fails?

First, identify whether the failure is a context-length rejection. The 2.1.323 changelog describes repeated failures but does not publish one universal error string.

Gateway errors can appear in different forms. Anthropic’s gateway troubleshooting reference includes examples such as:

ContextWindowExceededError

and:

prompt token count of N exceeds the limit of M

These are examples of gateway-side wording, not guaranteed messages from the 2.1.323 change.

Try the least destructive recovery path first:

  1. Preserve the current task state outside the conversation if you can still access it. Record changed files, test results, and the next action.
  2. Update Claude Code to 2.1.325 or later and verify the installed version.
  3. Confirm the real window and set CLAUDE_CODE_MAX_CONTEXT_TOKENS or a suitable auto-compact threshold before relaunching.
  4. If the session remains accessible, try /compact manually.
  5. If the conversation cannot be compacted or continued, use /clear, then restart from the saved task state.

A gateway that rewrites a too-long error into unfamiliar wording may prevent Claude Code from recognizing it for automatic recovery. The 2.1.325 fix addresses many such repeated failures, but the changelog does not list every supported gateway.

For a detailed recovery path, including cases where manual compaction fails, use the Claude Code and DeepSeek input-length recovery guide.

Do not set CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1 as a general fix. Anthropic documents that this skips proactive compaction for unknown IDs and waits for a recognizable API error. That can make recovery less reliable when a gateway rewrites the error.

Why do some instructions still say unknown models use 200K?

The documentation changed around this release.

The model-configuration text captured on November 13 still described a 200K assumption. However, the live model-configuration page, checked on November 15, now shows an unknown-model warning with context assumed to be 1m tokens.

Do not use the older 200K warning text as evidence of current behavior. Check your installed version, the warning Claude Code actually prints, and your effective settings.

For a recognized model or a correctly declared window, the warning may disappear. That confirms Claude Code accepted its model configuration, not that the gateway can process a request of that full size.

For an unknown model whose gateway cap is below 1M, use Claude Code 2.1.325 or later and declare the verified effective window. Add an earlier compact threshold when the gateway needs extra room for output.

For a gateway with a confirmed 200K limit, CLAUDE_CODE_DISABLE_1M_CONTEXT=1 is a quick workaround. A precise window override plus an earlier threshold gives you more control.

For a model with a real 1M window, keep that capacity unless you prefer shorter sessions or a gateway imposes a lower limit.

For unknown IDs with a [1m] suffix or recognized Claude IDs, follow the separate override rules in Anthropic’s documentation. Do not assume the environment variable alone overrides every ID.

The safest configuration is the one that matches the window your actual API route accepts, rather than Claude Code’s default estimate.

Ready to optimize your LLM workflow?

Join thousands of developers building faster, smarter, and more cost-effective AI applications with BetterToken.

Get Started for Free