Qwen Code CLI - Install, Slash Commands & MCP

Qwen Code is Alibaba Qwen open-source AI coding CLI (Claude Code-like, built on Qwen3-Max / Qwen3-Coder), for developers using Tongyi/Qwen models who want terminal-based AI coding, especially those already on Alibaba Cloud DashScope. Usage resembles Claude Code but with different models and pricing, connecting via DASHSCOPE_API_KEY. This sheet covers launch, print mode, slash commands, and MCP.

AI CLI·25 commands·Last updated 2026-08-21
qwen-codeqwenaicliagentQwen

Install & Auth 5

npm install -g @qwen-code/qwen-code
Install globally via npm
qwen --version
Print the version
export DASHSCOPE_API_KEY="sk-..."
Set the Tongyi API key
qwen auth login
Interactive sign-in (if supported)
qwen auth status
Show auth status

Launch & Run 5

qwen
Start an interactive REPL in the cwd
qwen "Refactor the user module"
Start with an initial prompt
qwen -p "Explain this function"
Print mode: run then exit
qwen -c
Continue the most recent session (--continue)
qwen -m qwen3-max "task"
Run with a specified model

Slash Commands 5

/init
Generate project config (QWEN.md)
/clear
Clear conversation history
/compact
Summarize to free context
/model
Switch the active model
/exit
Quit the REPL

MCP & Extensions 5

qwen mcp add <name> <url>
Add an MCP server
qwen mcp list
List configured MCP servers
qwen mcp remove <name>
Remove an MCP server
qwen mcp get <name>
Show server config
@./src/utils.ts
Reference a file with @ in the prompt

Chinese-Context Tips 5

qwen -p "Explain the architecture in Chinese"
Use Chinese prompts directly
Put conventions in QWEN.md
Build/test commands auto-load from QWEN.md
qwen -p --output-format json
JSON output for scripting
Continue with -c
Resume context with -c
qwen --permission-mode plan
Read-only plan mode

Tips

  • Qwen Code is a domestic vendor CLI; its Chinese context and Qwen3-Coder coding strength make it a necessary pick for the "Chinese AI cheatsheet" track.
  • Put build/test conventions in QWEN.md — auto-loaded each session, more stable than repeating prompts.
  • Print mode -p --output-format json drops into CI/scripts just like Claude Code, low migration cost.
  • The CLI asks before exiting the sandbox for network (e.g. npm install); for pure-local inference use Qwen open weights via Ollama.

FAQ

What should go into QWEN.md?

Project conventions and commands, auto-loaded each session so it stops guessing: how to build, how to run tests, code style rules, directories to avoid. The highest-value entry is how to verify a change — otherwise it may claim success without running tests. Keep it short; long documents dilute attention rather than help.

Is it better to prompt in Chinese for Chinese tasks?

Usually. Prompting in Chinese and getting Chinese back removes a translation round-trip and keeps terminology stable. Switch to explicitly requesting English when you need English docs or code comments, and give an example of the style you want — for example "for an English audience, technical writing style" — rather than relying on the default.

How do I attach an MCP server to Qwen Code?

Add one with qwen mcp add <name> <url>, list with qwen mcp list, inspect with qwen mcp get <name> and remove with qwen mcp remove <name>. MCP grants access to external tools and data sources. In prompts, @./src/utils.ts references a specific file precisely, avoiding a full repository scan.

How do I make Qwen Code emit JSON for scripts?

Use qwen -p --output-format json to get structured output that a downstream program can consume directly. Continue prior context with -c instead of restating the background. For planning tasks add --permission-mode plan to stay read-only.

Which slash commands are worth knowing in Qwen Code?

/init generates a QWEN.md config in the project root — put build and test commands there and they load automatically. /clear wipes conversation history, which is right when switching tasks. /compact summarizes the conversation to free context in long sessions. /model switches the active model and /exit leaves the REPL.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Aug 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us