BuildBotsBetter
QWN

Set Up Qwen Code

Installation, Authentication, Standalone Execution, Approval Modes, and Everyday Automation (Ollama Not Required)

0% (0/14)
Cross-Platform Compatibility: Qwen Code operates identically across Windows (PowerShell), macOS (zsh), and Linux (bash). On macOS/Linux, install via npm install -g @qwen-code/qwen-code, use export DASHSCOPE_API_KEY="..." instead of $env:, and run python3 instead of python.
Lesson 1 · Step 1

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.

PowerShell
node --version
npm --version
✓ Checkpoint 1: Node.js Runtime Check

Verify that Node.js outputs a version of v18.0.0 or newer, and npm outputs 9.0.0 or newer.

Lesson 1 · Step 2

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.

PowerShell
Get-ExecutionPolicy -List
npm config get prefix

If CurrentUser is Restricted, configure it to RemoteSigned:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force
Lesson 2 · Step 3

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.

PowerShell
npm install -g @qwen-code/qwen-code

Notice: Ollama is never touched, downloaded, or invoked during this process. Qwen Code is completely standalone!

Lesson 2 · Step 4

Verify qwen Binary and Location

Confirm that the qwen binary resolves correctly in your terminal shell.

PowerShell
qwen --version
where.exe qwen
✓ Checkpoint 2: CLI Binary Verification

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.

Lesson 3 · Step 5

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:

PowerShell
$env:DASHSCOPE_API_KEY = "sk-your-dashscope-key"

Alternatively, launch qwen in interactive mode to complete standard browser OAuth authentication.

Lesson 3 · Step 6

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):

PowerShell
$env:OPENAI_API_KEY = "your-api-key"
$env:OPENAI_BASE_URL = "https://api.openai.com/v1"
$env:OPENAI_MODEL = "gpt-4o"
Lesson 3 · Step 7

Inspect Help & Provider Flags

Verify available backend options and CLI features.

PowerShell
qwen --help
✓ Checkpoint 3: CLI Flags & Capabilities

Confirm that qwen --help lists parameters for --approval-mode, --auth-type, --output-format, and --include-directories.

Lesson 4 · Step 8

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:

PowerShell
qwen

Useful interactive commands: /help, /clear, /model, /bye.

Lesson 4 · Step 9

Headless Scripting & STDIN Piping

Automate tasks non-interactively using prompt arguments and standard input pipes.

Execute single-shot prompts without launching the interactive UI:

PowerShell
qwen -p "Explain the contents of package.json in one concise paragraph"

Pipe error logs or command output directly into Qwen Code:

PowerShell
git status | qwen -p "Suggest a commit message for these changes"
Lesson 4 · Step 10

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
Lesson 5 · Step 11

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:

Terminal Command
# Windows PowerShell:
qwen --include-directories "$HOME\projects\shared_lib"

# macOS / Linux:
qwen --include-directories "$HOME/projects/shared_lib"
Lesson 5 · Step 12

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:

JSON Config (.qwen/settings.json)
{
  "mcpServers": {
    "sql-explorer": {
      "command": "python",
      "args": ["-m", "mcp_server_sql", "--db", "BOTS"]
    }
  }
}
Lesson 6 · Step 13

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:

Terminal Command
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.

✓ Checkpoint 4: Automated Task Verification

Confirm that Qwen Code generated the files and they pass tests when executed with python -m unittest.

Lesson 6 · Step 14

Everyday "Run It Later" Workflows

Permanent terminal commands and shortcuts for daily productive use.

PowerShell Cheatsheet
# 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
✓ Checkpoint 5: Complete Setup Certified

Confirm that Qwen Code is ready for daily development and autonomous fleet tasks without requiring Ollama.