QwenLM/qwen-code

GitHub: QwenLM/qwen-code

一款在终端中运行的开源 AI 编程 Agent,帮助开发者理解代码库、自动化编码任务并加速发布流程。

Stars: 25236 | Forks: 2510

[![npm 版本](https://img.shields.io/npm/v/@qwen-code/qwen-code.svg)](https://www.npmjs.com/package/@qwen-code/qwen-code) [![许可证](https://img.shields.io/github/license/QwenLM/qwen-code.svg)](./LICENSE) [![Node.js 版本](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg)](https://nodejs.org/) [![下载量](https://img.shields.io/npm/dm/@qwen-code/qwen-code.svg)](https://www.npmjs.com/package/@qwen-code/qwen-code) QwenLM%2Fqwen-code | Trendshift **一个在终端中运行的开源 AI agent。** 中文 | Deutsch | français | 日本語 | Русский | Português (Brasil)
## 🎉 新闻 - **2026-04-15**: Qwen OAuth 免费额度已停止。要继续使用 Qwen Code,请切换至[阿里云 Coding Plan](https://modelstudio.console.alibabacloud.com/?tab=coding-plan#/efm/coding-plan-index)、[OpenRouter](https://openrouter.ai)、[Fireworks AI](https://app.fireworks.ai),或自带 API key。运行 `qwen auth` 进行配置。 - **2026-04-13**: Qwen OAuth 免费额度政策更新:每日配额调整为 100 次请求/天(原为 1,000 次)。 - **2026-04-02**: Qwen3.6-Plus 现已上线!从[阿里云 ModelStudio](https://modelstudio.console.alibabacloud.com/ap-southeast-1?tab=doc#/doc/?type=model&url=2840914_2&modelId=qwen3.6-plus) 获取 API key,通过兼容 OpenAI 的 API 进行访问。 - **2026-02-16**: Qwen3.5-Plus 现已上线! ## 为什么选择 Qwen Code? Qwen Code 是一款针对终端的开源 AI agent,专为 Qwen 系列模型优化。它可以帮助你理解庞大的代码库、自动化繁琐的工作,并加快发布速度。 - **多协议,灵活的 provider**:使用 OpenAI / Anthropic / Gemini 兼容的 API、[阿里云 Coding Plan](https://modelstudio.console.alibabacloud.com/?tab=coding-plan#/efm/coding-plan-index)、[OpenRouter](https://openrouter.ai)、[Fireworks AI](https://app.fireworks.ai),或自带 API key。 - **开源,共同演进**:框架和 Qwen3-Coder 模型均为开源——并且它们会同步发布和演进。 - **Agentic workflow,功能丰富**:丰富的内置工具(Skills, SubAgents),提供完整的 Agentic workflow 以及类似 Claude Code 的体验。 - **终端优先,IDE 友好**:专为常驻命令行的开发者打造,支持与 VS Code、Zed 和 JetBrains IDE 的可选集成。 ![](https://gw.alicdn.com/imgextra/i1/O1CN01D2DviS1wwtEtMwIzJ_!!6000000006373-2-tps-1600-900.png) ## 安装 ### 快速安装(推荐) #### Linux / macOS ``` curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.sh | bash ``` #### Windows ``` irm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iex ``` ### 手动安装 #### 前置条件 请确保你已安装 Node.js 22 或更高版本。可从 [nodejs.org](https://nodejs.org/en/download) 下载。 #### NPM ``` npm install -g @qwen-code/qwen-code@latest ``` #### Homebrew (macOS, Linux) ``` brew install qwen-code ``` ## 快速开始 ``` # 启动 Qwen Code(交互式) qwen # 然后,在会话中: /help /auth ``` 首次使用时,系统会提示你登录。你可以随时运行 `/auth` 来切换认证方式。 提示词示例: ``` What does this project do? Explain the codebase structure. Help me refactor this function. Generate unit tests for this module. ```
点击观看演示视频
## 🦞 在 Claw 中使用 Qwen Code 处理编码任务 复制下方的提示词并粘贴到你的 agent 中: ``` Use Qwen Code as a coding agent. First, fetch and read this skill reference: https://raw.githubusercontent.com/QwenLM/qwen-code/refs/heads/main/.qwen/skills/qwen-code-claw/SKILL.md Then follow the instructions inside to install, authenticate, and use Qwen Code via acpx for all coding tasks. ``` ## 认证 Qwen Code 支持以下认证方式: - **API Key(推荐)**:使用来自阿里云 Model Studio([北京](https://bailian.console.aliyun.com/) / [国际](https://modelstudio.console.alibabacloud.com/))或任何受支持 provider(OpenAI、Anthropic、Google GenAI 及其他兼容 endpoint)的 API key。 - **Coding Plan**:订阅阿里云 Coding Plan([北京](https://bailian.console.aliyun.com/cn-beijing?tab=coding-plan#/efm/coding-plan-index) / [国际](https://modelstudio.console.alibabacloud.com/?tab=coding-plan#/efm/coding-plan-index)),以固定月费享受更高的配额。 #### API Key(推荐) 使用 API key 连接到阿里云 Model Studio 或任何受支持的 provider。支持多种协议: - **兼容 OpenAI**:阿里云 ModelStudio、ModelScope、OpenAI、OpenRouter 及其他兼容 OpenAI 的 provider - **Anthropic**:Claude 模型 - **Google GenAI**:Gemini 模型 配置模型和 provider 的**推荐**方式是编辑 `~/.qwen/settings.json`(如果不存在则创建)。此文件允许你在一个地方定义所有可用的模型、API key 和默认设置。 ##### 3 步快速设置 **第 1 步:** 创建或编辑 `~/.qwen/settings.json` 这是一个完整的示例: ``` { "modelProviders": { "openai": [ { "id": "qwen3.6-plus", "name": "qwen3.6-plus", "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1", "description": "Qwen3-Coder via Dashscope", "envKey": "DASHSCOPE_API_KEY" } ] }, "env": { "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx" }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "qwen3.6-plus" } } ``` **第 2 步:** 了解每个字段 | 字段 | 用途 | | ---------------------------- | ----------------------------------------------------------------------------------------------------------------- | | `modelProviders` | 声明哪些模型可用以及如何连接它们。`openai`、`anthropic`、`gemini` 等 key 代表 API 协议。 | | `modelProviders[].id` | 发送到 API 的模型 ID(例如 `qwen3.6-plus`、`gpt-4o`)。 | | `modelProviders[].envKey` | 保存你 API key 的环境变量名称。 | | `modelProviders[].baseUrl` | API endpoint URL(非默认 endpoint 必填)。 | | `env` | 存储 API key 的备用位置(优先级最低;对于敏感 key,建议使用 `.env` 文件或 `export`)。 | | `security.auth.selectedType` | 启动时使用的协议(`openai`、`anthropic`、`gemini`、`vertex-ai`)。 | | `model.name` | Qwen Code 启动时默认使用的模型。 | **第 3 步:** 启动 Qwen Code — 你的配置将自动生效: ``` qwen ``` 随时使用 `/model` 命令在所有已配置的模型之间切换。 ##### 更多示例
Coding Plan(阿里云 ModelStudio) — 固定月费,更高配额 ``` { "modelProviders": { "openai": [ { "id": "qwen3.6-plus", "name": "qwen3.6-plus (Coding Plan)", "baseUrl": "https://coding.dashscope.aliyuncs.com/v1", "description": "qwen3.6-plus from ModelStudio Coding Plan", "envKey": "BAILIAN_CODING_PLAN_API_KEY" }, { "id": "qwen3.5-plus", "name": "qwen3.5-plus (Coding Plan)", "baseUrl": "https://coding.dashscope.aliyuncs.com/v1", "description": "qwen3.5-plus with thinking enabled from ModelStudio Coding Plan", "envKey": "BAILIAN_CODING_PLAN_API_KEY", "generationConfig": { "extra_body": { "enable_thinking": true } } }, { "id": "glm-4.7", "name": "glm-4.7 (Coding Plan)", "baseUrl": "https://coding.dashscope.aliyuncs.com/v1", "description": "glm-4.7 with thinking enabled from ModelStudio Coding Plan", "envKey": "BAILIAN_CODING_PLAN_API_KEY", "generationConfig": { "extra_body": { "enable_thinking": true } } }, { "id": "kimi-k2.5", "name": "kimi-k2.5 (Coding Plan)", "baseUrl": "https://coding.dashscope.aliyuncs.com/v1", "description": "kimi-k2.5 with thinking enabled from ModelStudio Coding Plan", "envKey": "BAILIAN_CODING_PLAN_API_KEY", "generationConfig": { "extra_body": { "enable_thinking": true } } } ] }, "env": { "BAILIAN_CODING_PLAN_API_KEY": "sk-xxxxxxxxxxxxx" }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "qwen3.6-plus" } } ```
多个 provider(OpenAI + Anthropic + Gemini) ``` { "modelProviders": { "openai": [ { "id": "gpt-4o", "name": "GPT-4o", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.openai.com/v1" } ], "anthropic": [ { "id": "claude-sonnet-4-20250514", "name": "Claude Sonnet 4", "envKey": "ANTHROPIC_API_KEY" } ], "gemini": [ { "id": "gemini-2.5-pro", "name": "Gemini 2.5 Pro", "envKey": "GEMINI_API_KEY" } ] }, "env": { "OPENAI_API_KEY": "sk-xxxxxxxxxxxxx", "ANTHROPIC_API_KEY": "sk-ant-xxxxxxxxxxxxx", "GEMINI_API_KEY": "AIzaxxxxxxxxxxxxx" }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "gpt-4o" } } ```
开启 thinking 模式(适用于支持 thinking 的模型,如 qwen3.5-plus) ``` { "modelProviders": { "openai": [ { "id": "qwen3.5-plus", "name": "qwen3.5-plus (thinking)", "envKey": "DASHSCOPE_API_KEY", "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1", "generationConfig": { "extra_body": { "enable_thinking": true } } } ] }, "env": { "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx" }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "qwen3.5-plus" } } ```
#### 本地模型设置(Ollama / vLLM) 你也可以在本地运行模型 — 无需 API key 或云账号。这不是一种认证方式;相反,请在 `~/.qwen/settings.json` 中使用 `modelProviders` 字段配置你的本地模型 endpoint。 在匹配的 provider 条目中设置 `generationConfig.contextWindowSize` 并将其调整为你本地服务器上配置的上下文长度。
Ollama 设置 1. 从 [ollama.com](https://ollama.com/) 安装 Ollama 2. 拉取模型:`ollama pull qwen3:32b` 3. 配置 `~/.qwen/settings.json`: ``` { "modelProviders": { "openai": [ { "id": "qwen3:32b", "name": "Qwen3 32B (Ollama)", "baseUrl": "http://localhost:11434/v1", "description": "Qwen3 32B running locally via Ollama", "generationConfig": { "contextWindowSize": 131072 } } ] }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "qwen3:32b" } } ```
vLLM 设置 1. 安装 vLLM:`pip install vllm` 2. 启动服务器:`vllm serve Qwen/Qwen3-32B` 3. 配置 `~/.qwen/settings.json`: ``` { "modelProviders": { "openai": [ { "id": "Qwen/Qwen3-32B", "name": "Qwen3 32B (vLLM)", "baseUrl": "http://localhost:8000/v1", "description": "Qwen3 32B running locally via vLLM", "generationConfig": { "contextWindowSize": 131072 } } ] }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "Qwen/Qwen3-32B" } } ```
## 用法 作为一个开源终端 agent,你可以通过五种主要方式使用 Qwen Code: 1. 交互模式(终端 UI) 2. Headless 模式(脚本、CI) 3. IDE 集成(VS Code、Zed) 4. SDK(TypeScript、Python、Java) 5. Daemon 模式 — `qwen serve` 通过 HTTP+SSE 暴露 ACP,允许多个客户端共享同一个 agent(实验性) #### 交互模式 ``` cd your-project/ qwen ``` 在你的项目文件夹中运行 `qwen` 以启动交互式终端 UI。使用 `@` 引用本地文件(例如 `@src/main.ts`)。 #### Headless 模式 ``` cd your-project/ qwen -p "your question" ``` 使用 `-p` 运行 Qwen Code 而无需交互式 UI — 非常适合脚本、自动化和 CI/CD。了解更多:[Headless 模式](https://qwenlm.github.io/qwen-code-docs/en/users/features/headless)。 #### IDE 集成 在你的编辑器(VS Code、Zed 和 JetBrains IDE)中使用 Qwen Code: - [在 VS Code 中使用](https://qwenlm.github.io/qwen-code-docs/en/users/integration-vscode/) - [在 Zed 中使用](https://qwenlm.github.io/qwen-code-docs/en/users/integration-zed/) - [在 JetBrains IDE 中使用](https://qwenlm.github.io/qwen-code-docs/en/users/integration-jetbrains/) #### Daemon 模式(`qwen serve`,实验性) ``` cd your-project/ qwen serve # → qwen serve listening on http://127.0.0.1:4170 (mode=http-bridge) ``` 将 Qwen Code 作为本地 HTTP daemon 运行,以便 IDE 插件、Web UI、CI 脚本和自定义 CLI 都可以通过 HTTP+SSE 共享**一个** agent 会话 — 而不是各自生成自己的子进程。环回绑定默认没有身份验证(设置 `QWEN_SERVER_TOKEN` 以即使在环回上也启用 bearer auth);远程绑定(`--hostname 0.0.0.0`)**必须**提供 token — 否则启动将被拒绝。请参阅: - [Daemon 模式用户指南](https://qwenlm.github.io/qwen-code-docs/en/users/qwen-serve) - [HTTP 协议参考](https://qwenlm.github.io/qwen-code-docs/en/developers/qwen-serve-protocol) - [DaemonClient TypeScript 快速入门](https://qwenlm.github.io/qwen-code-docs/en/developers/examples/daemon-client-quickstart) #### SDK 使用可用的 SDK 在 Qwen Code 的基础上进行开发: - TypeScript:[使用 Qwen Code SDK](./packages/sdk-typescript/README.md) - Python:[使用 Python SDK](./packages/sdk-python/README.md) - Java:[使用 Java SDK](./packages/sdk-java/qwencode/README.md) Python SDK 示例: ``` import asyncio from qwen_code_sdk import is_sdk_result_message, query async def main() -> None: result = query( "Summarize the repository layout.", { "cwd": "/path/to/project", "path_to_qwen_executable": "qwen", }, ) async for message in result: if is_sdk_result_message(message): print(message["result"]) asyncio.run(main()) ``` ## 命令与快捷键 ### 会话命令 - `/help` - 显示可用命令 - `/clear` - 清除对话历史 - `/compress` - 压缩历史记录以节省 token - `/stats` - 显示当前会话信息 - `/bug` - 提交 bug 报告 - `/exit` 或 `/quit` - 退出 Qwen Code ### 键盘快捷键 - `Ctrl+C` - 取消当前操作 - `Ctrl+D` - 退出(在空行时) - `Up/Down` - 浏览命令历史 ## 配置 Qwen Code 可以通过 `settings.json`、环境变量和 CLI 标志进行配置。 | 文件 | 范围 | 描述 | | ----------------------- | ----------- | ------------------------------------------------------------------------------- | | `~/.qwen/settings.json` | 用户(全局)| 适用于你所有的 Qwen Code 会话。**推荐用于 `modelProviders` 和 `env`。** | | `.qwen/settings.json` | 项目 | 仅在当前项目中运行 Qwen Code 时生效。覆盖用户设置。 | `settings.json` 中最常用的顶级字段: | 字段 | 描述 | | ---------------------------- | -------------------------------------------------------------------------------------------------- | | `modelProviders` | 定义每个协议(`openai`、`anthropic`、`gemini`、`vertex-ai`)可用的模型。 | | `env` | 备用环境变量(例如 API key)。优先级低于 shell `export` 和 `.env` 文件。 | | `security.auth.selectedType` | 启动时使用的协议(例如 `openai`)。 | | `model.name` | Qwen Code 启动时默认使用的模型。 | ## 基准测试结果 ### Terminal-Bench 性能 | Agent | Model | Accuracy | | --------- | ------------------ | -------- | | Qwen Code | Qwen3-Coder-480A35 | 37.5% | | Qwen Code | Qwen3-Coder-30BA3B | 31.3% | ## 生态系统 正在寻找图形界面? - [AionUi**](https://github.com/iOfficeAI/AionUi) 命令行 AI 工具(包括 Qwen Code)的现代 GUI - [**Gemini CLI Desktop**](https://github.com/Piebald-AI/gemini-cli-desktop) 适用于 Qwen Code 的跨平台桌面/网页/移动端 UI ## 故障排除 如果遇到问题,请查看[故障排除指南](https://qwenlm.github.io/qwen-code-docs/en/users/support/troubleshooting/)。 **常见问题:** - **`Qwen OAuth free tier was discontinued on 2026-04-15`**:Qwen OAuth 已不再可用。运行 `qwen` → `/auth` 并切换到 API Key 或 Coding Plan。有关设置说明,请参阅上方的[认证](#authentication)部分。 要在 CLI 中报告 bug,请运行 `/bug` 并附上简短标题和复现步骤。 ## 联系我们 - Discord: https://discord.gg/RN7tqZCeDK - 钉钉: https://qr.dingtalk.com/action/joingroup?code=v1,k1,+FX6Gf/ZDlTahTIRi8AEQhIaBlqykA0j+eBKKdhLeAE=&_dt_no_comment=1&origin=1 ## 致谢 本项目基于 [Google Gemini CLI](https://github.com/google-gemini/gemini-cli)。我们感谢 Gemini CLI 团队的杰出工作。我们的主要贡献集中在 parser 级别的适配上,以更好地支持 Qwen-Coder 模型。
标签:AI编程助手, DLL 劫持, GNU通用公共许可证, MITM代理, Node.js, SOC Prime, 大语言模型, 开发工具, 暗色界面, 自动化攻击, 通义千问