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.
Get running in a few minutes:
You should see: Qwen Code generates the string reversal function
Configure Qwen Code to use Qwen Cloud:
Configure multiple models for different tasks:
Qwen Code supports specialized sub-agents:
Connect external tools via Model Context Protocol:
Create reusable workflows:
Reduce consumption by:
"401 Incorrect API key provided"
Use
Type
Quick start
Get running in a few minutes:
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
Authentication methods
- API Key (Recommended)
- Qwen OAuth (1000 free calls/day)
Edit
~/.qwen/settings.json (macOS/Linux) or C:\Users\username\.qwen\settings.json (Windows):Model configuration
Configure multiple models for different tasks:
| Model | Best for | Configuration |
|---|---|---|
qwen3.5-plus | General coding | Default, with thinking mode |
qwen3-coder-next | Fast iterations | Lightweight, quick responses |
qwen3-coder-plus | Complex logic | Deep code understanding |
qwen3-max | Architecture | Advanced 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
Code generation
Code review
Refactoring
Testing
Commands
| Command | Description |
|---|---|
/auth | Switch authentication method |
/model | Change active model |
/compress | Compress conversation history |
/clear | Clear all history |
/settings | View/edit settings |
/help | Show 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:
Custom skills
Create reusable workflows:
Token optimization
Reduce consumption by:
- Directory focus: Start Qwen Code in specific project folders
- Settings optimization:
- Regular compression: Use
/compressto free tokens - Clear sessions:
/clearbetween unrelated tasks - Model selection: Use lighter models for simple tasks
Troubleshooting
"401 Incorrect API key provided"
Solution:High token consumption
- Verify API key in settings.json
- Check baseUrl matches your region
- Ensure API key has quota
Solution:"Range of input length should be [1, xxx]"
- Set
sessionTokenLimitin settings- Work in focused directories
- Use
/compressregularly- Clear history with
/clear
Solution:Model not responding
- Reduce context with
/compress- Lower sessionTokenLimit
- Start new session with
/clear
Solution:
- Check
/modelto 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
/compressand/clearregularly - Set
sessionTokenLimitto limit context - Start Qwen Code in specific directories
- Use appropriate models for tasks
Related resources
- Coding Plan: Setup with subscription →
- Models & pricing: See pricing →
- API docs: OpenAI-compatible reference →
- Official docs: Qwen Code documentation →