Course
Alibaba released Qwen3-Coder, an agentic coding model available in multiple sizes, with the strongest variant being Qwen3-Coder-480B-A35B-Instruct. Alongside these models, Alibaba open-sourced Qwen Code CLI, a command-line tool for agentic coding.
Qwen Code CLI is forked from Gemini CLI and has been adapted specifically for use with the Qwen3-Coder model on agentic coding tasks.
In this blog, I’ll explain step by step how to set up and use Qwen Code CLI. We’ll use it to explore codebases, perform code refactoring, and more.
We keep our readers updated on the latest in AI by sending out The Median, our free Friday newsletter that breaks down the week’s key stories. Subscribe and stay sharp in just a few minutes a week:
What Is Qwen Code?
Qwen Code is a command-line interface designed to facilitate agentic coding tasks. It uses customized prompts and function-calling protocols optimized for Qwen3-Coder. With Qwen Code, you can:
- Navigate and understand complex codebases
- Detect and fix coding issues
- Generate code and unit tests
- Create documentation and flowcharts

Source: QwenLM
Now, let’s set up Qwen3-Coder and use it to explore and fix issues for an open-source project that I worked on recently.
Step 1: Prerequisites
Before setting up Qwen Code, ensure you have Node.js (version 20 or higher) installed. You can install Node.js by running:
curl -qL https://www.npmjs.com/install.sh | sh
Then, verify your installation by running the following:
node -v
npm -v
Step 2: Setting Up Qwen Code
In this step, we’ll look into multiple options for installing and authenticating Qwen Code on our device.
Step 2.1: Installation via npm
With Node.js installed, set up Qwen Code globally and check the installation version as well:
npm install -g @qwen-code/qwen-code
qwen --version

This code installs the Qwen Code CLI globally using Node.js's package manager. After installation, the qwen --version command checks and displays the installed version of the Qwen CLI to verify that it's correctly set up and ready to use.
Let’s run Qwen Code:
qwen

Click Enter to select the default theme and apply it to the user settings. Next, we need to set up the authentication.
Step 2.2: Installation from source (Optional)
Alternatively, you can opt to install Qwen Code directly from their GitHub repository:
git clone https://github.com/QwenLM/qwen-code.git
cd qwen-code
npm install
npm install -g .
This code clones the GitHub repository of Qwen Code CLI to your local machine using the git clone command. We then navigate into the cloned directory and install all project dependencies specified in the repository's package.json.
Note: -g means it's available system-wide, not just in the local project directory.
Step 2.3: Authentication
CLI requires a Qwen 3 Coder API key for authentication. The formal documentation suggests that you can authenticate by applying for an API key at https://bailian.console.aliyun.com/ (if you are in mainland China). If you are not in mainland China, then visit https://modelstudio.console.alibabacloud.com/ to apply for your API key.
However, if you are based in India, these options are not available to you. Instead, you can opt for OpenRouter, which provides users access to multiple API keys for numerous models. Here are the steps to set up an API Key for Qwen 3 Coder with it:
- Set up an account at https://openrouter.ai/
- Navigate to the Models tab and search for “Qwen 3 Coder”. You can choose a free version if you require fewer than 128k tokens, else choose the paid version instead ($0.302/M input and output tokens).

- Scroll down and click on Create API Key. Fill out the name for the key and credit limit (optional), and click Create. Save this API key for future use.

- Next, navigate to the Credits tab and add your card or bank information. You can also pay via Amazon Pay. For this demo, I added about $15, which was enough.

Step 2.4: Configuring the environment
We can now use the API key within the CLI. Return to the CLI from step 2.1 and click Enter.

Then, pass in the API key from the previous step, followed by the base URL and model name as given below:
API_KEY >Qwen_API_KEY_FROM_OPENROUTER
BASE_URL >https://openrouter.ai/api/v1
MODEL >qwen/qwen3-coder
Optionally, you can set up these variables as environment variables as well. Open a new terminal and run the following line-by-line.
export OPENAI_API_KEY="Qwen_API_KEY_FROM_OPENROUTER"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
export OPENAI_MODEL="qwen/qwen3-coder"
If you are using an API key from Alibaba Cloud, then set up your environment variables as follows:
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
export OPENAI_MODEL="qwen3-coder-plus"
Once these environment variables are set, click Enter, and you can start experimenting with CLI.
Step 3: Experimenting With Qwen Code CLI
In this section, I’ll walk through how I used Qwen Code CLI to interact with a real-world GitHub-hosted project. With just a few prompts, Qwen helped me understand the codebase, optimize functions, add new capabilities, automate tests, and maintain documentation.
Using thoughtfully crafted prompts, I was able to:
- Analyze the codebase architecture
- Optimize specific functions for memory efficiency
- Automatically generate and run unit tests
- Extend functionality by integrating new components
- Push versioned updates to GitHub
- Generate a visual flowchart of module interactions
- Document all changes in a structured changelog format
Let’s dive into each of these steps.
Exploring and understanding the codebase
Let’s begin by asking Qwen Code to explore and explain the architecture of the codebase. But, first clone the repository from GitHub and navigate into the project directory using the following command:
git clone https://github.com/AashiDutt/Voxtral_with_vLLM.git
cd Voxtral_with_vLLM
Here is the prompt I used to understand the cloned repository:
Prompt: Explain the architecture of this codebase.

Qwen CLI scanned files like app.py, config.py, requirements.txt, and a Colab notebook. It then returned a clear breakdown of the project’s structure along with a high-level summary of its key modules, saving me the time of manually opening and reading each file.
Code refactoring and optimization
After understanding the architecture, I used Qwen Code CLI to analyze potential areas of improvement in the codebase.
Prompt: What parts of this module can be optimized?



