Qwen Code 使用指南 2025: 20个实用技巧提升编程效率
正在寻找 Qwen Code 使用教程? 这是2025年最完整的实战指南。
Qwen Code 是阿里云推出的 AI 编程助手,不仅支持代码生成,还能直接调用阿里云服务。相比海外工具,Qwen Code 对中文支持更好,国内网络访问更快,价格更实惠。
本指南包含:
- ✅ Qwen Code 安装和配置(VS Code / IDEA / Vim)
- ✅ 20个实用技巧,从基础到高级
- ✅ 提示词优化方法,提升AI理解准确度
- ✅ 阿里云服务集成实战
- ✅ 与 GitHub Copilot、Cursor 等工具的对比
快速开始:
- 📦 Qwen Code 官方文档
- 🔧 PHP Function Calling 实战 — 本地LLM Function Calling实现
- 🤖 AI Tools Directory 2025 — 更多AI工具推荐
Hey folks, AI programming tools are becoming real game-changers! But most of them are made overseas, and sometimes they just don't feel quite right. Qwen Code is different. It's an AI programming assistant from Alibaba Cloud, and it not only writes slick code but can also directly call various Alibaba Cloud services. It's a blast to use!
Today, I'm sharing 20 practical tips for Qwen Code that you'll actually use in your daily development. These are guaranteed to make your programming efficiency take off! (This is all practical stuff, so I recommend bookmarking it for later.)
How to Install Qwen Code?
Installing Qwen Code is actually pretty simple. Here’s a detailed breakdown:
Step 1: Register for an Alibaba Cloud Account
- Go to the official Alibaba Cloud website and register for an account (if you don't have one).
- Complete the real-name verification for more stable usage.
Step 2: Find Qwen Code
- Log in to the Alibaba Cloud console.
- Search for "Tongyi Qianwen" or "Qwen Code".
- Choose your development tool (VS Code, IDEA, and Vim are all supported).
Step 3: Install the Plugin
- Download the corresponding plugin package.
- Follow the installation prompts.
- Configure your API key.
Why Choose Qwen Code?
- Excellent Chinese support makes writing comments and documentation easy.
- Directly calls Alibaba Cloud services, so you don't have to set up your own environment.
- It's more affordable than many international tools.
- Fast domestic network access means no lag.
1. Be Precise with Your Descriptions for Better AI Understanding
Stop using vague commands like "fix this bug." Try to be as specific as possible with your requests.
Practical Example:
❌ Incorrect Example:
Fix this bug
✅ Correct Example:
Fix the null pointer error that occurs when a user tries to log in without a password.Why does this matter?
- The AI can understand your needs more accurately.
- It reduces back-and-forth communication time.
- The generated code is more likely to meet your expectations.
- It avoids generating irrelevant code.
2. Break Down Large Tasks into Small Steps for Higher Efficiency
For small tasks or modules, you can send the entire requirement to the AI at once, and it can deliver the result in one go, which is more efficient.
However, for larger requirements with a long implementation process, it's better to break down complex tasks into smaller steps:
Practical Example:
Step 1: Create a new endpoint for the user API.
Step 2: Add necessary validation for the request fields.
Step 3: Write test cases for this endpoint.
Step 4: Update the API documentation.Why execute in steps?
- AI context windows have limits; long requests might get truncated.
- You can review/test each step before telling the AI to proceed to the next one.
- It reduces repetitive explanations and communication costs.
- It lowers the probability of errors.
3. Let the AI Understand the Project Before It Starts Working
Before modifying code, let Qwen understand your codebase first. This will help it assist you more accurately and efficiently in development and optimization.
Practical Example:
Analyze the database table structure.
How are errors handled in this application?
What is the architecture of this project?Why let it understand first?
- The AI can better grasp your business logic.
- The generated code will be more consistent with the project's style.
- It avoids breaking the existing code structure.
- It improves code quality and consistency.
4. Master Shortcuts for More Efficient Operation
Mastering shortcuts can significantly boost your efficiency:
Common Shortcuts:
- Type
/to see all slash commands. - Use the up and down arrow keys to browse command history.
- Use the
Tabkey for command auto-completion. - Use
Option + Enterfor a new line. - Use
Ctrl + Cto exit the terminal.
Practical Tips:
/help # View help information
/clear # Clear conversation history
/cost # Check usage costs
/compact # Compact the context5. Use Permission-less Mode to Avoid Frequent Confirmations
Are you tired of Qwen Code stopping midway through a task to ask for your permission? It can seriously disrupt your workflow.
Launch Command:
qwen --dangerously-skip-permissionsSet an Alias (Recommended):
alias qwen='qwen --dangerously-skip-permissions'⚠️ Security Warning:
- This mode skips all permission checks.
- It's recommended for use in personal development environments only.
- Use with caution on company projects.
- Regularly check the content of generated files.
6. Press ESC to Stop Incorrect Operations at Any Time
If you give Qwen Code a wrong command and want it to stop, just press the ESC key.
Practical Tip:
- Press
ESCto immediately stop the current task. - The terminal will display "Interrupted by user."
- You can then enter the correct command.
- Avoids wasting time waiting for an incorrect result.
7. Resume Previous Sessions to Keep Your Work Uninterrupted
Qwen Code offers multiple ways to resume a previous conversation:
Non-interactive Mode:
qwen --continue # Automatically continue the most recent conversation
qwen --resume # Show a history of conversations to choose fromInteractive Mode:
/resume # Resume a historical sessionPractical Tips:
- Use the up and down arrow keys to select a past session.
- You can return to any previous conversation.
- Supports cross-project session recovery.
- Avoids re-explaining your requirements.
8. Smart Memory Management and Personalized Configuration
Qwen Code provides three memory locations, each for a different purpose:
| Memory Type | File Location | Description |
|---|---|---|
| Project Memory (Shared) | ./QWEN.md | Instructions shared by the project team. |
| User Memory (Global) | ~/.qwen/QWEN.md | Personal preference settings. |
| Project Memory (Local) | ./QWEN.local.md | Personal project settings (deprecated). |
Practical Configuration:
# Edit the memory file
/memory
# Set responses to be in Chinese
echo "Please always answer me in Chinese." > ~/.qwen/QWEN.mdMemory File Content:
- Frequently used bash commands.
- Core files and utility functions.
- Code style guides.
- Testing instructions.
- Development environment settings.
9. Operate Git with Natural Language, Say Goodbye to Complex Commands
In Qwen Code, Git operations become conversational, so you don't have to remember tedious commands:
Practical Examples:
What files have I modified?
Commit my changes with a reasonable, descriptive message.
Push this branch to the remote.
Create a new branch: feature/test.
Delete this branch and switch to the master branch.
Show a list of all files from the last 3 commits.Git Integration Advantages:
- Operate Git with natural language.
- Automatically generate commit messages.
- Smart branch management.
- Automatic conflict resolution.
10. Linux Smart Assistant, Handle Complex Commands with One Click
Since Qwen Code is used in the terminal, you can also use it as a Linux smart assistant:
Interactive Mode:
List the top 3 .java files with the most lines.
Find the file that takes up the most disk space.
Count the lines of code.Non-interactive Mode:
qwen -p "List the top 3 .java files with the most lines"Linux Integration Advantages:
- No need to remember complex Linux commands.
- Smart command generation.
- Automatic error handling.
- Supports complex queries.
11. Monitor Costs to Keep Your Spending in Check
Use the /cost command to view your current session's usage:
Basic Command:
/cost # View current session's costAdvanced Tool (Recommended):
# Install the qcusage tool
sudo npm install -g qcusage
# View costs for a specific date
qcusage -s 20250701
# View costs in real-time
qcusage blocks --liveCost Control Tips:
- The personal plan costs a few dozen RMB per month, cheaper than international tools.
- The enterprise plan supports team sharing, reducing per-person costs.
- Regularly use
/compactto compress the context. - Batch similar tasks to improve efficiency.
12. Smart Compression to Save Costs and Speed Up Responses
Qwen Code provides the /compact command for compression:
How to Use:
/compact # Manually compact the contextAutomatic Compression:
- By default, automatically compresses when the context exceeds 95% capacity.
- The remaining percentage is displayed in the bottom right corner.
- Automatically compresses when it reaches 0%.
Compression Advantages:
- Reduces the size of the conversation context.
- Lowers token usage.
- Improves response speed.
- Saves costs.
Best Practices:
- Regularly use
/compactto manually compress. - Use the
clearcommand periodically to reset the context. - Break down complex tasks to avoid an overly long context.
- If you're a big spender, you can ignore these optimizations.
Part Three: Advanced Tips and Under-the-Hood Configuration (Tips 13-20)
13. Deep Configuration to Unlock Hidden Features
Qwen Code has many hidden advanced configurations. Mastering them will make your experience even better:
Configuration File Locations:
# Global configuration
~/.qwen/config.json
# Project configuration
./.qwen/config.jsonAdvanced Configuration Example:
{
"model": {
"default": "qwen-plus",
"fallback": "qwen-turbo"
},
"context": {
"maxTokens": 32000,
"compressionThreshold": 0.95,
"autoCompact": true
},
"features": {
"autoComplete": true,
"codeReview": true,
"securityScan": true,
"performanceAnalysis": true
},
"aliases": {
"commit": "Commit my changes with a reasonable, descriptive message",
"deploy": "Generate and execute a deployment script",
"test": "Generate test cases for this feature"
}
}Configuration Explained:
model: Model configuration, supports primary/fallback switching.context: Context management, controls memory usage.features: Feature toggles, enable as needed.aliases: Custom aliases for quick execution of common operations.
14. In-Depth Look at the Command System
Qwen Code's command system is very powerful. Mastering these commands can greatly improve your efficiency:
Core Commands:
# Basic Commands
/help # View help
/version # View version
/status # View status
/config # Configuration management
# Session Management
/new # New session
/clear # Clear current session
/save # Save session
/load # Load session
# Context Management
/compact # Compact context
/expand # Expand context
/summary # Generate summary
/context # View context info
# Cost Control
/cost # View cost
/limit # Set usage limit
/budget # Budget management
# Model Management
/model # Switch model
/switch # Quick switch
/compare # Model comparisonAdvanced Commands:
# Project Management
/init # Initialize project
/setup # Project setup
/analyze # Project analysis
/optimize # Performance optimization
# Code Management
/format # Format code
/lint # Lint code
/refactor # Refactor code
/migrate # Migrate code
# Deployment Management
/deploy # Deploy application
/rollback # Rollback deployment
/monitor # Monitor application
/scale # Scale up/down15. Deep Dive into MCP Configuration
MCP (Model Context Protocol) is Qwen Code's core extension protocol. Mastering it unlocks infinite possibilities:
MCP Server Installation:
# Install the MCP tool
npm install -g @modelcontextprotocol/cli
# List available servers
mcp list
# Install common servers
mcp install filesystem
mcp install database
mcp install web
mcp install gitMCP Server Configuration:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem"],
"env": {
"ALLOWED_DIRECTORIES": "/Users/username/projects"
}
},
"database": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-database"],
"env": {
"DATABASE_URL": "postgresql://localhost:5432/mydb"
}
},
"web": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-web"],
"env": {
"BROWSER": "chrome"
}
}
}
}MCP Usage Tips:
# Filesystem operations
/mcp filesystem read /path/to/file
/mcp filesystem write /path/to/file "content"
/mcp filesystem list /path/to/directory
# Database operations
/mcp database query "SELECT * FROM users"
/mcp database execute "INSERT INTO users VALUES (...)"
/mcp database schema
# Web operations
/mcp web open https://example.com
/mcp web click "button"
/mcp web fill "input[name='email']" "test@example.com"
/mcp web screenshot16. Custom Tool Development
Qwen Code supports custom tool development, allowing you to build your own specialized AI assistant:
Tool Development Template:
// tools/my-tool.js
const { Tool } = require('@qwen-code/sdk');
class MyCustomTool extends Tool {
constructor() {
super({
name: 'my-tool',
description: 'My custom tool',
parameters: {
type: 'object',
properties: {
input: {
type: 'string',
description: 'Input parameter'
}
},
required: ['input']
}
});
}
async execute(params) {
const { input } = params;
// Tool logic
const result = await this.processInput(input);
return {
success: true,
data: result,
message: 'Processing complete'
};
}
async processInput(input) {
// Specific processing logic
return `Processing result: ${input}`;
}
}
module.exports = MyCustomTool;Tool Registration:
{
"tools": {
"my-tool": {
"path": "./tools/my-tool.js",
"enabled": true,
"config": {
"timeout": 30000,
"retries": 3
}
}
}
}17. Advanced Context Management
Master context management techniques to help the AI remember more information:
Context Strategies:
# Set context strategy
/context strategy "smart" # Smart compression
/context strategy "aggressive" # Aggressive compression
/context strategy "conservative" # Conservative compression
# Context Marking
/context mark "Important Info"
/context mark "Project Config"
/context mark "API Docs"
# Context Search
/context search "user login"
/context find "database config"
/context grep "error handling"Context Optimization Tips:
# Regular cleanup
/context clean --older-than 7d
# Protect important information
/context protect "Project Architecture"
/context protect "API Keys"
# Context Analysis
/context analyze
/context stats
/context optimize18. Team Collaboration Configuration
Qwen Code supports team collaboration, allowing your entire team to enjoy AI programming:
Team Configuration:
{
"team": {
"name": "Development Team",
"members": [
{
"id": "user1",
"role": "admin",
"permissions": ["read", "write", "execute"]
},
{
"id": "user2",
"role": "developer",
"permissions": ["read", "write"]
}
],
"sharedContext": {
"project": "E-commerce System",
"techStack": ["Spring Boot", "Vue.js", "MySQL"],
"codingStandards": "Alibaba Java Development Manual"
}
}
}Collaboration Features:
# Share session
/share session "Project Discussion"
/invite user@example.com
# Code Review
/review request "Please review this PR"
/review approve "Code quality is great"
/review reject "Needs changes"
# Knowledge Sharing
/knowledge add "Best Practices"
/knowledge search "Performance Optimization"
/knowledge share "Team Docs"19. Performance Optimization Tips
Master these tips to make Qwen Code run faster and more stably:
Performance Configuration:
{
"performance": {
"cache": {
"enabled": true,
"size": "100MB",
"ttl": 3600
},
"concurrency": {
"maxRequests": 10,
"timeout": 30000
},
"memory": {
"maxUsage": "2GB",
"gcThreshold": 0.8
}
}
}Optimization Commands:
# Performance Monitoring
/performance monitor
/performance stats
/performance profile
# Cache Management
/cache clear
/cache stats
/cache optimize
# Memory Management
/memory usage
/memory gc
/memory optimize20. Troubleshooting and Debugging
When you encounter problems, these tips can help you solve them quickly:
Debugging Commands:
# Log Viewing
/logs show
/logs tail
/logs filter "error"
# Status Check
/status health
/status connections
/status memory
# Fault Diagnosis
/debug start
/debug stop
/debug reportCommon Problem Solving:
# Connection Issues
/ping
/connect test
/network check
# Model Issues
/model test
/model reset
/model fallback
# Configuration Issues
/config validate
/config reset
/config backupConclusion
Folks, Qwen Code is seriously awesome! By mastering these 20 practical tips, you can:
- Skyrocket your development efficiency: Automate the entire workflow from coding to deployment.
- Enjoy the Alibaba Cloud ecosystem: Directly call cloud services without setting up your own environment.
- Have a great Chinese programming experience: Chinese comments, Chinese documentation, and more efficient team collaboration.
- Get great value for your money: It's affordable, powerful, and has a high price-performance ratio.
- Unlock infinite possibilities with advanced features: MCP protocol, custom tools, team collaboration.
My Recommendations:
- Beginners should start with the basic functions and gradually get familiar with them.
- For team development, the enterprise version is recommended for more comprehensive features.
- Update to the latest version regularly to enjoy new features.
- Practice makes perfect.
- Try the MCP protocol to unlock more possibilities.
AI won't replace programmers, but those who don't use AI will be left behind. Programmers who use AI have a future!
I'll continue to share more practical tips for Qwen Code. Follow the "PFinalClub" public account to learn AI with me and make programming easier!

