Context window detection fails for third-party Anthropic-compatible providers
When using a third-party provider that implements the Anthropic API (e.g., MiniMax via https://api.minimax.io/anthropic), Claude Code's context window detection falls back to the hardcoded default of 200,000 tokens, even when the underlying model may support a larger context window.
Root Cause
In src/utils/context.ts, getContextWindowForModel() calls getModelCapability() to retrieve max_input_tokens from a cached capability list. However, getModelCapability() is gated by isFirstPartyAnthropicBaseUrl() in src/utils/model/modelCapabilities.ts:46-51:
function isModelCapabilitiesEligible(): boolean {
if (process.env.USER_TYPE !== 'ant') return false
if (getAPIProvider() !== 'firstParty') return false
if (!isFirstPartyAnthropicBaseUrl()) return false // ← MiniMax fails here
return true
}
Since MiniMax's base URL is https://api.minimax.io/anthropic (not api.anthropic.com), isFirstPartyAnthropicBaseUrl() returns false, and getModelCapability() returns undefined. This causes getContextWindowForModel() to fall through to MODEL_CONTEXT_WINDOW_DEFAULT = 200_000.
Impact
- AutoCompact triggers too aggressively: With a 200K assumed window, AutoCompact threshold is
200,000 - 13,000 = 187,000(93.5%). If MiniMax actually supports 1M, this is ~19% into the real window. - Users hit context limits unexpectedly: The tool estimates the context is at 93.5% when it may actually be at only 18.7% for a 1M-capable model served through MiniMax.
- Manual
/compactbecomes necessary: Users report needing to run/compactmanually when the auto-compact warning should have fired much earlier (or not at all).
Reproduction Steps
- Set
ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic - Set
ANTHROPIC_AUTH_TOKEN=<MiniMax token> - Set
ANTHROPIC_MODEL=MiniMax-M2.7(or any model served through MiniMax) - Observe that
getContextWindowForModel("MiniMax-M2.7")returns200000regardless of the model's actual capabilities - Note that AutoCompact warning fires at ~187K tokens (based on 200K window) rather than at a proportional threshold for the actual window
Expected Behavior
Claude Code should either:
- Detect actual context window for third-party providers (if the provider exposes model capabilities via their own endpoints)
- Allow manual override via environment variable (
CLAUDE_CODE_MAX_CONTEXT_TOKENS) or model configuration - At minimum, not assume the smallest possible window for unknown third-party providers — use a conservative estimate or probe the actual limit
Proposed Fix
Option A: Extend capability detection to third-party providers (medium effort)
Add a getThirdPartyModelCapability() path that tries to fetch from the provider's model list endpoint, or maintain a local override map for known MiniMax/Gateway models.
Option B: Environment variable override for specific models (simple, immediate)
Add support for per-model context window overrides in CLAUDE_CODE_MAX_CONTEXT_TOKENS:
CLAUDE_CODE_MAX_CONTEXT_TOKENS="MiniMax-M2.7:1000000,claude-opus-4-6:1000000"
Option C: Probe actual context limit on first use (most robust)
On the first API call with a new model, detect 413 Payload Too Large and learn the actual limit, persisting it locally. Already done for team memory (src/services/teamMemorySync/index.ts:529), could be generalized.
Workaround
Set CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000 in environment to override the auto-detected window for all models.
Additional Context
- AutoCompact already has a circuit breaker (3 consecutive failures) to prevent hammering the API when context is irrecoverably over the limit (
src/services/compact/autoCompact.ts:70) - The 200K default is documented at
src/utils/context.ts:9as a comment but may not reflect actual provider capabilities - This issue affects any Anthropic-compatible third-party API (Azure, AWS Bedrock, Vertex, MiniMax, OpenRouter, etc.) where the provider URL doesn't match
api.anthropic.com
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Additional Context for Triage
Affected providers: MiniMax (via
https://api.minimax.io/anthropic), likely also affected for Azure, AWS Bedrock, Vertex, OpenRouter, and other Anthropic-compatible third-party APIs.User config that triggers this:
Symptoms reported by users:
/compactwhen the automatic system should have handled itTechnical notes:
src/utils/model/modelCapabilities.ts:46-51(isModelCapabilitiesEligible()) intentionally restricts capability detection to first-party only — this is a design choice, not a bug — but it means third-party providers get the conservative 200K floor regardless of actual model supporteffectiveContextWindow - 13,000 tokens(src/services/compact/autoCompact.ts:75-76)Suggested labels:
area:providers,area:core,enhancement,provider:minimaxPriority consideration: This affects any multi-provider setup where models are routed through non-Anthropic endpoints. As more third-party providers support Claude models (Azure, AWS, Google Cloud), this becomes a broader issue.
Not a duplicate of the linked issues.
The linked issues cover:
ANTHROPIC_BASE_URL— unrelated symptomhas1mContext()doesn't match canonical model IDs from API responseOur issue adds a distinct problem that the existing issues don't cover:
Third-party providers (MiniMax, Azure, Bedrock, Vertex, OpenRouter) are gated out at a higher level —
isModelCapabilitiesEligible()inmodelCapabilities.ts:46-51returnsfalsefor any non-api.anthropic.comURL, so even ifhas1mContext()were fixed, third-party providers would still get the 200K default becausegetModelCapability()is never called for them.The fixes needed are different:
has1mContext()) helps first-party API responsesPlease reopen or acknowledge as a separate tracking issue.
Same problem here with DeepSeek V4 (
deepseek-v4-proanddeepseek-v4-flash), which advertise a 1M context window in the official docs: https://api-docs.deepseek.com/news/news260424.Repro:
Claude Code reports 200K in both the status bar and
/context, and AutoCompact fires at the ~187K mark even though there's another ~800K of headroom on the provider side. Same root cause flagged in the OP for MiniMax:isFirstPartyAnthropicBaseUrl()returns false forapi.deepseek.comsogetModelCapability()falls through to the 200K default.Adding DeepSeek as a second data point in case it helps.
Adding a third data point — and an inverse manifestation of the same root cause.
Setup
RedHatAI/Qwen3.6-35B-A3B-NVFP4\with a 256K context window (\max_model_len: 262144\from \/v1/models\)\
\\\ANTHROPIC_BASE_URL=http://<lan-host>:8000
ANTHROPIC_API_KEY=<dummy>
ANTHROPIC_DEFAULT_SONNET_MODEL=RedHatAI/Qwen3.6-35B-A3B-NVFP4
ANTHROPIC_DEFAULT_OPUS_MODEL=RedHatAI/Qwen3.6-35B-A3B-NVFP4
ANTHROPIC_DEFAULT_HAIKU_MODEL=RedHatAI/Qwen3.6-35B-A3B-NVFP4
\
\Symptom
Claude Code's status line reports a 1M context window — the underlying model only supports 256K. This is the inverse direction from the MiniMax / DeepSeek reports above (where Claude Code under-reports), but the root cause is the same: \
isModelCapabilitiesEligible()\returning false for non-\api.anthropic.com\base URLs causes capability detection to fall through to a default that doesn't match reality.Why the over-detection direction also hurts
context_length_exceeded\and breaks the flow with a hard error, no soft warning/compact\is the only safety net, but users have to guess the real budgetReinforcing the prior request: a generic override would fix both directions
Three concrete proposals (any one of these unblocks local-LLM workflows):
ANTHROPIC_CONTEXT_WINDOW=262144\models.<id>.contextWindow\field in \~/.claude/settings.json\max_model_len\from the proxy's \/v1/models\response when availableAs local-LLM-via-router (vLLM, Ollama, llama.cpp) becomes a more common Claude Code setup, the lack of any override mechanism is a real friction point — the workaround today is "ignore the bar and \
/compact\by feel," which negates a lot of Claude Code's session-management value.Closing for now — inactive for too long. Please open a new issue if this is still relevant.
Hi guys,
I met the same problem: my Minimax M3 model only has a 200k context window. After adding a '[1m]' suffix to the model configuration, the problem may be fixed:
<img width="478" height="82" alt="Image" src="https://github.com/user-attachments/assets/2795bbfd-df2d-4c49-a7dc-2b0176e0ef76" />
@allenjack Could you share which version of cc you are using? I'm not able to get it work even with a [1m] suffix
Hi @cmpute , I am using the CC Switch, and my CC version is 2.1.160 (Claude Code).
GOATED CHOICE
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.