What happened?
When switching Claude Code models live (tray slot submenu or settings), the next request sometimes fails with:
API Error: 400 This endpoint's maximum context length is 131072 tokens. However, you requested about 135293 tokens (36915 of text input, 34378 of tool input, 64000 in the output). Please reduce the length of either one, or use the context-compression plugin to compress your prompt automatically.
The failure is intermittent — it depends on how large the in-flight Claude Code session already is and which model the slot was switched to.
Expected
Live model swap should either keep working or surface a clear, actionable warning before/at swap time (e.g. “new model has a smaller context window than this session”).
Steps to reproduce
- Configure a Messages endpoint (Claude Code) with slot models that have different context windows (e.g. switch from a ~200k model to one capped at 131072).
- Launch Claude Code via the tray and work until the session accumulates substantial history (tool calls, file reads, long thread).
- Without restarting Claude Code, switch one or more slots to the smaller-context model from the tray.
- Continue the session — observe intermittent
400 with the context-length message above.
(Exact repro varies with provider catalog and session size; the error appears when input + tool_input + max_output exceeds the new model’s limit.)
App version
Observed on current main / v0.4.x Claude Code support (live slot swap via proxy-cc/* labels).
CLI agent
Claude Code (claude), launched through the proxy’s Run Claude Code flow.
Analysis (current behavior)
Today the proxy handles Claude Code like this:
- Launch: sets stable
proxy-cc/<slot> labels in env; maps to catalog ids at request time (resolve_messages_model in proxy-core/src/proxy.rs).
- Live swap: only rewrites the outgoing
model field — request body (including max_tokens) is otherwise pass-through.
- Token limits from
/models: parsed into ModelInfo.max_prompt_tokens / max_output_tokens and used for Copilot (COPILOT_PROVIDER_MAX_*), but not applied to Claude Code requests or UI (token override panel is hidden for Messages API by design).
So after a swap, Claude Code keeps its existing conversation + tool context and may still request a large output budget (e.g. 64000). If the newly selected upstream model has a smaller combined limit (here 131072 total), the provider rejects the request even though the proxy successfully remapped the model id.
Ideas to explore
- Proxy-side clamping (Messages API): when rewriting
model, also adjust max_tokens (and possibly related fields) using the target model’s advertised limits from the catalog, ensuring prompt + max_output ≤ context_window where provider metadata allows inference.
- Pre-swap guardrail: before accepting a tray/settings slot change, compare the new model’s limits against a heuristic or last-known session size; warn or block when likely to overflow.
- Surface limits in CC UI: show per-slot model context/output caps in settings/tray so users can pick compatible models without guessing.
- User guidance: document that switching to a smaller-context model mid-session may require
/clear or restart; mention provider “context-compression” plugins where applicable.
- Investigate upstream variance: some gateways report
context_length vs max_output_tokens differently — confirm extract_token_limits mapping is correct for the providers users hit with CC.
Acceptance criteria (draft)
What happened?
When switching Claude Code models live (tray slot submenu or settings), the next request sometimes fails with:
The failure is intermittent — it depends on how large the in-flight Claude Code session already is and which model the slot was switched to.
Expected
Live model swap should either keep working or surface a clear, actionable warning before/at swap time (e.g. “new model has a smaller context window than this session”).
Steps to reproduce
400with the context-length message above.(Exact repro varies with provider catalog and session size; the error appears when
input + tool_input + max_outputexceeds the new model’s limit.)App version
Observed on current
main/ v0.4.x Claude Code support (live slot swap viaproxy-cc/*labels).CLI agent
Claude Code (
claude), launched through the proxy’s Run Claude Code flow.Analysis (current behavior)
Today the proxy handles Claude Code like this:
proxy-cc/<slot>labels in env; maps to catalog ids at request time (resolve_messages_modelinproxy-core/src/proxy.rs).modelfield — request body (includingmax_tokens) is otherwise pass-through./models: parsed intoModelInfo.max_prompt_tokens/max_output_tokensand used for Copilot (COPILOT_PROVIDER_MAX_*), but not applied to Claude Code requests or UI (token override panel is hidden for Messages API by design).So after a swap, Claude Code keeps its existing conversation + tool context and may still request a large output budget (e.g. 64000). If the newly selected upstream model has a smaller combined limit (here 131072 total), the provider rejects the request even though the proxy successfully remapped the model id.
Ideas to explore
model, also adjustmax_tokens(and possibly related fields) using the target model’s advertised limits from the catalog, ensuringprompt + max_output ≤ context_windowwhere provider metadata allows inference./clearor restart; mention provider “context-compression” plugins where applicable.context_lengthvsmax_output_tokensdifferently — confirmextract_token_limitsmapping is correct for the providers users hit with CC.Acceptance criteria (draft)