Qwen Code CLI: install, sign in, models and headless use
Qwen Code, the open-source terminal coding agent: install, the end of the free tier, sign-in over SSH, API keys, models, config and headless mode.
Qwen Code is the Qwen team’s open-source coding agent for the terminal, Apache 2.0, originally based on Google’s Gemini CLI and developed on its own since. Install it with npm install -g @qwen-code/qwen-code@latest on Node.js 22 or later (0.29.0 as of November 28, 2026) and run qwen. The free Qwen OAuth sign-in closed on April 15, 2026: signing in with a Qwen account now needs a Plus or Pro subscription, and everything else is an API key, from Alibaba Cloud Model Studio, OpenRouter or any OpenAI-, Anthropic- or Gemini-compatible provider. Over SSH the account sign-in prints a URL you open on your own laptop or phone; a key needs no browser at all.
What Qwen Code is
The repository’s README calls it “The open-source AI coding agent for your terminal, editor, desktop, browser, and chat.” It reads your code, edits files and runs commands, like the other terminal agents. Its origin is stated plainly: “This project was originally based on Google Gemini CLI v0.8.2”, and from version 0.1 it became independent development. So the layout will look familiar to anyone who has used Gemini CLI: a ~/.qwen/ folder where Gemini has ~/.gemini/, a QWEN.md where Gemini has GEMINI.md, and the same -p flag for one-shot runs.
Unlike its parent, it is not tied to one company’s models. The README lists “OpenAI, Anthropic, Gemini, and Qwen APIs”, third-party providers and local models through Ollama or vLLM, with the model switchable mid-session. Besides the terminal it ships a desktop app, editor integrations and a web UI. Releases are frequent: 0.28.6, 0.28.7 and 0.29.0 came out between November 26 and 28, with a 1.0 preview running alongside on its own tag.
Install Qwen Code
The npm package is @qwen-code/qwen-code, its command is qwen, and its engines field asks for >=22.0.0, so check node --version first. The README gives four routes:
npm install -g @qwen-code/qwen-code@latest # any OS with Node.js 22+
brew install qwen-code # Homebrew, macOS or Linux
# the standalone installer, macOS and Linux
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.sh | bash
# the standalone installer, Windows PowerShell
irm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iexCopiedThe installer scripts run whatever the URL serves, so read the script first if that matters to you; the npm route is the one to pin and update with the rest of your tooling. After installing, the README says to restart the terminal so the new PATH takes effect. If a global npm install fails with a permissions error, the npm install -g guide covers the cause and the fixes.
Signing in: what changed in April 2026
Most older guides say Qwen Code is free with a Qwen account, up to 1,000 requests a day. That ended. In an issue on the repository, “Qwen OAuth Free Tier Policy Adjustment”, the team cut the free allowance to 100 requests a day on April 13, 2026, and announced:
Completely close the Qwen OAuth free entry point on 2026-04-15CopiedThe program itself stayed free and open source. What went was the free model access behind the sign-in. The first run of qwen (or /auth at any time) now offers five choices:
| Option in /auth | What it is | Needs a browser |
|---|---|---|
Qwen Account with Subscription | A Qwen account with an active Plus or Pro subscription from chat.qwen.ai; usage is subject to the plan | Once, for the sign-in |
QwenCloud | A Token Plan (a monthly credit quota) or a pay-as-you-go key, on the China or international platform | No |
Alibaba ModelStudio | A Coding Plan key (keys start sk-sp-), a Token Plan key or a standard Model Studio (DashScope) key | No |
Third-party Providers | Built-in entries for DeepSeek, Grok, MiniMax, Z.AI, Kimi, OpenRouter, Requesty and others, with your key | No |
Custom Provider | Any OpenAI-, Anthropic- or Gemini-compatible endpoint, a local server included; for OpenAI- and Anthropic-style endpoints Qwen Code fetches the model list | No |
The authentication guide names no free tier anywhere, and points CI and unattended containers, where a browser sign-in is not possible, at the API-key methods.
Signing in on a headless server over SSH
The subscription sign-in is a device authorization flow: Qwen Code asks chat.qwen.ai for a sign-in link, shows it, and waits while you approve it anywhere. No local port has to be reachable, so it works over SSH. Qwen Code decides not to open a browser on Linux when none of DISPLAY, WAYLAND_DISPLAY or MIR_SOCKET is set (the usual SSH session), on macOS and Windows when SSH_CONNECTION is set, and anywhere CI is set. It then prints a box headed “Qwen OAuth Device Authorization”:
Please visit the following URL in your browser to authorize:
...
Waiting for authorization to complete...CopiedOpen the URL on your laptop or phone, sign in with the same Qwen account that holds the subscription, and approve; the SSH session carries on by itself. If you take too long it stops with “Authorization timeout, please restart the process.” The result is saved to ~/.qwen/oauth_creds.json, readable by your user only, and reused on later runs. To keep a session running after you disconnect, start it inside tmux.
With an API key there is nothing to approve. Keep the key out of your shell history by putting it in ~/.qwen/.env, which Qwen Code reads on start:
mkdir -p ~/.qwen
read -rsp 'API key: ' k; echo
(umask 077; printf 'OPENROUTER_API_KEY=%s\n' "$k" >> ~/.qwen/.env); unset k
chmod 600 ~/.qwen/.env # appended, so anything already in the file staysCopiedQwen Code reads only the first .env it finds, and the files are not merged. It looks in the current directory, then each parent in turn, for .qwen/.env and then .env; only if none turns up does it read ~/.qwen/.env, then ~/.env. A project with its own .env hides the key in your home one, and a variable already set in your shell wins over any file. Keys can also go in the env block of settings.json, which the docs note is plain text; the .env file is the better home for a secret.
Using an OpenRouter or Model Studio key
A provider is described in ~/.qwen/settings.json under modelProviders, grouped by protocol. OpenRouter is OpenAI-compatible, so it goes under openai, with envKey naming the variable that holds the key. Adapted from the docs’ own OpenRouter entry:
{
"modelProviders": {
"openai": [
{
"id": "openai/gpt-4o",
"name": "GPT-4o (via OpenRouter)",
"envKey": "OPENROUTER_API_KEY",
"baseUrl": "https://openrouter.ai/api/v1"
}
]
},
"security": { "auth": { "selectedType": "openai" } },
"model": { "name": "openai/gpt-4o" }
}CopiedSwap the id and model.name for any model ID OpenRouter lists (the OpenRouter models guide shows how to find the exact one), and see the OpenRouter API key guide for making one. Third-party Providers in /auth offers OpenRouter as a built-in entry if you would rather not edit the file.
For Alibaba’s own models, Alibaba ModelStudio in /auth takes a Coding Plan key (variable BAILIAN_CODING_PLAN_API_KEY, base URL https://coding-intl.dashscope.aliyuncs.com/v1 outside China) or a standard key. The Coding Plan endpoint is not the standard DashScope one, so the base URL has to match the key. One rule matters on a server: Alibaba’s Coding Plan FAQ says the plan is “intended only for AI coding tools, such as Claude Code and Qwen Code”, and warns:
Do not use the plan's API key for automated scripts, custom application backends, or any non-interactive batch-calling scenarios.CopiedDoing so “may result in the suspension of your subscription or the disabling of your API key.” Its quota runs on a 5-hour, a weekly and a monthly window, counted in model calls rather than tokens. For scheduled jobs, use a pay-as-you-go key.
Which models it uses
Whatever the sign-in gives it. With the subscription, /model lists the models your plan includes (Qwen4-Max was added to that catalogue in the 1.0 preview of November 25). With an OpenAI-compatible key and no model set, the default is qwen3.5-plus. The Coding Plan list in the docs mixes Alibaba’s models with others: qwen3.7-plus, qwen3.6-plus (Pro only), qwen3.5-plus, qwen3-coder-plus, qwen3-coder-next, qwen3-max-2026-01-23, glm-5, glm-4.7, kimi-k2.5 and MiniMax-M2.5. Switch inside a session with /model, or at launch with --model (and --auth-type to pick the protocol).
Where Qwen Code keeps its config
Per-user state lives in ~/.qwen/; set QWEN_HOME to move it.
| Path | What it holds |
|---|---|
~/.qwen/settings.json | Your settings and providers |
.qwen/settings.json | The project’s settings, which override yours |
/etc/qwen-code/settings.json | System settings on Linux, which override both |
/etc/qwen-code/system-defaults.json | System defaults on Linux, which user and project files override |
~/.qwen/.env | Keys and other environment variables |
~/.qwen/oauth_creds.json | The cached Qwen account sign-in |
~/.qwen/QWEN.md | Your instructions for every project |
~/.qwen/projects/ | Per-project auto-memory |
In a project, Qwen Code reads QWEN.md at the root and a personal .qwen/QWEN.local.md to keep out of git, and in the docs’ words, “If your repository already has an AGENTS.md file for other AI tools, Qwen reads that too.” (More on that file in what AGENTS.md is.) The full order, lowest first: defaults, system defaults, user, project, system, environment variables, then command-line flags.
Running it without a prompt open
-p (or --prompt) runs one task and exits, and piped input works too:
qwen -p "Review this patch" --output-format json
qwen -p "Write a Python script" --output-format stream-json --include-partial-messages
qwen --continue -p "Run the tests again and summarize failures" # resume the last session
echo "Explain this code" | qwenCopiedWithout a flag it does not approve edits and commands on its own. --approval-mode takes plan, default, auto-edit, auto or yolo, and --yolo approves everything; the docs warn that “--yolo does not enable a sandbox”, so commands run with your user’s full rights. On a server, run it as an ordinary user, never root. A run that hits its turn limit exits with 53 and one that hits its budget with 55, so a script can tell those from a success. For a scheduled job, authenticate with a pay-as-you-go key in ~/.qwen/.env, not a Coding Plan key, for the reason above.
Qwen Code beside Claude Code, Codex and Gemini CLI
As read on November 28, 2026, from each project’s own README:
| Qwen Code | Gemini CLI | Codex CLI | Claude Code | |
|---|---|---|---|---|
Maker | The Qwen team at Alibaba | OpenAI | Anthropic | |
Licence | Apache 2.0 | Apache 2.0 | Apache 2.0 | Anthropic’s commercial terms |
Sign-in | A Qwen Plus or Pro subscription, or a key from any OpenAI-, Anthropic- or Gemini-compatible provider | Code Assist Standard or Enterprise (see the Gemini CLI guide for keys); free and Google One users moved to Antigravity CLI | Sign in with ChatGPT, or an API key | See the Claude Code login guide |
The difference that counts most is the model question. Codex, Claude Code and Gemini CLI are each their maker’s front end; Qwen Code is a front end for whatever key you bring, with Alibaba’s subscription as one option among several. If your models come through OpenRouter or a cheaper open-model provider, that makes it a natural fit; if you already pay for ChatGPT or Claude, the maker’s own agent uses that plan directly. The Claude Code alternatives guide sets the wider field side by side, and choosing a VPS for a coding agent covers the server any of them runs on.