Skip to content

Input length exceeds model's maximum context length - Claude Code

Quick fix

Add the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable to the provider config to cap the context window.

Error output
API Error: 500 Input length (121079) exceeds model's maximum context length (120000). This is a server-side issue, usually temporary — try again in a moment. If it persists, check your inference gateway (127.0.0.1:15721).

Handling long text or images, Claude Code sends an input longer than the maximum context window the model is configured for (120k, for instance), so the server returns a 500. Claude Code itself offers no official option for declaring the real context window of a BYOK backend, so cc-switch cannot truncate the input at that threshold automatically.

The effective fix is to use the cc-switch advanced configuration to inject the `CLAUDE_CODE_AUTO_COMPACT_WINDOW` environment variable into the Claude Code process. That variable triggers the automatic compaction built into Claude Code: as the context approaches the value you set, it compacts automatically and stays under the limit. Note that with the shared configuration in play, this environment variable can be extracted wrongly and applied to every provider — set it only in the specific provider configuration.

  1. Open the cc-switch provider config file and find the Claude Code provider entry.

  2. Add 'CLAUDE_CODE_AUTO_COMPACT_WINDOW' to the 'env' field of that provider config, with a value slightly below the maximum context length of the model (100000, for instance).

    {
    "providers": {
    "your-provider-name": {
    "type": "claude",
    "env": {
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "100000"
    }
    }
    }
    }
ToolClaude Code
VersionUnknown
PlatformsWindows
Why did the per-model compaction thresholds I set stop working once I ticked the shared configuration?
This is a known cc-switch behaviour problem (Issue #5401). The shared configuration extracts the environment variable properties automatically and overrides the specific provider configuration. For now, do not set CLAUDE_CODE_AUTO_COMPACT_WINDOW in the shared configuration — set it individually in each provider config that needs it.
Is this error a server-side problem?
Although the message says 'server-side issue', it usually means the input exceeded the maximum context window the model allows. Setting CLAUDE_CODE_AUTO_COMPACT_WINDOW to enable client-side automatic compaction resolves it — no server fix needed.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.