Qwen Code is a command-line AI workflow tool optimized for Qwen3-Coder. It boosts development efficiency through advanced code comprehension, task automation, and intelligent assistance features.
Procedure
Preparations
Get an API key: Get an API key before you start.
Check the Node.js version: Qwen Code requires Node.js version 20 or later. Run
node -vto check the version. If the version is earlier than 20, you must reinstall it.
Install and configure Qwen Code
Install Qwen Code
Run one of the following commands in your terminal to install Qwen Code.
Install using npm (Recommended)
npm install -g @qwen-code/qwen-code@latestInstall from source
git clone https://github.com/QwenLM/qwen-code.git cd qwen-code npm install npm install -g .Start and configure Qwen Code
Start Qwen Code
Enter
qwenin your terminal to start Qwen Code.Select an authentication method
This example uses the OpenAI-compatible authentication provided by Model Studio. Select OpenAI and press Enter.

Enter the following information on the page:
Item
Description

API Key
Your Model Studio API key.
Base URL
Singapore:
https://dashscope-intl.aliyuncs.com/compatible-mode/v1Virginia:
https://dashscope-us.aliyuncs.com/compatible-mode/v1Beijing:
https://dashscope.aliyuncs.com/compatible-mode/v1
Model
The name of the model. Qwen Code is specifically optimized for the Qwen3-Coder series and is compatible with models that provide an OpenAI compatible API, such as Qwen-Max, Qwen-Plus, Qwen-Flash, and DeepSeek. We recommend models with strong coding capabilities, such as:
qwen3-coder-plusqwen3-coder-480b-a35b-instructqwen3-coder-flashqwen3-coder-30b-a3b-instruct
To avoid entering this information every time you start Qwen Code, export environment variables as described below.
Export environment variables
Ask Qwen Code
In the dialog box, enter "How to implement a Binary Search Tree in Python?" Qwen Code then creates a plan and requests permission to perform operations, such as creating, writing to, and executing files.

The result is shown in the following figure:

View token usage
Enter /stats model to view the token usage and the number of API calls since Qwen Code was started.

Free quota
Claim a free quota in one of the following two ways:
Method 1: Model Studio's new user free quota
Model Studio provides a free quota of 1 million tokens for each model, such as Qwen3-Coder (only in the Singapore region). When you access the service using the OpenAI authentication method, the free quota for the model is used first. To check the remaining quota, go to the Models page and click the model card. To avoid extra charges, turn on the Free Quota Only feature.

Method 2: Qwen Code daily free quota
Authenticate with Qwen Chat to receive 2,000 free API calls daily. After you start Qwen Code, enter
/auth, select the Qwen Oauth authentication method, and log on to your Qwen Chat account on the redirected page or scan the QR code to authenticate.Note:
To continue using the service after the 2,000 API calls are used, switch to the OpenAI authentication method using the
/authcommand.If you are using Qwen Chat for the first time, register an account.
You cannot switch models with this authentication method. To maintain service quality, the model may be downgraded.
Advanced operations
For more information about the advanced features of Qwen Code or other coder models of the Qwen series, see the Qwen Code documentation and Model Studio's Coding capabilities (Qwen-Coder).
FAQ
Q: Why does Qwen Code consume tokens quickly?
A: Qwen Code may call the API multiple times, which can consume many tokens. Use the following methods to control token consumption:
Streamline the working directory
Start Qwen Code in a specific project directory. Having too many files in the startup directory, such as the root directory, can increase token consumption.
Set a token limit
Create a
.qwen/settings.jsonfile in the project root directory and restart Qwen Code. UsesessionTokenLimitto control the token usage for a single API call:{ "sessionTokenLimit": 32000 }Qwen Code may call the API multiple times, which can cause the token consumption for a single question to exceed the
sessionTokenLimitvalue.Use compression/purge commands
Enter the following commands to reduce token consumption:
/compressCompresses the conversation history to continue the dialogue within the token limit.
/clearPurges all conversation history and starts a new session.
Q: How to switch models?
A: The method depends on whether you have set environment variables:
If you have not configured environment variables
Enter
/quitto exit Qwen Code.Enter
qwento start Qwen Code, select the OpenAI authentication method, and then enter the API key, base URL, and target model name.
If you have configured environment variables
Change the
OPENAI_MODELenvironment variable to the target model and apply the change. For more information, see Export environment variables.Enter
/quitto exit Qwen Code, and then enterqwento restart it.
Q: Why do I get a 401 Incorrect API key provided error?
A: This error may be caused by an incorrect API configuration. Compare the API key in the error message with your settings to ensure they match. Global environment variable configurations take precedence over environment file configurations. To use the configuration from the environment file, ensure that the relevant global environment variables are not set or clear them temporarily.
For more information, see Qwen Code troubleshooting guide.