Why your local model gets the wrong context window in Qwen Code
Qwen Code does not ask your local server how much context it has. It reads the model id you configured and takes the context window — the maximum number of tokens one request can hold — from a models.dev catalogue when the id is known and the catalogue entry is at least 32K; otherwise it uses a built-in table. A local Qwen3.x id such as qwen3.6-35b-a3b is treated as the commercial 1,000,000-token model; an id it does not recognise falls back to 200,000. Your server is probably configured for neither.
Ollama, LM Studio, vLLM and llama.cpp are OpenAI-compatible endpoints: servers that accept OpenAI's chat-completions request shape. Qwen Code configures one as an openai provider entry in modelProviders, and that entry is where the window belongs. Qwen Code calls its copy contextWindowSize; it is the denominator in the footer percentage, the trigger for auto-compaction, and the budget the output request is sized against.
Run qwen --version first. This page was checked against Qwen Code v0.26.2, the stable release on 27 October 2026, and its source at tag v0.26.2.
Checked against Qwen Code's documentation and source on 27 October 2026.
The short version: put contextWindowSize in the matching modelProviders entry, not in the top-level model.generationConfig; set context.autoCompactThreshold if 85% of the declared window is too late for your server; then add context-window-size to the status line and compare it with the limit the server was started with.
What Qwen Code assumes, and why it matters#
| Model id you gave Qwen Code | Window it assumes without contextWindowSize |
|---|---|
qwen3.6-35b-a3b | 1,000,000 |
my-local-model | 200,000 |
Those are the two common failures. The 1M row is labelled for commercial API models in the source; 200K is the generic fallback. A models.dev entry can supply a different number for a known id, but it is still inferred from the name. A catalogue entry below 32K is ignored.
With context.autoCompactThreshold at its default 0.85, a 1M declaration says compaction may wait until about 850,000 tokens. If llama.cpp was started with --ctx-size 262144, the server rejects the request long before that. The report behind this page shows a 400 saying the request exceeded the available context size (#13415, opened 4 October 2026, still open on 27 October 2026). The 1M row is still in the v0.26.2 source, so a current install can still do this. A too-small declaration is safer, but it can make compaction run early and trim the output budget.
Put the number where the provider entry can see it#
A model listed in modelProviders in ~/.qwen/settings.json (user) or .qwen/settings.json (project) is a provider model. Its generationConfig is sealed: fields it does not define are not filled from the top-level model.generationConfig. Moving contextWindowSize to the top level therefore does nothing for that model.
A minimal local setup:
{
"modelProviders": {
"openai": [
{
"id": "qwen3.6-35b-a3b",
"name": "Qwen3.6 35B (llama.cpp)",
"baseUrl": "http://localhost:8080/v1",
"envKey": "LOCAL_MODEL_API_KEY",
"generationConfig": {
"contextWindowSize": 262144,
"timeout": 300000,
"streamIdleTimeoutMs": 600000,
"samplingParams": {
"temperature": 0.2,
"max_tokens": 8192
}
}
}
]
},
"env": {
"LOCAL_MODEL_API_KEY": "not-needed"
},
"security": {
"auth": {
"selectedType": "openai"
}
},
"model": {
"name": "qwen3.6-35b-a3b"
},
"context": {
"autoCompactThreshold": 0.6
}
}Each field has a job:
idis the exact model name sent to your server;nameis only the/modellabel.baseUrlis the API root with/v1, not the full/v1/chat/completionspath; the SDK appends the path.envKeynames an environment variable; for a server with no auth, put any placeholder inenv.security.auth.selectedTypeselects the OpenAI-compatible route; without it,/authcan still open.model.namemust match anid.generationConfig.contextWindowSizeis the declared window. It fixes the meter and the compaction trigger.context.autoCompactThresholdis top-level because it is a context policy, not a model property. It defaults to 0.85 and acts as a ceiling; Qwen Code can compact earlier on small windows to leave room for the summary. Lower it, as the reporter in #13415 did with 0.6, if the server errors near the edge.timeoutandstreamIdleTimeoutMsmatter for a server that is slow to queue or produce the first chunk. The 15-minute stream lifetime cap still applies unlessQWEN_STREAM_MAX_LIFETIME_MSis raised or disabled.
If you configure a runtime model instead — a raw --model, or model.name without a matching provider entry — the top-level model.generationConfig.contextWindowSize applies. The sealed rule only bites when the model is also in modelProviders.
Two 2026 reports trace the confusion. In #1898 (closed 25 February 2026) a vLLM window was fixed by moving contextWindowSize into the provider entry. In #3878 (closed 11 May 2026) the top-level value was ignored and the footer showed 1000k; the outcome was a startup warning plus clearer docs. The placement rule did not change.
Check the window, not just the percentage#
The footer's Context 34% used is prompt tokens divided by contextWindowSize. If the denominator is wrong, the percentage is confidently wrong. Add the size to the status line.
Run /statusline, choose context-window-size, or add it to ui.statusLine.items in settings. The item prints something like 131.1k window. In command mode, the JSON on stdin includes context_window.context_window_size and used_percentage.
Compare that with the server's own setting: --ctx-size or n_ctx for llama.cpp, --max-model-len for vLLM, the context length in LM Studio, or the model's configured context in Ollama. If they differ, fix the provider entry, reopen /model, and check again.
/context detail answers a different question: on the first turn it lists each tool, MCP server, context file and skill that makes up the prompt. It does not tell you the window; it tells you what is filling it.
/about (or /status) confirms the version, model and auth type that won. If the model name is not the one you edited, you are in a different provider entry or scope. Recheck after an upgrade; model tables and presets change.
Coming from Gemini CLI#
Qwen Code is a fork of Gemini CLI, but the provider layer is its own. The model list is modelProviders in ~/.qwen/settings.json, not ~/.gemini/settings.json. Gemini CLI's model switching guide describes an Auto router that chooses between hosted models per request; Qwen Code's /model selects one provider entry for the session. The number comes from Qwen's own models.dev catalogue and fallback table, not Gemini's.
If the model does not appear in `/model`, or tool calls fail#
Two Qwen-specific traps account for most /model cases. A project .qwen/settings.json that defines modelProviders replaces the user-scope list for that repository rather than merging, so a catalogue that works elsewhere disappears in that checkout. And /model and /auth write model.name to the closest writable settings file that defines modelProviders, otherwise user settings; a model picked in one repository may not start another.
The provider key must be a built-in protocol (openai, anthropic, gemini, vertex-ai, or qwen-oauth) or an id mapped in top-level providerProtocol. For a local server the useful one is openai; the qwen-oauth models are hard-coded and cannot be overridden. The provider reference covers duplicate entry identity, hot reload and the rest.
If the route is right and a tool call still fails, the request body is the next suspect. Qwen sends tool schemas and tool results, and strict servers reject parts of them. Ollama rejects tools whose schema Qwen sends without parameters, which it omits on tools with no arguments (#12878, open, 27 September 2026); a related strict-gateway report is also open (#11956, open, 15 September 2026). generationConfig.samplingParams is passed verbatim, so keep it minimal if the server rejects unknown fields. Tool results default to "parts"; toolResultContentFormat: "string" is for older runtimes whose templates ignore text parts (settings reference), and splitToolMedia moves tool-returned images into a follow-up user message for strict servers such as LM Studio and new-api. If LM Studio answers Model is unloaded, load the model there first (#3802, open, 3 May 2026).
Where to go next#
- Qwen Code guides — the rest of the set.
- QWEN.md and AGENTS.md — what Qwen Code loads before the model sees your prompt.
- Context compaction — the meter, the 0.85 ladder and what the summary keeps.
- Gemini CLI model switching — the routing contrast in more detail.