2025-06-26 09:38:11 +08:00
# Qwen Code
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
< div align = "center" >
2025-07-22 19:59:07 +08:00

2025-08-01 00:28:32 +08:00
[](https://www.npmjs.com/package/@qwen -code/qwen-code)
[](./LICENSE)
[](https://nodejs.org/)
[](https://www.npmjs.com/package/@qwen -code/qwen-code)
**AI-powered command-line workflow tool for developers**
[Installation ](#installation ) • [Quick Start ](#quick-start ) • [Features ](#key-features ) • [Documentation ](./docs/ ) • [Contributing ](./CONTRIBUTING.md )
< / div >
Qwen Code is a powerful command-line AI workflow tool adapted from [**Gemini CLI** ](https://github.com/google-gemini/gemini-cli ) ([details ](./README.gemini.md )), specifically optimized for [Qwen3-Coder ](https://github.com/QwenLM/Qwen3-Coder ) models. It enhances your development workflow with advanced code understanding, automated tasks, and intelligent assistance.
2025-07-24 00:07:31 +08:00
2025-08-08 09:48:31 +08:00
## 💡 Free Options Available
Get started with Qwen Code at no cost using any of these free options:
### 🔥 Qwen OAuth (Recommended)
- **2,000 requests per day** with no token limits
- **60 requests per minute** rate limit
- Simply run `qwen` and authenticate with your qwen.ai account
- Automatic credential management and refresh
- No API key setup required
### 🌏 Regional Free Tiers
- **Mainland China**: ModelScope offers **2,000 free API calls per day**
- **International**: OpenRouter provides **up to 1,000 free API calls per day** worldwide
For detailed setup instructions, see [Authorization ](#authorization ).
2025-07-24 00:07:31 +08:00
> [!WARNING]
2025-08-01 00:31:34 +08:00
> **Token Usage Notice**: Qwen Code may issue multiple API calls per cycle, resulting in higher token usage (similar to Claude Code). We're actively optimizing API efficiency.
2025-07-22 19:59:07 +08:00
## Key Features
- **Code Understanding & Editing** - Query and edit large codebases beyond traditional context window limits
- **Workflow Automation** - Automate operational tasks like handling pull requests and complex rebases
- **Enhanced Parser** - Adapted parser specifically optimized for Qwen-Coder models
2025-08-01 00:28:32 +08:00
## Installation
2025-07-22 19:59:07 +08:00
### Prerequisites
Ensure you have [Node.js version 20 ](https://nodejs.org/en/download ) or higher installed.
2025-07-23 00:27:14 +08:00
```bash
2025-07-22 19:59:07 +08:00
curl -qL https://www.npmjs.com/install.sh | sh
```
2025-08-01 00:28:32 +08:00
### Install from npm
2025-08-01 00:31:34 +08:00
2025-07-22 19:59:07 +08:00
```bash
2025-07-30 18:21:28 +08:00
npm install -g @qwen -code/qwen-code@latest
2025-07-22 19:59:07 +08:00
qwen --version
```
2025-08-01 00:28:32 +08:00
### Install from source
2025-08-01 00:31:34 +08:00
2025-07-22 19:59:07 +08:00
```bash
2025-07-22 08:32:58 -07:00
git clone https://github.com/QwenLM/qwen-code.git
2025-07-22 19:59:07 +08:00
cd qwen-code
npm install
npm install -g .
```
2025-08-01 00:28:32 +08:00
## Quick Start
```bash
# Start Qwen Code
qwen
# Example commands
> Explain this codebase structure
> Help me refactor this function
> Generate unit tests for this module
```
### Session Management
Control your token usage with configurable session limits to optimize costs and performance.
#### Configure Session Token Limit
Create or edit `.qwen/settings.json` in your home directory:
2025-07-30 18:14:24 +08:00
```json
{
2025-07-31 15:23:31 +08:00
"sessionTokenLimit": 32000
2025-07-30 18:14:24 +08:00
}
```
2025-08-01 00:28:32 +08:00
#### Session Commands
- **`/compress` ** - Compress conversation history to continue within token limits
- **`/clear` ** - Clear all conversation history and start fresh
- **`/status` ** - Check current token usage and limits
> 📝 **Note**: Session token limit applies to a single conversation, not cumulative API calls.
2025-07-30 18:14:24 +08:00
2025-08-08 09:48:31 +08:00
### Authorization
Choose your preferred authentication method based on your needs:
2025-07-22 19:59:07 +08:00
2025-08-08 09:48:31 +08:00
#### 1. Qwen OAuth (🚀 Recommended - Start in 30 seconds)
2025-08-01 00:28:32 +08:00
2025-08-08 09:48:31 +08:00
The easiest way to get started - completely free with generous quotas:
```bash
# Just run this command and follow the browser authentication
qwen
```
**What happens:**
1. **Instant Setup** : CLI opens your browser automatically
2. **One-Click Login** : Authenticate with your qwen.ai account
3. **Automatic Management** : Credentials cached locally for future use
4. **No Configuration** : Zero setup required - just start coding!
**Free Tier Benefits:**
- ✅ **2,000 requests/day** (no token counting needed)
- ✅ **60 requests/minute** rate limit
- ✅ **Automatic credential refresh**
- ✅ **Zero cost** for individual users
- ℹ ️ **Note** : Model fallback may occur to maintain service quality
#### 2. OpenAI-Compatible API
Use API keys for OpenAI or other compatible providers:
**Configuration Methods:**
2025-07-23 17:47:41 +08:00
2025-08-01 00:28:32 +08:00
1. **Environment Variables**
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
```bash
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="your_api_endpoint"
export OPENAI_MODEL="your_model_choice"
```
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
2. **Project `.env` File**
Create a `.env` file in your project root:
```env
OPENAI_API_KEY=your_api_key_here
OPENAI_BASE_URL=your_api_endpoint
OPENAI_MODEL=your_model_choice
```
2025-07-25 13:15:25 +08:00
2025-08-08 09:48:31 +08:00
**API Provider Options**
2025-08-01 00:28:32 +08:00
> ⚠️ **Regional Notice:**
2025-08-01 00:31:34 +08:00
>
2025-08-01 00:28:32 +08:00
> - **Mainland China**: Use Alibaba Cloud Bailian or ModelScope
> - **International**: Use Alibaba Cloud ModelStudio or OpenRouter
< details >
< summary > < b > 🇨🇳 For Users in Mainland China< / b > < / summary >
**Option 1: Alibaba Cloud Bailian** ([Apply for API Key ](https://bailian.console.aliyun.com/ ))
2025-08-01 00:31:34 +08:00
2025-07-25 13:15:25 +08:00
```bash
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
export OPENAI_MODEL="qwen3-coder-plus"
```
2025-08-01 00:28:32 +08:00
**Option 2: ModelScope (Free Tier)** ([Apply for API Key ](https://modelscope.cn/docs/model-service/API-Inference/intro ))
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
- ✅ **2,000 free API calls per day**
- ⚠️ Connect your Aliyun account to avoid authentication errors
2025-07-25 13:15:25 +08:00
```bash
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://api-inference.modelscope.cn/v1"
export OPENAI_MODEL="Qwen/Qwen3-Coder-480B-A35B-Instruct"
```
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
< / details >
2025-07-25 13:15:25 +08:00
2025-08-01 00:28:32 +08:00
< details >
< summary > < b > 🌍 For International Users< / b > < / summary >
2025-07-25 13:15:25 +08:00
2025-08-01 00:28:32 +08:00
**Option 1: Alibaba Cloud ModelStudio** ([Apply for API Key ](https://modelstudio.console.alibabacloud.com/ ))
2025-08-01 00:31:34 +08:00
2025-07-22 19:59:07 +08:00
```bash
export OPENAI_API_KEY="your_api_key_here"
2025-07-25 13:15:25 +08:00
export OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
export OPENAI_MODEL="qwen3-coder-plus"
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
**Option 2: OpenRouter (Free Tier Available)** ([Apply for API Key ](https://openrouter.ai/ ))
2025-08-01 00:31:34 +08:00
2025-07-31 21:10:33 +08:00
```bash
export OPENAI_API_KEY="your_api_key_here"
2025-08-01 00:28:32 +08:00
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
2025-07-31 21:10:33 +08:00
export OPENAI_MODEL="qwen/qwen3-coder:free"
```
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
< / details >
2025-07-31 21:10:33 +08:00
2025-07-22 19:59:07 +08:00
## Usage Examples
2025-08-01 00:28:32 +08:00
### 🔍 Explore Codebases
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
```bash
2025-07-22 19:59:07 +08:00
cd your-project/
qwen
2025-08-01 00:28:32 +08:00
# Architecture analysis
2025-07-22 19:59:07 +08:00
> Describe the main pieces of this system's architecture
2025-08-01 00:28:32 +08:00
> What are the key dependencies and how do they interact?
> Find all API endpoints and their authentication methods
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
### 💻 Code Development
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
```bash
# Refactoring
2025-07-22 19:59:07 +08:00
> Refactor this function to improve readability and performance
2025-08-01 00:28:32 +08:00
> Convert this class to use dependency injection
> Split this large module into smaller, focused components
# Code generation
> Create a REST API endpoint for user management
> Generate unit tests for the authentication module
> Add error handling to all database operations
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
### 🔄 Automate Workflows
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
```bash
# Git automation
> Analyze git commits from the last 7 days, grouped by feature
> Create a changelog from recent commits
> Find all TODO comments and create GitHub issues
2025-07-22 19:59:07 +08:00
2025-08-01 00:28:32 +08:00
# File operations
2025-07-22 19:59:07 +08:00
> Convert all images in this directory to PNG format
2025-08-01 00:28:32 +08:00
> Rename all test files to follow the *.test.ts pattern
> Find and remove all console.log statements
```
### 🐛 Debugging & Analysis
```bash
# Performance analysis
> Identify performance bottlenecks in this React component
> Find all N+1 query problems in the codebase
# Security audit
> Check for potential SQL injection vulnerabilities
> Find all hardcoded credentials or API keys
2025-07-22 19:59:07 +08:00
```
## Popular Tasks
2025-08-01 00:28:32 +08:00
### 📚 Understand New Codebases
2025-07-22 19:59:07 +08:00
```text
> What are the core business logic components?
> What security mechanisms are in place?
2025-08-01 00:28:32 +08:00
> How does the data flow through the system?
> What are the main design patterns used?
> Generate a dependency graph for this module
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
### 🔨 Code Refactoring & Optimization
2025-07-22 19:59:07 +08:00
```text
> What parts of this module can be optimized?
2025-08-01 00:28:32 +08:00
> Help me refactor this class to follow SOLID principles
2025-07-22 19:59:07 +08:00
> Add proper error handling and logging
2025-08-01 00:28:32 +08:00
> Convert callbacks to async/await pattern
> Implement caching for expensive operations
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
### 📝 Documentation & Testing
2025-07-22 19:59:07 +08:00
```text
2025-08-01 00:28:32 +08:00
> Generate comprehensive JSDoc comments for all public APIs
> Write unit tests with edge cases for this component
> Create API documentation in OpenAPI format
> Add inline comments explaining complex algorithms
> Generate a README for this module
2025-07-22 19:59:07 +08:00
```
2025-08-01 00:28:32 +08:00
### 🚀 Development Acceleration
```text
> Set up a new Express server with authentication
> Create a React component with TypeScript and tests
> Implement a rate limiter middleware
> Add database migrations for new schema
> Configure CI/CD pipeline for this project
```
## Commands & Shortcuts
### Session Commands
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
- `/help` - Display available commands
- `/clear` - Clear conversation history
- `/compress` - Compress history to save tokens
- `/status` - Show current session information
- `/exit` or `/quit` - Exit Qwen Code
### Keyboard Shortcuts
2025-08-01 00:31:34 +08:00
2025-08-01 00:28:32 +08:00
- `Ctrl+C` - Cancel current operation
- `Ctrl+D` - Exit (on empty line)
- `Up/Down` - Navigate command history
2025-07-22 09:57:08 -07:00
## Benchmark Results
2025-08-01 00:28:32 +08:00
### Terminal-Bench Performance
2025-07-22 09:57:08 -07:00
| Agent | Model | Accuracy |
2025-07-23 16:18:31 +08:00
| --------- | ------------------ | -------- |
2025-08-01 00:28:32 +08:00
| Qwen Code | Qwen3-Coder-480A35 | 37.5% |
| Qwen Code | Qwen3-Coder-30BA3B | 31.3% |
2025-07-22 19:59:07 +08:00
## Development & Contributing
See [CONTRIBUTING.md ](./CONTRIBUTING.md ) to learn how to contribute to the project.
2025-08-08 09:48:31 +08:00
For detailed authentication setup, see the [authentication guide ](./docs/cli/authentication.md ).
2025-07-22 19:59:07 +08:00
## Troubleshooting
If you encounter issues, check the [troubleshooting guide ](docs/troubleshooting.md ).
## Acknowledgments
This project is based on [Google Gemini CLI ](https://github.com/google-gemini/gemini-cli ). We acknowledge and appreciate the excellent work of the Gemini CLI team. Our main contribution focuses on parser-level adaptations to better support Qwen-Coder models.
## License
[LICENSE ](./LICENSE )
2025-07-25 00:11:47 +08:00
## Star History
[](https://www.star-history.com/#QwenLM/qwen -code& Date)