npm install -g @qwen-code/qwen-code, use export DASHSCOPE_API_KEY="..." instead of $env:, and run python3 instead of python.
Verify Node.js and npm Prerequisites
Confirm that Node.js 18+ and npm are properly installed and accessible in your system PATH.
Qwen Code is an autonomous AI coding agent CLI published on npm as @qwen-code/qwen-code. Unlike local weight runners, it does not require gigabytes of neural weights or Ollama installed. It requires Node.js v18.0.0 or higher.
node --version
npm --version
Verify that Node.js outputs a version of v18.0.0 or newer, and npm outputs 9.0.0 or newer.
Inspect Shell Execution Policy & npm PATH
Ensure PowerShell permits script execution and the global npm bin folder is in your environment PATH.
On Windows, npm installs global CLI commands into %APPDATA%\npm. If your PowerShell execution policy is restricted, running global scripts can throw an authorization error.
Get-ExecutionPolicy -List
npm config get prefix
If CurrentUser is Restricted, configure it to RemoteSigned:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force
Install Qwen Code CLI Globally
Install the official @qwen-code/qwen-code package using npm.
Run npm install globally. This installs the CLI binaries qwen and qwen.cmd into your global npm path.
npm install -g @qwen-code/qwen-code
Notice: Ollama is never touched, downloaded, or invoked during this process. Qwen Code is completely standalone!
Verify qwen Binary and Location
Confirm that the qwen binary resolves correctly in your terminal shell.
qwen --version
where.exe qwen
Confirm that qwen --version returns the active package version (e.g. @qwen-code/qwen-code@0.24.4) and where.exe qwen returns %APPDATA%\npm\qwen.cmd.
Qwen Cloud & OAuth Sign-In
Authenticate with Qwen's cloud infrastructure or configure Alibaba DashScope API credentials.
Qwen Code connects to Qwen's official models in the cloud via browser OAuth or API keys. If you have a DashScope / Alibaba Cloud account, set your API key:
$env:DASHSCOPE_API_KEY = "sk-your-dashscope-key"
Alternatively, launch qwen in interactive mode to complete standard browser OAuth authentication.
Custom OpenAI-Compatible Provider Keys
Configure Qwen Code to connect to any OpenAI-compatible API gateway.
Qwen Code features built-in support for any OpenAI-compatible REST endpoint (including OpenAI, OpenRouter, vLLM, or private enterprise gateways):
$env:OPENAI_API_KEY = "your-api-key"
$env:OPENAI_BASE_URL = "https://api.openai.com/v1"
$env:OPENAI_MODEL = "gpt-4o"
Inspect Help & Provider Flags
Verify available backend options and CLI features.
qwen --help
Confirm that qwen --help lists parameters for --approval-mode, --auth-type, --output-format, and --include-directories.
Interactive Terminal TUI Session
Launch Qwen Code in interactive terminal mode.
Running bare qwen in your project folder opens the rich interactive interface with conversational memory, syntax highlighting, and inline diff viewing:
qwen
Useful interactive commands: /help, /clear, /model, /bye.
Headless Scripting & STDIN Piping
Automate tasks non-interactively using prompt arguments and standard input pipes.
Execute single-shot prompts without launching the interactive UI:
qwen -p "Explain the contents of package.json in one concise paragraph"
Pipe error logs or command output directly into Qwen Code:
git status | qwen -p "Suggest a commit message for these changes"
Approval Modes: Plan vs Default vs YOLO
Master execution safety levels to balance speed and system protection.
| Mode | File Edits | Shell Commands | Ideal Use Case |
|---|---|---|---|
| plan | Disabled | Disabled | Codebase audits, architectural reviews, risk-free analysis |
| default | Prompt | Prompt | Everyday pair-programming with human in the loop |
| auto-edit | Auto | Prompt | Rapid refactoring where shell commands need vetting |
| yolo (-y) | Auto | Auto | Fully automated CI/CD pipelines, disposable sandboxes |
Multi-Directory Workspace Configuration
Grant Qwen Code read and write access across multiple independent project trees.
By default, Qwen Code operates within your current working directory. Use --include-directories to include shared libraries, docs, or sibling folders:
# Windows PowerShell:
qwen --include-directories "$HOME\projects\shared_lib"
# macOS / Linux:
qwen --include-directories "$HOME/projects/shared_lib"
Model Context Protocol (MCP) Integration
Extend Qwen Code with custom MCP tool servers for databases, APIs, and specialized services.
Connect MCP servers via --mcp-config or within .qwen/settings.json:
{
"mcpServers": {
"sql-explorer": {
"command": "python",
"args": ["-m", "mcp_server_sql", "--db", "BOTS"]
}
}
}
Execute & Verify First Coding Task
Run an end-to-end task to verify code generation, test creation, and execution.
Run a prompt task to build a small utility and its test suite. By default, execute without the -y flag so you review file diffs before accepting:
qwen -p "Create math_utils.py with a gcd function and test_math.py with unit tests"
Safety Note: Append -y only in automated CI/CD pipelines or isolated sandboxes. In day-to-day workspaces, omit -y so you can confirm diffs interactively.
Confirm that Qwen Code generated the files and they pass tests when executed with python -m unittest.
Everyday "Run It Later" Workflows
Permanent terminal commands and shortcuts for daily productive use.
# Interactive Session
qwen
# Headless Prompt
qwen -p "Fix the failing test in test_db.py"
# Resume Prior Session
qwen --continue
# Review Mode (No writes)
qwen --approval-mode plan
Confirm that Qwen Code is ready for daily development and autonomous fleet tasks without requiring Ollama.