Repository navigation
Description
Client or integration
Claude Code
Area
Proxy and routing
Summary
A Claude Code session on a Messages → Responses translated route keeps running past the model's context window instead of compacting.
When the upstream rejects an oversized input, the error says Your input exceeds the context window of this model but has no context_length_exceeded code. opencodex only treats a refusal as an overflow when that code is present, so this one falls through to the generic upstream-failure mapping and reaches Claude Code as a 502. Claude Code sees a 502 as a temporary server error, so it retries instead of compacting. If the response were a 400 with prompt is too long, Claude Code would compact.
Reproduction
- Route Claude Code through opencodex to an
openai-responsesmodel with a window under 1M. In my setup that'sgpt-6-astra(872K) behind an Anthropic-adapter provider withmodelAdapters: openai-responses. - Select the model with the
[1m]suffix, so Claude Code's auto-compact threshold sits above the real window. - Keep working until the request is larger than 872K tokens.
- Claude Code shows
API Error: 502 Your input exceeds the context window of this model…and retries, several times over a few minutes. It never compacts on the overflow; compaction happened only once the client's own threshold was reached (preTokensabout 925K in my transcripts).
Where it falls through (2.96.0 has the same code):
src/claude/outbound.ts:anthropicFailedStatusreturns 400 only forcode === "context_length_exceeded". An uncoded orserver_errorrefusal goes tohttpStatusFromTerminalErrorand gets 502.src/server/claude-messages.ts: the non-stream!response.okbranch setscontextErrorfrom the code only. Thestatus === "failed"JSON branch checks the code only too.
isContextOverflowText already recognises this message and is used on the native Messages lane (claudeOverflowSsePayload). The translated Responses lane doesn't use it.
Suggested fix (I'm running this as a local patch)
Add a helper that treats a refusal as context_length_exceeded when the message matches isContextOverflowText. Excluded: messages that match isThroughputLimitText, and errors whose type is rate_limit_error, authentication_error or permission_error. Use it in the stream response.failed handler, the non-stream error branch, and the failed-JSON branch.
Results with the patch:
- Uncoded overflow: 400
invalid_request_error, messageprompt is too long: … server_erroroverflow: 400- Coded overflow: 400 (unchanged)
too many tokens per minute: 429 (unchanged)- Connection reset: 502 (unchanged)
Version
2.94.0 (2.96.0 code checked, same behaviour)
Operating system
macOS 26.6.2
Provider and model
Anthropic-compatible provider in front of CLIProxyAPI; gpt-6-astra / gpt-6.1-sol (872K) via openai-responses
Logs or error output
API Error: 502 Your input exceeds the context window of this model. Please adjust your input and try again.
Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
Activity
github-actions commentedon Nov 3, 2026
Automated translation bookkeeping — detected language: English.
fix(claude): answer uncoded context-window refusals as prompt too long (
lidge-jun commentedon Nov 3, 2026
Fixed on
devby #8128 (60ac8ef): on the translated Claude Messages lane, a refusal that clearly says the request exceeds the context window now answers 400 "prompt is too long" (context_length_exceeded) instead of a retryable 502, so Claude Code compacts. It ships in the next release; please reopen if it still reproduces after updating.