Qwen Code 0.29.4 connects to Ollama, vLLM and llama.cpp through its OpenAI-compatible provider: a modelProviders.openai entry with the model id and baseUrl, security.auth.selectedType set to openai, model.name set to that id, and any placeholder key. Qwen Code infers the context window from the model id and assumes 256K or 1M for qwen-prefixed ids, while Ollama v0.40.21 allocates 4K on GPUs under 24 GiB of VRAM, so set OLLAMA_CONTEXT_LENGTH and generationConfig.contextWindowSize to the same number, at least 64000. On vLLM 0.34.0, tool calls need --enable-auto-tool-choice and --tool-call-parser qwen3_coder, and --max-model-len should equal contextWindowSize. On llama-server b12973, Jinja templates are on by default and the default port is 9931. Usage statistics are on by default for every auth method and, for openai auth, the payload includes the model id and the configured base_url, sent to an Alibaba Cloud RUM endpoint. A trusted repository's .qwen/settings.json can turn them back on, so the opt-out belongs in /etc/qwen-code/settings.json together with QWEN_USAGE_STATISTICS_ENABLED=false. Start by writing that system settings file on one developer machine this week.
To run Qwen Code with Ollama, vLLM or llama.cpp, point its OpenAI-compatible provider at the local server in ~/.qwen/settings.json: add a modelProviders.openai entry with the server's model id and baseUrl (http://host:11434/v1 for Ollama, http://host:8000/v1 for vLLM), set security.auth.selectedType to openai and model.name to that id, and give the key variable any placeholder value. Three more settings decide whether the agent works and stays private: generationConfig.contextWindowSize equal to the window the server allocated, tool calling switched on in the server, and privacy.usageStatisticsEnabled set to false, because usage statistics are on by default for every auth method, local endpoints included.
Everything below was read from the Qwen Code 0.29.4 docs and source, the release published to npm on December 4, 2026, and from the server documentation at vLLM 0.34.0, Ollama v0.40.21 and llama.cpp build b12973. Nothing here comes from a test run. Qwen Code's terms and privacy page records that the free Qwen OAuth allowance was discontinued on April 15, 2026, so without a subscription a self-hosted endpoint is the remaining route, and for a regulated team it is the route that keeps source code inside the network.
Qwen Code installs with npm install -g @qwen-code/qwen-code@latest, needs Node 22 or later, and runs as qwen. For where it sits among the other terminal and IDE agents, see the AI development tools pillar; the same local-model exercise for another CLI is in running Codex CLI against a local model with MCP tools.
Qwen Code local model setup in settings.json
The Qwen Code authentication docs list five options in the /auth menu, and the last one, Custom Provider, is the one for a local server, proxy or unsupported provider. You can click through it, but a hand-written file is reproducible and can be checked into a dotfiles repo or pushed by configuration management. Four keys do the work:
The following file declares an Ollama host and a vLLM host on the internal network, starts on the vLLM model, and turns off the three background calls Qwen Code makes by default. The hostnames are illustrative.
{
"modelProviders": {
"openai": [
{
"id": "qwen3-coder:30b",
"name": "Qwen3-Coder 30B (Ollama)",
"envKey": "OLLAMA_API_KEY",
"baseUrl": "http://ollama.internal:11434/v1",
"generationConfig": {
"timeout": 300000,
"streamIdleTimeoutMs": 600000,
"contextWindowSize": 65536
}
},
{
"id": "qwen3-coder",
"name": "Qwen3-Coder 30B (vLLM)",
"envKey": "VLLM_API_KEY",
"baseUrl": "http://vllm.internal:8000/v1",
"generationConfig": {
"contextWindowSize": 131072
}
}
]
},
"env": {
"OLLAMA_API_KEY": "ollama"
},
"security": {
"auth": {
"selectedType": "openai"
}
},
"model": {
"name": "qwen3-coder",
"catalogRefresh": false
},
"privacy": {
"usageStatisticsEnabled": false
},
"general": {
"enableAutoUpdate": false
}
}Ollama ignores the key, so the env block gives it a placeholder. VLLM_API_KEY is left to the shell because the vLLM server below runs with --api-key, and a real key belongs in the environment, outside a file people copy around. The key lookup order is the --openai-api-key flag, then the shell environment, then the first dotenv file found (in .qwen/ or the current directory, walking up toward the root, then the home directory), then the env block.
Generation settings go inside each provider entry. Provider entries are sealed: a top-level model.generationConfig does not fill in values an entry leaves out, so contextWindowSize and the timeouts have to sit where the block shows them.
export OPENAI_API_KEY="not-needed" export OPENAI_BASE_URL="http://vllm.internal:8000/v1" export OPENAI_MODEL="qwen3-coder" export QWEN_USAGE_STATISTICS_ENABLED=false export QWEN_CODE_MODELS_DEV_REFRESH=off qwen
Where the settings files live and which one wins
Qwen Code reads a user file at ~/.qwen/settings.json, a project file at .qwen/settings.json in the repository, and a system file at /etc/qwen-code/settings.json on Linux (/Library/Application Support/QwenCode/settings.json on macOS, C:\ProgramData\qwen-code\settings.json on Windows, overridable with QWEN_CODE_SYSTEM_SETTINGS_PATH). From lowest to highest precedence the layers are: built-in defaults, /etc/qwen-code/system-defaults.json, user, project, system settings, environment variables, and CLI arguments. Keep that order in mind for the egress section, because it decides who can turn usage statistics back on.
Environment variables only, for CI and containers
For a container or a CI job where writing a settings file is awkward, the auth docs describe an environment-only route: OPENAI_API_KEY, OPENAI_BASE_URL and OPENAI_MODEL select the OpenAI-compatible provider. Provider-specific names such as OLLAMA_API_KEY take effect only when a settings entry names them as envKey, so in this mode the key has to be OPENAI_API_KEY. If the vLLM server was started with --api-key, put that key in OPENAI_API_KEY instead of the placeholder. The same values are available per invocation as --openai-base-url, --openai-api-key, --model and --auth-type openai.
The API key screen that keeps coming back
Issue #3384, Unable to add OpenAI-compatible local LLM, opened on April 17, 2026 and still open on December 4 with 15 comments, describes a hand-written local provider that keeps showing the API-key screen. The first report is from 0.14.5, and adding security.auth.selectedType set to openai is what clears it for the reporter and others in the thread. The one-file example in the 0.29.4 docs includes that key, and so does the block above.
| Key | What it does | Note |
|---|---|---|
modelProviders.openai[] | Declares each endpoint: id (required), name, envKey, baseUrl, generationConfig | envKey defaults to OPENAI_API_KEY for the openai protocol |
env | Supplies key values as the lowest-priority fallback | A shell variable or dotenv file with the same name wins |
security.auth.selectedType | Picks the protocol on startup | Without it you are sent to /auth interactively |
model.name | Selects which provider entry starts | Must match an id exactly, Ollama tag included |
Qwen Code with Ollama: make the context windows agree
For Ollama, baseUrl is http://host:11434/v1, the model id is the Ollama tag (qwen3-coder:30b exists in the Ollama library), and the key is any placeholder. Those three values are enough for a chat reply, while an agent working on a real repository also needs two numbers, set in different places, to agree.
The first is the window Ollama allocates. The Ollama context length documentation at v0.40.21 sets the default from available VRAM: 4K tokens under 24 GiB, 32K from 24 to 48 GiB, and 256K at 48 GiB or more. The same page says tasks such as web search, agents and coding tools should be set to at least 64000 tokens. Ollama's OpenAI-compatible API cannot change the context size per request, so a client like Qwen Code has no way to ask for more; the window is set on the server with OLLAMA_CONTEXT_LENGTH or per model with num_ctx in a Modelfile.
The second is the window Qwen Code assumes. It infers the limit from the model id using a built-in pattern table plus the models.dev catalog where that has an entry, after stripping Ollama and LM Studio tags such as :30b and :latest. Ids starting with qwen3. followed by a digit map to 1M tokens, qwen3-coder- ids other than the hosted plus and flash models to 256K, and other qwen ids to 256K; an id it cannot place gets a 200,000-token fallback. A qwen-prefixed Ollama tag is therefore assumed to have 256K or 1M unless you set contextWindowSize.
On a 16 GiB card that combination means Qwen Code budgets against a window at least 64 times larger than the 4K Ollama loaded, and the overflow is handled on the server, which truncates the prompt. The mechanics of that truncation are covered in Ollama's num_ctx and silent prompt truncation. The fix is to set both numbers to the same value:
OLLAMA_CONTEXT_LENGTH=65536 ollama serve ollama ps # CONTEXT column must show the window you set in contextWindowSize
The 65536 here matches the Ollama entry in the settings file above and clears Ollama's 64000 floor for coding tools. Pick the largest number your GPU holds alongside the weights, then copy it into contextWindowSize. If ollama ps shows a smaller CONTEXT value than you asked for, Qwen Code's setting is wrong until you lower it to match.
Qwen Code with vLLM: the flags that make tool calls work
The Qwen Code docs state that it sends tool definitions on every request, so the server must turn the model's tool-call output into OpenAI tool_calls. On vLLM that needs two flags. The vLLM tool calling documentation at v0.34.0 marks --enable-auto-tool-choice as mandatory for auto tool choice and lists Qwen3-Coder-480B-A35B-Instruct and Qwen3-Coder-30B-A3B-Instruct under the qwen3_xml parser. The Qwen3-Coder-Next model card uses qwen3_coder in its own vllm serve example. At 0.34.0 the parser registry maps both names to the same Qwen3EngineToolParser class, so either works. Without a parser the model's tool calls come back as plain text in the reply and the agent never runs them.
vllm serve Qwen/Qwen3-Coder-30B-A3B-Instruct \ --served-model-name qwen3-coder \ --max-model-len 131072 \ --enable-auto-tool-choice \ --tool-call-parser qwen3_coder \ --api-key "$VLLM_API_KEY" \ --port 8000
--served-model-name is the id in the settings file, and --max-model-len is its contextWindowSize. Qwen3-Coder-30B-A3B-Instruct has a native context of 262,144 tokens; 131072 is a setting for a deployment whose KV cache cannot hold the full window, and the Qwen3-Coder-Next card itself suggests dropping to 32,768 on out-of-memory errors. Whatever you choose, use the same number on both sides. vLLM 0.34.0 is the release to pin: the vLLM security advisories published on November 18 and November 29, 2026 list it as the patched version.
This model is an instruct model, so the command has no reasoning parser. For a Qwen3.x thinking model, add --reasoning-parser qwen3. The empty-tool_calls and reasoning_content failures that come from parser choice on these models are covered in vLLM tool parsers and empty tool_calls, and keeping the vLLM server from reaching Hugging Face at startup is covered in running vLLM air-gapped.
Custom served model names
The Qwen Code model providers guide documents a rule that applies whenever --served-model-name does not start with qwen, for example --served-model-name chat. Qwen Code then cannot infer that the model is a Qwen3.x model: it loses thinking control and falls back to the 200,000-token window. Declare both in the provider entry: capabilities.reasoning.profile set to qwen-chat-template, which sends chat_template_kwargs.enable_thinking to the server, and generationConfig.contextWindowSize equal to --max-model-len. Set the window explicitly whatever the name, since inference from the id cannot see --max-model-len.
Qwen Code with llama.cpp and LM Studio
llama-server speaks the same OpenAI-compatible protocol, and the llama-server README at build b12973 settles four details. --jinja is enabled by default, and OpenAI-style function calling is supported only with Jinja templates, so the setting that breaks Qwen Code is --no-jinja; some models also need --chat-template-file. -c sets the context size, and its default of 0 loads the value from the model file. --alias sets the model name the API reports, which is the id Qwen Code must send. The default port is 9931, so pass --port if your firewall rules or docs assume another.
llama-server -m /models/Qwen3-Coder-30B-A3B-Instruct-Q4_K_M.gguf \ --alias qwen3-coder \ -c 65536 \ --host 0.0.0.0 --port 8080 \ --api-key "$LLAMA_KEY"
The matching provider entry uses baseUrl http://host:8080/v1, id qwen3-coder and contextWindowSize 65536. The GGUF path is illustrative. For LM Studio, the Qwen Code docs give http://localhost:1234/v1 as the base URL and lm-studio as a placeholder key.
Older guides for both servers mention API Error: 400 Failed to initialize samplers: failed to parse grammar. That error came from the built-in tool schemas Qwen Code sent, with empty properties maps and large maxLength values that llama.cpp's grammar converter rejected; it was reported against LM Studio 0.4.21 in issue #10065 and against llama-server in issue #10435. Pull request #10080, which normalizes tool schemas for grammar-based providers, merged on September 6, 2026 and shipped in 0.23.1. The interim workaround of setting tools.eager to an empty list is unnecessary on current versions, and at 0.29.4 it holds every built-in tool schema back from the initial request, so upgrade instead.
What breaks with local models in Qwen Code
Each of the following local-model failures has a setting that addresses it:
The timeout keys cover different spans. timeout is per request and can also be set with QWEN_CODE_API_TIMEOUT_MS; streamIdleTimeoutMs is the gap allowed between chunks and can be set with QWEN_STREAM_IDLE_TIMEOUT_MS, with the per-entry value winning; 0 disables either. QWEN_STREAM_MAX_LIFETIME_MS caps a single stream and has no settings.json equivalent. The Ollama entry in the settings file raises both values for a server slow to produce its first token.
The re-processing row is issue #14203, open since October 14, 2026. Since 0.25.1 Qwen Code places its auto-memory catalog at the tail of every main request. On hybrid and recurrent models served by llama.cpp-based servers, reported on Ollama 0.40.3 with Qwen3.8-27B, the cached prefix stops matching once the catalog grows past about 512 tokens and the server processes the whole prompt again on every step. The maintainer triage names the reporter's workaround, setting both memory keys to false; both default to true at 0.29.4. Why these models cannot reuse a partial cache is explained in prompt re-processing on SWA and hybrid models. A different failure in the same tool loops, the Qwen chat template raising an error when no user turn is left in the history, is covered in No user query found in messages.
Two diagnostics cover the rest. model.enableOpenAILogging, or --openai-logging for one session, writes each request and response to JSON files under logs/openai in the working directory (model.openAILoggingDir moves them), which shows the exact tools, window and messages the server received. If a session ends with Model stream ended with empty response text., those logs show whether the server returned the answer in a field Qwen Code did not read. /doctor runs installation and environment checks. The request logs contain your prompts and code, so point openAILoggingDir at a directory that stays on the machine and delete it when you finish.
| Symptom | Cause | Setting |
|---|---|---|
No stream activity for 120000ms after 19 chunks, or the older API Error: terminated (cause: Body Timeout Error) | A slow server exceeds a timeout guard | generationConfig.timeout (default 120000 ms), streamIdleTimeoutMs (default 240000 ms), QWEN_STREAM_MAX_LIFETIME_MS (default 900000 ms) |
| Every agent step re-processes the whole prompt on Ollama or llama-server | The auto-memory catalog is appended to the end of each request | memory.enableManagedAutoMemory and memory.enableManagedAutoDream set to false |
| The agent forgets instructions or earlier files mid-task | Qwen Code's assumed window is larger than the server's | contextWindowSize equal to the server window |
| Tool calls appear as text in the reply | No tool-call parser on the server | --enable-auto-tool-choice and --tool-call-parser on vLLM; no --no-jinja on llama-server |
| The API key screen appears on every start | Missing protocol selection (issue #3384) | security.auth.selectedType set to openai |
API Error: 400 Failed to initialize samplers: failed to parse grammar | Tool schemas before 0.23.1 | Upgrade to 0.23.1 or later |
Qwen Code telemetry and network egress with a local model
A local baseUrl moves inference inside the network and leaves the CLI's other outbound traffic as it was. The 0.29.4 terms and privacy page states that usage statistics are enabled by default for all authentication methods and are sent to an Alibaba Cloud RUM collection endpoint. The settings reference lists what they include: tool names, categories, status and duration, the model used per request, request duration and success, and CLI configuration such as enabled tools and approval mode. The docs state that prompt, response and file content are not collected.
The Qwen Code usage logger source at v0.29.4 sets the host to gb4w8c3ygj-default-sea.rum.aliyuncs.com on port 443, and its payload carries auth_type, model and, when auth is openai or openai-responses, base_url, the endpoint URL you configured. With a local provider, the internal hostname of your inference server and the model id you serve travel in the usage payload until statistics are off. For a team in a regulated environment this discloses internal infrastructure names to a third-party endpoint, and it belongs in the same review as any other outbound data flow.
The default outbound paths at 0.29.4, usage statistics included:
Turning usage statistics off also stops the catalog refresh. OpenTelemetry is separate from all of this: the telemetry.* group (telemetry.enabled, telemetry.otlpEndpoint, telemetry.otlpProtocol) sends to a collector you name, and telemetry.includeSensitiveSpanAttributes adds prompts and tool input and output to the spans, so leave that key off unless the collector sits inside the perimeter.
A repository can turn usage statistics back on
Settings precedence lets a repository undo a user's opt-out. A user who sets privacy.usageStatisticsEnabled to false in ~/.qwen/settings.json is overridden by any trusted workspace whose .qwen/settings.json sets it to true, because project settings outrank user settings. The usage statistics section of the settings reference names this case and points operators to model.catalogRefresh as the catalog opt-out a repository cannot override, since that key is honored only in user and system scope. For usage statistics, two places above the project file can hold the opt-out: the system settings file and the environment variable, where only true or 1 enables collection.
| Path | Default | Destination | How to turn it off |
|---|---|---|---|
| Usage statistics | On for every auth method | Alibaba Cloud RUM endpoint | privacy.usageStatisticsEnabled: false or QWEN_USAGE_STATISTICS_ENABLED=false |
| Model catalog refresh | At most once every 24 hours | https://models.dev/api.json | model.catalogRefresh: false (user or system scope only) or QWEN_CODE_MODELS_DEV_REFRESH=off |
| Update check | general.enableAutoUpdate true: checks and installs on startup | Not named in the docs | general.enableAutoUpdate: false |
| web_fetch tool | Available to the agent | Any URL the model requests | Deny WebFetch in permissions.deny |
| MCP servers | Only those you configure | Whatever each server calls | Review each mcpServers entry |
Lock Qwen Code down at system scope
A perimeter install puts the opt-outs in the system file, which outranks user and project settings:
{
"privacy": { "usageStatisticsEnabled": false },
"model": { "catalogRefresh": false },
"general": { "enableAutoUpdate": false },
"slashCommands": { "disabled": ["auth"] },
"permissions": { "deny": ["WebFetch"] }
}Write it to /etc/qwen-code/settings.json and add export QWEN_USAGE_STATISTICS_ENABLED=false to the login profile, because environment variables outrank system settings in both directions: a developer who exports true would otherwise re-enable collection. The Qwen Code settings reference documents the other two keys. slashCommands.disabled with auth removes the /auth command, so nobody switches the session to a cloud provider, and a list set at system scope cannot be shrunk from user scope. The WebFetch deny rule removes the fetch tool, and deny rules are also enforced against equivalent shell commands such as curl and wget; drop it if the team needs the agent to read internal documentation over HTTP. On Linux, operators can go further with tools.executionSandbox, whose network setting takes open or closed.
None of this replaces an egress firewall, because the 0.29.4 settings reference has no single offline switch and a new release can add a path. Allow the developer machines to reach the inference hosts and the internal package mirror, and deny the rest. The verification method, from packet capture to a blocked-egress run, is written up for another agent in OpenCode offline mode for air-gapped networks and applies unchanged; the Anthropic-side equivalent is in Claude Code with a local model. Our on-premise AI development team builds and verifies this setup on client GPUs.
Check your Qwen Code local setup this week
Five checks confirm that a Qwen Code install is local in practice:
ollama ps (or the vLLM and llama-server launch flags) shows the same window as contextWindowSize in the provider entry.--openai-logging produces a request body whose model, tool list and message history look the way you expect./etc/qwen-code/settings.json exists with privacy.usageStatisticsEnabled set to false, and QWEN_USAGE_STATISTICS_ENABLED=false is in the login profile.*.rum.aliyuncs.com or models.dev.Pin the version you checked, Qwen Code 0.29.4 or whatever you deploy, since enableAutoUpdate is now off and upgrades become a decision. The one action to take this week is the fourth check: write the five-key system settings file above to one developer machine, run a session, and confirm in the firewall log that nothing went to the RUM host.
FAQ
Quick answers to the questions this post tends to raise.



