Skip to main content

Introduction

Qwen Code is an AI-powered coding assistant that runs directly in your terminal. The CLI supports both interactive and headless modes, making it suitable for development workflows, automation, and CI/CD pipelines.

Basic Usage

Interactive Mode

Launch Qwen Code in interactive mode for a conversational coding experience:
qwen
This opens an interactive terminal interface where you can chat with the AI, execute commands, and work on your code.

Headless Mode

Use the --prompt flag to run Qwen Code in non-interactive mode:
qwen --prompt "Create a Python function to calculate fibonacci numbers"
You can also pipe input from stdin:
echo "Explain this code" | qwen --prompt

Positional Arguments

Provide a prompt as positional arguments for one-shot execution:
qwen "Write unit tests for my authentication module"
Use --prompt-interactive to execute a prompt and continue in interactive mode:
qwen --prompt-interactive "Setup a React project with TypeScript"

Available Commands

Qwen Code provides slash commands that you can use within interactive mode or with the --prompt flag:

/auth

Configure authentication settings

/help

Display help information

/clear

Clear conversation history

/compress

Compress conversation context

/model

Switch the active model

/stats

View session statistics

/bug

Submit a bug report

Command-Line Options

Configure Qwen Code behavior with command-line flags:

--prompt

Execute a prompt in non-interactive mode

--model

Specify the AI model to use

--yolo

Auto-approve all actions

--plan

Plan-only mode without execution

--resume

Resume a previous session

--session-id

Specify a custom session ID

Output Formats

Qwen Code supports multiple output formats for different use cases:

Text Format (Default)

Human-readable output suitable for terminal usage:
qwen --prompt "Hello"

JSON Format

Structured output for programmatic consumption:
qwen --prompt "Analyze this code" --output-format json

Stream JSON Format

Real-time streaming output with JSON events:
qwen --prompt "Generate a report" --output-format stream-json

Input Formats

Control how Qwen Code processes input:
  • text: Standard text input (default)
  • stream-json: JSON-formatted streaming input for programmatic control
qwen --input-format stream-json

Session Management

Starting a New Session

Each invocation creates a new session by default:
qwen

Resuming Sessions

Resume the most recent session:
qwen --continue
Resume a specific session by ID:
qwen --resume <session-id>
Show session picker:
qwen --resume

Custom Session ID

Specify a custom session ID:
qwen --session-id my-custom-session

Approval Modes

Control how Qwen Code handles tool execution:
  • default: Prompt for approval before executing tools
  • yolo: Auto-approve all tool executions
  • plan: Generate plans without executing
  • auto-edit: Auto-approve edit operations only
qwen --approval-mode yolo

Examples

Code Generation

qwen --prompt "Create a REST API with Express.js"

Code Review

git diff | qwen --prompt "Review these changes"

Automated Testing

qwen --yolo --prompt "Add unit tests to all functions in src/"

CI/CD Integration

qwen --prompt "Run linter and fix all issues" --output-format json

Environment Variables

Configure Qwen Code using environment variables:
  • QWEN_CODE_NO_RELAUNCH: Disable automatic memory reconfiguration
  • NO_COLOR: Disable colored output
  • DEBUG: Enable debug logging
  • SANDBOX: Indicates running inside sandbox

Configuration Files

Qwen Code reads configuration from:
  • Global settings: ~/.qwen/settings.json
  • Project settings: .qwen/settings.json
  • Project config: .qwen.config.js
See the Configuration guide for details.

Getting Help

View all available options:
qwen --help
Access help within interactive mode:
/help
Submit bug reports:
/bug "Description of the issue"

Next Steps

Authentication

Set up API keys and OAuth

Configuration

Customize Qwen Code settings

Features

Explore powerful features

IDE Integration

Use Qwen Code in your editor