Qwen returned a structured list of suggestions across multiple dimensions: performance, memory efficiency, maintainability, and user experience. It didn’t just identify issues, it also proposed actionable code changes.
By following its guidance, I was able to:
- Reduce memory and CPU usage
- Strengthen error handling
- Improve user feedback
- Simplify code structure for future development
In the next step, I’ll show how I applied one of these optimizations (memory usage) and tested it using Qwen CLI itself.
Implementing and testing the code optimization
After identifying several areas for optimization, I decided to apply one of the most impactful suggestions: improving the memory usage in the transcribe_audio function. So, I prompted Qwen CLI to target that specific file below:
Prompt: Apply memory usage optimization to the transcribe_audio function in @app.py
Qwen focused exclusively on app.py using its @ syntax for scoped edits. This precise targeting is useful when you want changes applied in isolation without impacting unrelated parts of the codebase. The CLI rewrote the function to:
- Stream and process audio chunks instead of loading them all into memory
- Reduce UI updates by refreshing the progress bar only every 10 chunks
- Remove the need to precompute the total number of chunks
It also automatically updated the CHANGELOG.md file to reflect this improvement under a new version tag.
Generating and running tests
Once the memory usage optimization was applied to the transcribe_audio function, I used Qwen Coder CLI to automatically generate and validate unit tests for the new implementation.
Prompt: Write a pytest unit test for the recent changes.
Qwen began by scanning the project structure to check if a test directory existed and whether pytest was listed in requirements.txt. Since both were missing, it:
- Added
pytest>=7.0.0torequirements.txt - Created a new
tests/directory - Generated a test module:
tests/test_transcribe_audio.py
Qwen ran the tests and confirmed that all four tests passed successfully. To maintain a clear version history, Qwen also appended a new "Fixed" entry to CHANGELOG.md under version v0.2.0.

With just a single prompt, Qwen CLI automated test generation, identified edge cases, helped fix a logic bug, and ensured code correctness through rigorous validation.
Implementing a new component
To extend the functionality of the Voxtral Audio Assistant(codebase), I prompted Qwen Code CLI to integrate support for YouTube videos.
Prompt: Extend the current example to support YouTube videos. When a user provides a YouTube URL, extract the audio from the video and pass it to the Voxtral model for processing. Keep the rest of the pipeline and components unchanged.

The goal was to allow users to enter a YouTube URL in addition to uploading audio files. Once provided, the app should automatically extract the audio from the video and process it just like a regular file upload, without modifying the downstream pipeline for transcription or Q&A.

Qwen scanned app.py, config.py, and requirements.txt to identify the required updates. It recognized the need for yt-dlp and pydub, both of which were already listed.


As a result, a new UI component has been added, allowing users to enter a YouTube URL. Upon submission, the app extracts the audio and passes it through the existing pipeline for transcription. However, the changes made to app.py were still not enough to run the whole code without errors.
Pushing changes to GitHub
Once the transcribe_audio optimization was complete and tested, I used the CLI to version and push the changes to GitHub.
Prompt: Create a new branch on GitHub and commit and push the updated code as a second version with the message: "v2: Optimized transcribe_audio for memory usage".

Qwen automated the full Git flow using WebFlow tool that helps compare local and GitHub-hosted files. CLI could perform multiple tasks from branching to commit and push, with no manual steps required.
Qwen used its WebFetch tool to:
- Create a new branch
- Stage and commit the changes
- Push the commit
- Verify the remote update
All done with a single prompt. The updated version (v2-optimization) was safely isolated and available for review via pull request. This GitHub integration made it easy to track improvements, collaborate on updates, and maintain a clean version history.
Here is what the updated new branch looks like:

Flowchart generation
To visualize how different modules in the Voxtral Audio Assistant interact, I asked Qwen Code CLI to:
Prompt: Create a flowchart illustrating module interactions.

Qwen generated a detailed Mermaid.js flowchart showing the complete pipeline, from file upload or YouTube input, to processing via the Voxtral model, to the final output. It even attempted to embed the diagram into the project’s README.md.
Generating documentation
Once the code optimization was complete, I asked Qwen Code CLI to help document the changes in a structured and professional format.
Prompt: Write a Markdown summary of the changes made. Format it like a changelog entry under "v0.2.0".

Qwen used its WriteFile tool to append the entry directly to CHANGELOG.md under v0.2.0, following semantic versioning best practices. Once a changelog task is initiated, Qwen remembers it and avoids redundant updates, thereby saving tokens and preventing repetitive tool calls.
Conclusion
In summary, this tutorial demonstrated how Qwen Code CLI can be used to:
- Understand and explain a codebase architecture
- Apply targeted optimizations and improvements
- Generate and run unit tests with minimal overhead
- Extend functionality through new components like YouTube integration
- Automate version control and GitHub workflows
- Visualize project flows and maintain clean documentation
Qwen Code CLI significantly reduces the manual effort involved in understanding, debugging, and extending a codebase. While it draws heavily from Gemini CLI as its foundation, Qwen Code introduces enhancements for Qwen3-Coder models, like improved parser and tool support.
What impressed me the most is its ability to maintain context across tasks. Once you give it a changelog task or a file to monitor, Qwen remembers it and avoids repetition. It also scopes changes using syntax like @file.py, making it safe to use in large projects.
If you're working with complex Python projects or maintaining open-source repos, this tool can save hours of boilerplate and make your workflow more intelligent and iterative.

I am a Google Developers Expert in ML(Gen AI), a Kaggle 3x Expert, and a Women Techmakers Ambassador with 3+ years of experience in tech. I co-founded a health-tech startup in 2020 and am pursuing a master's in computer science at Georgia Tech, specializing in machine learning.






