Skip to main content
Clients & tools

Qwen Code

Official CLI for Qwen models

Qwen Code is the official CLI tool for Qwen models, providing AI-powered coding assistance directly in your terminal. Connect it to Qwen Cloud's pay-as-you-go API for seamless access to Qwen3-Coder and other Qwen models.

Quick start

Get running in a few minutes:
# 1. Install
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.sh | bash
qwen --version

# 2. Configure (~/.qwen/settings.json)
{
  "env": {
    "QWENCLOUD_API_KEY": "sk-xxx"
  },
  "modelProviders": {
    "openai": [{
      "id": "qwen3.5-plus",
      "name": "[QwenCloud] qwen3.5-plus",
      "baseUrl": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
      "envKey": "QWENCLOUD_API_KEY"
    }]
  }
}

# 3. Test (run qwen and ask)
qwen
Ask: "Write a Python function to reverse a string"
You should see: Qwen Code generates the string reversal function

Configuration

Basic setup

Configure Qwen Code to use Qwen Cloud:
  • API endpoint: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
  • Authentication: API key required
  • Model selection: Configure multiple Qwen models
Free quota and billing:
  • First-time users get a free quota (valid for 90 days)
  • Enable Free quota only to prevent unexpected charges
  • Qwen OAuth provides 1,000 free calls/day (separate from Qwen Cloud quota)
For Coding Plan users: Use your exclusive base URL and API key instead. See Coding Plan for Qwen Code.

Installation

  • macOS/Linux
  • Windows
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen.sh | bash
qwen --version

Authentication methods

  • Qwen OAuth (1000 free calls/day)

Model configuration

Configure multiple models for different tasks:
ModelBest forConfiguration
qwen3.5-plusGeneral codingDefault, with thinking mode
qwen3-coder-nextFast iterationsLightweight, quick responses
qwen3-coder-plusComplex logicDeep code understanding
qwen3-maxArchitectureAdvanced reasoning

Limitations

  • Token usage: Scans project files and conversation history
  • Context limit: Large projects may exceed token limits
  • File access: Cannot read files outside project directory

Examples

Basic usage

qwen
# Ask questions directly
"Explain this error: TypeError: 'NoneType' object is not iterable"

Code generation

"Create a FastAPI endpoint for user registration with email validation"

Code review

"Review this function for potential bugs and performance issues"

Refactoring

"Refactor this class to follow SOLID principles"

Testing

"Write comprehensive unit tests for the payment module"

Commands

CommandDescription
/authSwitch authentication method
/modelChange active model
/compressCompress conversation history
/clearClear all history
/settingsView/edit settings
/helpShow available commands

Advanced features

Sub-agents

Qwen Code supports specialized sub-agents:
  • File Agent: Navigate and edit files
  • Web Agent: Search documentation
  • Terminal Agent: Execute commands

MCP support

Connect external tools via Model Context Protocol:
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem"]
    }
  }
}

Custom skills

Create reusable workflows:
qwen /skill create "test-writer"
# Define the skill steps
qwen /skill use "test-writer"

Token optimization

Reduce consumption by:
  1. Directory focus: Start Qwen Code in specific project folders
  2. Settings optimization:
{
  "sessionTokenLimit": 32000
}
  1. Regular compression: Use /compress to free tokens
  2. Clear sessions: /clear between unrelated tasks
  3. Model selection: Use lighter models for simple tasks

Troubleshooting

"401 Incorrect API key provided"
Solution:
  • Verify API key in settings.json
  • Check baseUrl matches your region
  • Ensure API key has quota
High token consumption
Solution:
  • Set sessionTokenLimit in settings
  • Work in focused directories
  • Use /compress regularly
  • Clear history with /clear
"Range of input length should be [1, xxx]"
Solution:
  • Reduce context with /compress
  • Lower sessionTokenLimit
  • Start new session with /clear
Model not responding
Solution:
  • Check /model to verify selection
  • Verify model in settings.json
  • Try switching to different model

FAQ

How to use 1,000 free calls/day?

Use /auth → Select "Qwen OAuth" → Authenticate via browser. This quota is separate from Qwen Cloud quota.

How to switch models?

Type /model to select from configured models, or add new models to settings.json.

How to reduce costs?

  • Use /compress and /clear regularly
  • Set sessionTokenLimit to limit context
  • Start Qwen Code in specific directories
  • Use appropriate models for tasks