mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
docs: Add detailed documentation for Qwen Code's approval modes and usage
- Introduced a comprehensive guide on the four permission modes: Plan, Default, Auto-Edit, and YOLO, including their use cases and risk levels. - Updated the overview and quickstart documentation for clarity and consistency. - Removed the outdated CLI reference document and integrated relevant content into the updated documentation. - Improved command creation examples and best practices for custom commands.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
# Common workflows
|
||||
|
||||
> Learn about common workflows with Qwen Code.
|
||||
@@ -13,26 +12,26 @@ Suppose you've just joined a new project and need to understand its structure qu
|
||||
|
||||
1. Navigate to the project root directory
|
||||
|
||||
```bash
|
||||
cd /path/to/project
|
||||
```bash
|
||||
cd /path/to/project
|
||||
```
|
||||
|
||||
2. Start Qwen Code
|
||||
|
||||
```bash
|
||||
```bash
|
||||
qwen
|
||||
```
|
||||
|
||||
3. Ask for a high-level overview
|
||||
|
||||
```
|
||||
give me an overview of this codebase
|
||||
give me an overview of this codebase
|
||||
```
|
||||
|
||||
4. Dive deeper into specific components
|
||||
|
||||
```
|
||||
explain the main architecture patterns used here
|
||||
explain the main architecture patterns used here
|
||||
```
|
||||
|
||||
```
|
||||
@@ -43,11 +42,11 @@ what are the key data models?
|
||||
how is authentication handled?
|
||||
```
|
||||
|
||||
>[!tip] Tips:
|
||||
>
|
||||
> - Start with broad questions, then narrow down to specific areas
|
||||
> - Ask about coding conventions and patterns used in the project
|
||||
> - Request a glossary of project-specific terms
|
||||
> [!tip]
|
||||
>
|
||||
> - Start with broad questions, then narrow down to specific areas
|
||||
> - Ask about coding conventions and patterns used in the project
|
||||
> - Request a glossary of project-specific terms
|
||||
|
||||
### Find relevant code
|
||||
|
||||
@@ -56,50 +55,53 @@ Suppose you need to locate code related to a specific feature or functionality.
|
||||
1. Ask Qwen Code to find relevant files
|
||||
|
||||
```
|
||||
find the files that handle user authentication
|
||||
find the files that handle user authentication
|
||||
```
|
||||
|
||||
2. Get context on how components interact
|
||||
|
||||
```
|
||||
how do these authentication files work together?
|
||||
how do these authentication files work together?
|
||||
```
|
||||
|
||||
3. Understand the execution flow
|
||||
|
||||
```
|
||||
trace the login process from front-end to database
|
||||
trace the login process from front-end to database
|
||||
```
|
||||
|
||||
> [!tip] Tips
|
||||
>
|
||||
> - Be specific about what you're looking for
|
||||
> - Use domain language from the project
|
||||
> [!tip]
|
||||
>
|
||||
> - Be specific about what you're looking for
|
||||
> - Use domain language from the project
|
||||
|
||||
## Fix bugs efficiently
|
||||
|
||||
Suppose you've encountered an error message and need to find and fix its source.
|
||||
|
||||
1. Share the error with Qwen Code
|
||||
|
||||
```
|
||||
I'm seeing an error when I run npm test
|
||||
I'm seeing an error when I run npm test
|
||||
```
|
||||
|
||||
2. Ask for fix recommendations
|
||||
|
||||
```
|
||||
suggest a few ways to fix the @ts-ignore in user.ts
|
||||
```
|
||||
|
||||
3. Apply the fix
|
||||
|
||||
```
|
||||
update user.tsto add the null check you suggested
|
||||
update user.tsto add the null check you suggested
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> - Tell Qwen Code the command to reproduce the issue and get a stack trace
|
||||
> - Mention any steps to reproduce the error
|
||||
> - Let Qwen Code know if the error is intermittent or consistent
|
||||
> [!tip]
|
||||
>
|
||||
> - Tell Qwen Code the command to reproduce the issue and get a stack trace
|
||||
> - Mention any steps to reproduce the error
|
||||
> - Let Qwen Code know if the error is intermittent or consistent
|
||||
|
||||
## Refactor code
|
||||
|
||||
@@ -108,32 +110,32 @@ Suppose you need to update old code to use modern patterns and practices.
|
||||
1. Identify legacy code for refactoring
|
||||
|
||||
```
|
||||
find deprecated API usage in our codebase
|
||||
find deprecated API usage in our codebase
|
||||
```
|
||||
|
||||
2. Get refactoring recommendations
|
||||
|
||||
```
|
||||
suggest how to refactor utils.js to use modern JavaScript features
|
||||
suggest how to refactor utils.js to use modern JavaScript features
|
||||
```
|
||||
|
||||
3. Apply the changes safely
|
||||
|
||||
```
|
||||
refactor utils.js to use ES 2024 features while maintaining the same behavior
|
||||
refactor utils.js to use ES 2024 features while maintaining the same behavior
|
||||
```
|
||||
|
||||
4. Verify the refactoring
|
||||
|
||||
```
|
||||
run tests for the refactored code
|
||||
run tests for the refactored code
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> - Ask Qwen Code to explain the benefits of the modern approach
|
||||
> - Request that changes maintain backward compatibility when needed
|
||||
> - Do refactoring in small, testable increments
|
||||
> [!tip]
|
||||
>
|
||||
> - Ask Qwen Code to explain the benefits of the modern approach
|
||||
> - Request that changes maintain backward compatibility when needed
|
||||
> - Do refactoring in small, testable increments
|
||||
|
||||
## Use specialized subagents
|
||||
|
||||
@@ -175,82 +177,20 @@ have the debugger subagent investigate why users can't log in
|
||||
/agents
|
||||
```
|
||||
|
||||
Then select "Create New subagent" and follow the prompts to define:
|
||||
Then select "create" and follow the prompts to define:
|
||||
|
||||
- A unique identifier that describes the subagent's purpose (for example, `code-reviewer`, `api-designer`).
|
||||
- When Qwen Code should use this agent
|
||||
- Which tools it can access
|
||||
- A system prompt describing the agent's role and behavior
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Create project-specific subagents in `.qwen/agents/` for team sharing
|
||||
> - Use descriptive `description` fields to enable automatic delegation
|
||||
> - Limit tool access to what each subagent actually needs
|
||||
> - Know more [Sub Agents](/sub-agents)
|
||||
|
||||
|
||||
## Use Plan Mode for safe code analysis
|
||||
|
||||
Plan Mode instructs Qwen Code to create a plan by analyzing the codebase with read-only operations, perfect for exploring codebases, planning complex changes, or reviewing code safely.
|
||||
|
||||
### When to use Plan Mode
|
||||
|
||||
- **Multi-step implementation**: When your feature requires making edits to many files
|
||||
- **Code exploration**: When you want to research the codebase thoroughly before changing anything
|
||||
- **Interactive development**: When you want to iterate on the direction with Qwen Code
|
||||
|
||||
### How to use Plan Mode
|
||||
|
||||
**Turn on Plan Mode during a session**
|
||||
|
||||
You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes.
|
||||
|
||||
If you are in Normal Mode, **Shift+Tab** first switches into Auto-Accept Mode, indicated by `⏵⏵ accept edits on` at the bottom of the terminal. A subsequent **Shift+Tab** will switch into Plan Mode, indicated by `⏸ plan mode`.
|
||||
|
||||
**Start a new session in Plan Mode**
|
||||
|
||||
To start a new session in Plan Mode, use the `/approval-mode` then select `plan`
|
||||
|
||||
```bash
|
||||
/approval-mode
|
||||
```
|
||||
|
||||
**Run "headless" queries in Plan Mode**
|
||||
|
||||
You can also run a query in Plan Mode directly with `-p` or `prompt`:
|
||||
|
||||
```bash
|
||||
qwen --prompt "What is machine learning?"
|
||||
```
|
||||
|
||||
### Example: Planning a complex refactor
|
||||
|
||||
```bash
|
||||
/approval-mode plan
|
||||
```
|
||||
|
||||
```
|
||||
I need to refactor our authentication system to use OAuth2. Create a detailed migration plan.
|
||||
```
|
||||
|
||||
Qwen Code analyzes the current implementation and create a comprehensive plan. Refine with follow-ups:
|
||||
|
||||
```
|
||||
What about backward compatibility?
|
||||
How should we handle database migration?
|
||||
```
|
||||
|
||||
### Configure Plan Mode as default
|
||||
|
||||
```json
|
||||
// .qwen/settings.json
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "plan"
|
||||
}
|
||||
}
|
||||
```
|
||||
> - Use descriptive `description` fields to enable automatic delegation
|
||||
> - Limit tool access to what each subagent actually needs
|
||||
> - Know more about [Sub Agents](/users/features/sub-agents)
|
||||
> - Know more about [Approval Mode](/users/features/approval-mode)
|
||||
|
||||
## Work with tests
|
||||
|
||||
@@ -259,22 +199,25 @@ Suppose you need to add tests for uncovered code.
|
||||
1. Identify untested code
|
||||
|
||||
```
|
||||
find functions in NotificationsService. swift that are not covered by tests
|
||||
find functions in NotificationsService.swift that are not covered by tests
|
||||
```
|
||||
|
||||
2. Generate test scaffolding
|
||||
|
||||
```
|
||||
add tests for the notification service
|
||||
add tests for the notification service
|
||||
```
|
||||
|
||||
3. Add meaningful test cases
|
||||
|
||||
```
|
||||
add test cases for edge conditions in the notification service
|
||||
add test cases for edge conditions in the notification service
|
||||
```
|
||||
|
||||
4. Run and verify tests
|
||||
|
||||
```
|
||||
run the new tests and fix any failures
|
||||
run the new tests and fix any failures
|
||||
```
|
||||
|
||||
Qwen Code can generate tests that follow your project's existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Qwen Code examines your existing test files to match the style, frameworks, and assertion patterns already in use.
|
||||
@@ -286,62 +229,70 @@ For comprehensive coverage, ask Qwen Code to identify edge cases you might have
|
||||
Suppose you need to create a well-documented pull request for your changes.
|
||||
|
||||
1. Summarize your changes
|
||||
|
||||
```
|
||||
summarize the changes I've made to the authentication module
|
||||
summarize the changes I've made to the authentication module
|
||||
```
|
||||
|
||||
2. Generate a pull request with Qwen Code
|
||||
2. Generate a pull request with Qwen Code
|
||||
|
||||
```
|
||||
create a pr
|
||||
create a pr
|
||||
```
|
||||
|
||||
3. Review and refine
|
||||
3. Review and refine
|
||||
|
||||
```
|
||||
enhance the PR description with more context about the security improvements
|
||||
enhance the PR description with more context about the security improvements
|
||||
```
|
||||
|
||||
4. Add testing details
|
||||
4. Add testing details
|
||||
|
||||
```
|
||||
add information about how these changes were tested
|
||||
add information about how these changes were tested
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> - Ask Qwen Code directly to make a PR for you
|
||||
> - Review Qwen Code's generated PR before submitting
|
||||
> - Ask Qwen Code to highlight potential risks or considerations
|
||||
> [!tip]
|
||||
>
|
||||
> - Ask Qwen Code directly to make a PR for you
|
||||
> - Review Qwen Code's generated PR before submitting
|
||||
> - Ask Qwen Code to highlight potential risks or considerations
|
||||
|
||||
## Handle documentation
|
||||
|
||||
Suppose you need to add or update documentation for your code.
|
||||
|
||||
1. Identify undocumented code
|
||||
|
||||
```
|
||||
find functions without proper JSDoc comments in the auth module
|
||||
find functions without proper JSDoc comments in the auth module
|
||||
```
|
||||
|
||||
2. Generate documentation
|
||||
2. Generate documentation
|
||||
|
||||
```
|
||||
add JSDoc comments to the undocumented functions in auth.js
|
||||
add JSDoc comments to the undocumented functions in auth.js
|
||||
```
|
||||
|
||||
3. Review and enhance
|
||||
3. Review and enhance
|
||||
|
||||
```
|
||||
improve the generated documentation with more context and examples
|
||||
improve the generated documentation with more context and examples
|
||||
```
|
||||
|
||||
4. Verify documentation
|
||||
4. Verify documentation
|
||||
|
||||
```
|
||||
check if the documentation follows our project standards
|
||||
check if the documentation follows our project standards
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> - Specify the documentation style you want (JSDoc, docstrings, etc.)
|
||||
> - Ask for examples in the documentation
|
||||
> - Request documentation for public APIs, interfaces, and complex logic
|
||||
> [!tip]
|
||||
>
|
||||
> - Specify the documentation style you want (JSDoc, docstrings, etc.)
|
||||
> - Ask for examples in the documentation
|
||||
> - Request documentation for public APIs, interfaces, and complex logic
|
||||
|
||||
## Work with images
|
||||
## Work with images【TBD 目前读不了】
|
||||
|
||||
Suppose you need to work with images in your codebase, and you want Qwen Code's help analyzing image content.
|
||||
|
||||
@@ -349,11 +300,12 @@ Suppose you need to work with images in your codebase, and you want Qwen Code's
|
||||
|
||||
You can use any of these methods:
|
||||
|
||||
1) Drag and drop an image into the Qwen Code window
|
||||
2) Copy an image and paste it into the CLI with ctrl+v (Do not use cmd+v)
|
||||
3) Provide an image path to Qwen Code. E.g., "Analyze this image: /path/to/your/image. png"
|
||||
- Drag and drop an image into the Qwen Code window
|
||||
- Copy an image and paste it into the CLI with ctrl+v (Do not use cmd+v)
|
||||
- Provide an image path to Qwen Code. E.g., "Analyze this image: @/path/to/your/image. png"
|
||||
|
||||
2. Ask Qwen Code to analyze the image
|
||||
|
||||
4. Ask Qwen Code to analyze the image
|
||||
```
|
||||
What does this image show?
|
||||
```
|
||||
@@ -366,7 +318,8 @@ Describe the UI elements in this screenshot
|
||||
Are there any problematic elements in this diagram?
|
||||
```
|
||||
|
||||
3. Use images for context
|
||||
3. Use images for context
|
||||
|
||||
```
|
||||
Here's a screenshot of the error. What's causing it?
|
||||
```
|
||||
@@ -376,6 +329,7 @@ This is our current database schema. How should we modify it for the new feature
|
||||
```
|
||||
|
||||
4. Get code suggestions from visual content
|
||||
|
||||
```
|
||||
Generate CSS to match this design mockup
|
||||
```
|
||||
@@ -384,99 +338,77 @@ Generate CSS to match this design mockup
|
||||
What HTML structure would recreate this component?
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> - Use images when text descriptions would be unclear or cumbersome
|
||||
> [!tip]
|
||||
>
|
||||
> - Use images when text descriptions would be unclear or cumbersome
|
||||
> - Include screenshots of errors, UI designs, or diagrams for better context
|
||||
> - You can work with multiple images in a conversation
|
||||
> - Image analysis works with diagrams, screenshots, mockups, and more
|
||||
> - You can work with multiple images in a conversation
|
||||
> - Image analysis works with diagrams, screenshots, mockups, and more
|
||||
|
||||
## Reference files and directories
|
||||
|
||||
Use `@` to quickly include files or directories without waiting for Qwen Code to read them.
|
||||
|
||||
1. Reference a single file
|
||||
|
||||
```
|
||||
Explain the logic in @src/utils/auth.js
|
||||
```
|
||||
|
||||
This includes the full content of the file in the conversation.
|
||||
|
||||
2. Reference a directory
|
||||
2. Reference a directory
|
||||
|
||||
```
|
||||
What's the structure of @src/components?
|
||||
```
|
||||
|
||||
This provides a directory listing with file information.
|
||||
|
||||
3. Reference MCP resources
|
||||
3. Reference MCP resources
|
||||
|
||||
```
|
||||
Show me the data from @github: repos/owner/repo/issues
|
||||
```
|
||||
|
||||
This fetches data from connected MCP servers using the format @server: resource. See [MCP](/mcp) for details.
|
||||
This fetches data from connected MCP servers using the format @server: resource. See [MCP](/users/features/mcp) for details.
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - File paths can be relative or absolute
|
||||
> - @ file references add `QWEN.md` in the file's directory and parent directories to context
|
||||
> - Directory references show file listings, not contents
|
||||
> - You can reference multiple files in a single message (for example, "`@file 1.js` and `@file 2.js`")
|
||||
|
||||
|
||||
## Use extended thinking
|
||||
|
||||
Suppose you're working on complex architectural decisions, challenging bugs, or planning multi-step implementations that require deep reasoning.
|
||||
|
||||
1. Provide context and ask Qwen Code to think
|
||||
```
|
||||
I need to implement a new authentication system using OAuth 2 for our API. Think deeply about the best approach for implementing this in our codebase.
|
||||
```
|
||||
|
||||
Qwen Code gathers relevant information from your codebase and uses extended thinking, which is visible in the interface.
|
||||
|
||||
2. Refine the thinking with follow-up prompts
|
||||
|
||||
```
|
||||
think about potential security vulnerabilities in this approach
|
||||
```
|
||||
|
||||
```
|
||||
think hard about edge cases we should handle
|
||||
```
|
||||
|
||||
> [!note]
|
||||
> Qwen Code displays its thinking process as italic gray text above the response.
|
||||
|
||||
## Resume previous conversations
|
||||
|
||||
Suppose you've been working on a task with Qwen Code and need to continue where you left off in a later session.
|
||||
|
||||
Qwen Code provides two options for resuming previous conversations:
|
||||
|
||||
- `--continue` to automatically continue the most recent conversation
|
||||
- `--resume` to display a conversation picker
|
||||
- `--continue` to automatically continue the most recent conversation
|
||||
- `--resume` to display a conversation picker
|
||||
|
||||
1. Continue the most recent conversation
|
||||
|
||||
```bash
|
||||
qwen-code --continue
|
||||
```bash
|
||||
qwen --continue
|
||||
```
|
||||
|
||||
This immediately resumes your most recent conversation without any prompts.
|
||||
|
||||
2. Continue in non-interactive mode
|
||||
|
||||
```bash
|
||||
qwen-code --continue --print "Continue with my task"
|
||||
```bash
|
||||
qwen --continue --p "Continue with my task"
|
||||
```
|
||||
|
||||
Use `--print` with `--continue` to resume the most recent conversation in non-interactive mode, perfect for scripts or automation.
|
||||
|
||||
3. Show conversation picker
|
||||
|
||||
```bash
|
||||
qwen-code --resume
|
||||
```bash
|
||||
qwen --resume
|
||||
```
|
||||
|
||||
This displays an interactive conversation selector with a clean list view showing:
|
||||
@@ -486,50 +418,49 @@ This displays an interactive conversation selector with a clean list view showin
|
||||
|
||||
Use arrow keys to navigate and press Enter to select a conversation. Press Esc to exit.
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Conversation history is stored locally on your machine
|
||||
> - Use `--continue` for quick access to your most recent conversation
|
||||
> - Use `--resume` when you need to select a specific past conversation
|
||||
> - When resuming, you'll see the entire conversation history before continuing
|
||||
> - The resumed conversation starts with the same model and configuration as the original
|
||||
>
|
||||
> How it works:
|
||||
>
|
||||
>
|
||||
> **How it works**:
|
||||
>
|
||||
> 1. **Conversation Storage**: All conversations are automatically saved locally with their full message history
|
||||
> 2. **Message Deserialization**: When resuming, the entire message history is restored to maintain context
|
||||
> 3. **Tool State**: Tool usage and results from the previous conversation are preserved
|
||||
> 4. **Context Restoration**: The conversation resumes with all previous context intact
|
||||
>
|
||||
> Examples:
|
||||
>
|
||||
> ```bash
|
||||
> # Continue most recent conversation
|
||||
> qwen-code --continue
|
||||
>
|
||||
> # Continue most recent conversation with a specific prompt
|
||||
> qwen-code --continue --print "Show me our progress"
|
||||
>
|
||||
> # Show conversation picker
|
||||
> qwen-code --resume
|
||||
>
|
||||
> # Continue most recent conversation in non-interactive mode
|
||||
> qwen-code --continue --print "Run the tests again"
|
||||
> ```
|
||||
> 3. **Tool State**: Tool usage and results from the previous conversation are preserved
|
||||
> 4. **Context Restoration**: The conversation resumes with all previous context intact
|
||||
>
|
||||
> **Examples**:
|
||||
>
|
||||
> ```bash
|
||||
> # Continue most recent conversation
|
||||
> qwen --continue
|
||||
>
|
||||
> # Continue most recent conversation with a specific prompt
|
||||
> qwen --continue --p "Show me our progress"
|
||||
>
|
||||
> # Show conversation picker
|
||||
> qwen --resume
|
||||
>
|
||||
> # Continue most recent conversation in non-interactive mode
|
||||
> qwen --continue --p "Run the tests again"
|
||||
> ```
|
||||
|
||||
|
||||
## Run parallel Qwen Code sessions with Git worktrees
|
||||
## Run parallel Qwen Code sessions with Git worktrees【TBD 不是特别理解创建 worktree,需要确认一下命令】
|
||||
|
||||
Suppose you need to work on multiple tasks simultaneously with complete code isolation between Qwen Code instances.
|
||||
|
||||
1. Understand Git worktrees
|
||||
|
||||
Git worktrees allow you to check out multiple branches from the same repository into separate directories. Each worktree has its own working directory with isolated files, while sharing the same Git history. Learn more in the [official Git worktree documentation]( https://git-scm.com/docs/git-worktree ).
|
||||
Git worktrees allow you to check out multiple branches from the same repository into separate directories. Each worktree has its own working directory with isolated files, while sharing the same Git history. Learn more in the [official Git worktree documentation](https://git-scm.com/docs/git-worktree).
|
||||
|
||||
2. Create a new worktree
|
||||
|
||||
```bash
|
||||
# Create a new worktree with a new branch
|
||||
```bash
|
||||
# Create a new worktree with a new branch
|
||||
git worktree add ../project-feature-a -b feature-a
|
||||
|
||||
# Or create a worktree with an existing branch
|
||||
@@ -539,23 +470,25 @@ git worktree add ../project-bugfix bugfix-123
|
||||
This creates a new directory with a separate working copy of your repository.
|
||||
|
||||
4. Run Qwen Code in each worktree
|
||||
```bash
|
||||
# Navigate to your worktree
|
||||
|
||||
```bash
|
||||
# Navigate to your worktree
|
||||
cd ../project-feature-a
|
||||
|
||||
# Run Qwen Code in this isolated environment
|
||||
qwen
|
||||
```
|
||||
|
||||
|
||||
5. Run Qwen Code in another worktree
|
||||
```bash
|
||||
|
||||
```bash
|
||||
cd ../project-bugfix
|
||||
qwen
|
||||
```
|
||||
|
||||
6. Manage your worktrees
|
||||
```bash
|
||||
|
||||
```bash
|
||||
# List all worktrees
|
||||
git worktree list
|
||||
|
||||
@@ -563,19 +496,17 @@ git worktree list
|
||||
git worktree remove ../project-feature-a
|
||||
```
|
||||
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Each worktree has its own independent file state, making it perfect for parallel Qwen Code sessions
|
||||
> - Changes made in one worktree won't affect others, preventing Qwen Code instances from interfering with each other
|
||||
> - All worktrees share the same Git history and remote connections
|
||||
> - For long-running tasks, you can have Qwen Code working in one worktree while you continue development in another
|
||||
> - Use descriptive directory names to easily identify which task each worktree is for
|
||||
> - Remember to initialize your development environment in each new worktree according to your project's setup. Depending on your stack, this might include:
|
||||
> - JavaScript projects: Running dependency installation (`npm install`, `yarn`)
|
||||
> - Python projects: Setting up virtual environments or installing with package managers
|
||||
> - Other languages: Following your project's standard setup process
|
||||
|
||||
> - JavaScript projects: Running dependency installation (`npm install`, `yarn`)
|
||||
> - Python projects: Setting up virtual environments or installing with package managers
|
||||
> - Other languages: Following your project's standard setup process
|
||||
|
||||
## Use Qwen Code as a unix-style utility
|
||||
|
||||
@@ -585,20 +516,19 @@ Suppose you want to use Qwen Code as a linter or code reviewer.
|
||||
|
||||
**Add Qwen Code to your build script:**
|
||||
|
||||
```json
|
||||
```json
|
||||
// package.json
|
||||
{
|
||||
...
|
||||
"scripts": {
|
||||
...
|
||||
"lint:Qwen Code": "qwen-code -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"
|
||||
"lint:Qwen Code": "qwen -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Use Qwen Code for automated code review in your CI/CD pipeline
|
||||
> - Customize the prompt to check for specific issues relevant to your project
|
||||
> - Consider creating multiple scripts for different types of verification
|
||||
@@ -609,12 +539,12 @@ Suppose you want to pipe data into Qwen Code, and get back data in a structured
|
||||
|
||||
**Pipe data through Qwen Code:**
|
||||
|
||||
```bash
|
||||
cat build-error.txt | qwen-code -p 'concisely explain the root cause of this build error' > output.txt
|
||||
```bash
|
||||
cat build-error.txt | qwen -p 'concisely explain the root cause of this build error' > output.txt
|
||||
```
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Use pipes to integrate Qwen-Code into existing shell scripts
|
||||
> - Combine with other Unix tools for powerful workflows
|
||||
> - Consider using --output-format for structured output
|
||||
@@ -623,32 +553,32 @@ cat build-error.txt | qwen-code -p 'concisely explain the root cause of this bui
|
||||
|
||||
Suppose you need Qwen Code's output in a specific format, especially when integrating Qwen Code into scripts or other tools.
|
||||
|
||||
1. Use text format (default)
|
||||
1. **Use text format (default)**
|
||||
|
||||
```bash
|
||||
cat data. txt | qwen-code -p 'summarize this data' --output-format text > summary. txt
|
||||
```bash
|
||||
cat data.txt | qwen -p 'summarize this data' --output-format text > summary.txt
|
||||
```
|
||||
|
||||
This outputs just Qwen Code's plain text response (default behavior).
|
||||
|
||||
2. Use JSON format
|
||||
2. **Use JSON format**
|
||||
|
||||
```bash
|
||||
cat code. py | qwen-code -p 'analyze this code for bugs' --output-format json > analysis.json
|
||||
```bash
|
||||
cat code.py | qwen -p 'analyze this code for bugs' --output-format json > analysis.json
|
||||
```
|
||||
|
||||
This outputs a JSON array of messages with metadata including cost and duration.
|
||||
|
||||
3. Use streaming JSON format
|
||||
3. **Use streaming JSON format**
|
||||
|
||||
```bash
|
||||
cat log. txt | qwen-code -p 'parse this log file for errors' --output-format stream-json
|
||||
```bash
|
||||
cat log.txt | qwen -p 'parse this log file for errors' --output-format stream-json
|
||||
```
|
||||
|
||||
This outputs a series of JSON objects in real-time as Qwen Code processes the request. Each message is a valid JSON object, but the entire output is not valid JSON if concatenated.
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Use `--output-format text` for simple integrations where you just need Qwen Code's response
|
||||
> - Use `--output-format json` when you need the full conversation log
|
||||
> - Use `--output-format stream-json` for real-time output of each conversation turn
|
||||
@@ -683,13 +613,12 @@ how do I configure Qwen Code for Amazon Bedrock?
|
||||
what are the limitations of Qwen Code?
|
||||
```
|
||||
|
||||
|
||||
> [!note]
|
||||
>
|
||||
>
|
||||
> Qwen Code provides documentation-based answers to these questions. For executable examples and hands-on demonstrations, refer to the specific workflow sections above.
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> [!tip]
|
||||
>
|
||||
> - Qwen Code always has access to the latest Qwen Code documentation, regardless of the version you're using
|
||||
> - Ask specific questions to get detailed answers
|
||||
> - Qwen Code can explain complex features like MCP integration, enterprise configurations, and advanced workflows
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
Qwen Code offers three distinct permission modes that allow you to flexibly control how AI interacts with your code and system based on task complexity and risk level.
|
||||
|
||||
## Permission Modes Comparison
|
||||
|
||||
| Mode | File Editing | Shell Commands | Best For | Risk Level |
|
||||
| -------------- | --------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ | ---------- |
|
||||
| **Plan** | ❌ Read-only analysis only | ❌ Not executed | • Code exploration <br>• Planning complex changes <br>• Safe code review | Lowest |
|
||||
| **Default** | ✅ Manual approval required | ✅ Manual approval required | • New/unfamiliar codebases <br>• Critical systems <br>• Team collaboration <br>• Learning and teaching | Low |
|
||||
| **Auto-Edit** | ✅ Auto-approved | ❌ Manual approval required | • Daily development tasks <br>• Refactoring and code improvements <br>• Safe automation | Medium |
|
||||
| **YOLO** | ✅ Auto-approved | ✅ Auto-approved | • Trusted personal projects <br>• Automated scripts/CI/CD <br>• Batch processing tasks | Highest |
|
||||
|
||||
### Quick Reference Guide
|
||||
|
||||
- **Start in Plan Mode**: Great for understanding before making changes
|
||||
- **Work in Default Mode**: The balanced choice for most development work
|
||||
- **Switch to Auto-Edit**: When you're making lots of safe code changes
|
||||
- **Use YOLO sparingly**: Only for trusted automation in controlled environments
|
||||
|
||||
> [!tip]
|
||||
>
|
||||
> You can quickly cycle through modes during a session using **Shift+Tab**. The terminal status bar shows your current mode, so you always know what permissions Qwen Code has.
|
||||
|
||||
## 1. Use Plan Mode for safe code analysis
|
||||
|
||||
Plan Mode instructs Qwen Code to create a plan by analyzing the codebase with **read-only** operations, perfect for exploring codebases, planning complex changes, or reviewing code safely.
|
||||
|
||||
### When to use Plan Mode
|
||||
|
||||
- **Multi-step implementation**: When your feature requires making edits to many files
|
||||
- **Code exploration**: When you want to research the codebase thoroughly before changing anything
|
||||
- **Interactive development**: When you want to iterate on the direction with Qwen Code
|
||||
|
||||
### How to use Plan Mode
|
||||
|
||||
**Turn on Plan Mode during a session**
|
||||
|
||||
You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes.
|
||||
|
||||
If you are in Normal Mode, **Shift+Tab** first switches into `auto-edits` Mode, indicated by `⏵⏵ accept edits on` at the bottom of the terminal. A subsequent **Shift+Tab** will switch into Plan Mode, indicated by `⏸ plan mode`.
|
||||
|
||||
**Start a new session in Plan Mode**
|
||||
|
||||
To start a new session in Plan Mode, use the `/approval-mode` then select `plan`
|
||||
|
||||
```bash
|
||||
/approval-mode
|
||||
```
|
||||
|
||||
**Run "headless" queries in Plan Mode**
|
||||
|
||||
You can also run a query in Plan Mode directly with `-p` or `prompt`:
|
||||
|
||||
```bash
|
||||
qwen --prompt "What is machine learning?"
|
||||
```
|
||||
|
||||
### Example: Planning a complex refactor
|
||||
|
||||
```bash
|
||||
/approval-mode plan
|
||||
```
|
||||
|
||||
```
|
||||
I need to refactor our authentication system to use OAuth2. Create a detailed migration plan.
|
||||
```
|
||||
|
||||
Qwen Code analyzes the current implementation and create a comprehensive plan. Refine with follow-ups:
|
||||
|
||||
```
|
||||
What about backward compatibility?
|
||||
How should we handle database migration?
|
||||
```
|
||||
|
||||
### Configure Plan Mode as default
|
||||
|
||||
```json
|
||||
// .qwen/settings.json
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "plan"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 2. Use Default Mode for Controlled Interaction
|
||||
|
||||
Default Mode is the standard way to work with Qwen Code. In this mode, you maintain full control over all potentially risky operations - Qwen Code will ask for your approval before making any file changes or executing shell commands.
|
||||
|
||||
### When to use Default Mode
|
||||
|
||||
- **New to a codebase**: When you're exploring an unfamiliar project and want to be extra cautious
|
||||
- **Critical systems**: When working on production code, infrastructure, or sensitive data
|
||||
- **Learning and teaching**: When you want to understand each step Qwen Code is taking
|
||||
- **Team collaboration**: When multiple people are working on the same codebase
|
||||
- **Complex operations**: When the changes involve multiple files or complex logic
|
||||
|
||||
### How to use Default Mode
|
||||
|
||||
**Turn on Default Mode during a session**
|
||||
|
||||
You can switch into Default Mode during a session using **Shift+Tab** to cycle through permission modes. If you're in any other mode, pressing **Shift+Tab** will eventually cycle back to Default Mode, indicated by the absence of any mode indicator at the bottom of the terminal.
|
||||
|
||||
**Start a new session in Default Mode**
|
||||
|
||||
Default Mode is the initial mode when you start Qwen Code. If you've changed modes and want to return to Default Mode, use:
|
||||
|
||||
```
|
||||
/approval-mode default
|
||||
```
|
||||
|
||||
**Run "headless" queries in Default Mode**
|
||||
|
||||
When running headless commands, Default Mode is the default behavior. You can explicitly specify it with:
|
||||
|
||||
```
|
||||
qwen --prompt "Analyze this code for potential bugs"
|
||||
```
|
||||
|
||||
### Example: Safely implementing a feature
|
||||
|
||||
```
|
||||
/approval-mode default
|
||||
```
|
||||
|
||||
```
|
||||
I need to add user profile pictures to our application. The pictures should be stored in an S3 bucket and the URLs saved in the database.
|
||||
```
|
||||
|
||||
Qwen Code will analyze your codebase and propose a plan. It will then ask for approval before:
|
||||
|
||||
1. Creating new files (controllers, models, migrations)
|
||||
2. Modifying existing files (adding new columns, updating APIs)
|
||||
3. Running any shell commands (database migrations, dependency installation)
|
||||
|
||||
You can review each proposed change and approve or reject it individually.
|
||||
|
||||
### Configure Default Mode as default
|
||||
|
||||
```bash
|
||||
// .qwen/settings.json
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "default"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Auto Edits Mode
|
||||
|
||||
Auto-Edit Mode instructs Qwen Code to automatically approve file edits while requiring manual approval for shell commands, ideal for accelerating development workflows while maintaining system safety.
|
||||
|
||||
### When to use Auto-Accept Edits Mode
|
||||
|
||||
- **Daily development**: Ideal for most coding tasks
|
||||
- **Safe automation**: Allows AI to modify code while preventing accidental execution of dangerous commands
|
||||
- **Team collaboration**: Use in shared projects to avoid unintended impacts on others
|
||||
|
||||
### How to switch to this mode
|
||||
|
||||
```
|
||||
# Switch via command
|
||||
/approval-mode auto-edit
|
||||
|
||||
# Or use keyboard shortcut
|
||||
Shift+Tab # Switch from other modes
|
||||
```
|
||||
|
||||
### Workflow Example
|
||||
|
||||
1. You ask Qwen Code to refactor a function
|
||||
2. AI analyzes the code and proposes changes
|
||||
3. **Automatically** applies all file changes without confirmation
|
||||
4. If tests need to be run, it will **request approval** to execute `npm test`
|
||||
|
||||
## 4. YOLO Mode - Full Automation
|
||||
|
||||
YOLO Mode grants Qwen Code the highest permissions, automatically approving all tool calls including file editing and shell commands.
|
||||
|
||||
### When to use YOLO Mode
|
||||
|
||||
- **Automated scripts**: Running predefined automated tasks
|
||||
- **CI/CD pipelines**: Automated execution in controlled environments
|
||||
- **Personal projects**: Rapid iteration in fully trusted environments
|
||||
- **Batch processing**: Tasks requiring multi-step command chains
|
||||
|
||||
> [!warning]
|
||||
>
|
||||
> **Use YOLO Mode with caution**: AI can execute any command with your terminal permissions. Ensure:
|
||||
>
|
||||
> 1. You trust the current codebase
|
||||
> 2. You understand all actions AI will perform
|
||||
> 3. Important files are backed up or committed to version control
|
||||
|
||||
### How to enable YOLO Mode
|
||||
|
||||
```
|
||||
# Temporarily enable (current session only)
|
||||
/approval-mode yolo
|
||||
|
||||
# Set as project default
|
||||
/approval-mode yolo --project
|
||||
|
||||
# Set as user global default
|
||||
/approval-mode yolo --user
|
||||
```
|
||||
|
||||
### Configuration Example
|
||||
|
||||
```bash
|
||||
// .qwen/settings.json
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "yolo",
|
||||
"confirmShellCommands": false,
|
||||
"confirmFileEdits": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Automated Workflow Example
|
||||
|
||||
```bash
|
||||
# Fully automated refactoring task
|
||||
qwen --prompt "Run the test suite, fix all failing tests, then commit changes"
|
||||
|
||||
# Without human intervention, AI will:
|
||||
# 1. Run test commands (auto-approved)
|
||||
# 2. Fix failed test cases (auto-edit files)
|
||||
# 3. Execute git commit (auto-approved)
|
||||
```
|
||||
|
||||
## 🔄 Mode Switching & Configuration
|
||||
|
||||
### Keyboard Shortcut Switching
|
||||
|
||||
During a Qwen Code session, use **Shift+Tab** to quickly cycle through the three modes:
|
||||
|
||||
```
|
||||
Default Mode → Auto-Edit Mode → YOLO Mode → Plan Mode → Default Mode
|
||||
```
|
||||
|
||||
### Persistent Configuration
|
||||
|
||||
```
|
||||
// Project-level: ./.qwen/settings.json
|
||||
// User-level: ~/.qwen/settings.json
|
||||
{
|
||||
"permissions": {
|
||||
"defaultMode": "auto-edit", // or "plan" or "yolo"
|
||||
"confirmShellCommands": true,
|
||||
"confirmFileEdits": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Mode Usage Recommendations
|
||||
|
||||
1. **New to codebase**: Start with **Plan Mode** for safe exploration
|
||||
2. **Daily development tasks**: Use **Auto-Accept Edits** (default mode), efficient and safe
|
||||
3. **Automated scripts**: Use **YOLO Mode** in controlled environments for full automation
|
||||
4. **Complex refactoring**: Use **Plan Mode** first for detailed planning, then switch to appropriate mode for execution
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
> Learn about Qwen Code, Qwen's agentic coding tool that lives in your terminal and helps you turn ideas into code faster than ever before.
|
||||
|
||||
## 🚀 Get started in 30 seconds
|
||||
## Get started in 30 seconds
|
||||
|
||||
Prerequisites:
|
||||
|
||||
- A [Qwen Code](https://chat.qwen.ai/auth?mode=register) account
|
||||
- Requires [Node.js 20+](https://nodejs.org/zh-cn/download), you can use `node -v` to check the version. If it's not installed, use the following command to install it.
|
||||
|
||||
### ⏬ Install Qwen Code:
|
||||
### Install Qwen Code:
|
||||
|
||||
⭐️ **NPM**(recommended)
|
||||
**NPM**(recommended)
|
||||
|
||||
```bash
|
||||
npm install -g @qwen-code/qwen-code@latest
|
||||
@@ -23,7 +23,7 @@ npm install -g @qwen-code/qwen-code@latest
|
||||
brew install qwen-code
|
||||
```
|
||||
|
||||
### 💻 Start using Qwen Code:
|
||||
### Start using Qwen Code:
|
||||
|
||||
```bash
|
||||
cd your-project
|
||||
@@ -48,14 +48,14 @@ You'll be prompted to log in on first use. That's it! [Continue with Quickstart
|
||||
>
|
||||
> **New VS Code Extension (Beta)**: Prefer a graphical interface? Our new **VS Code extension** provides an easy-to-use native IDE experience without requiring terminal familiarity. Simply install from the marketplace and start coding with Qwen Code directly in your sidebar. You can search for **Qwen Code** in the VS Code Marketplace and download it.
|
||||
|
||||
## 🧩 What Qwen Code does for you
|
||||
## What Qwen Code does for you
|
||||
|
||||
- **Build features from descriptions**: Tell Qwen Code what you want to build in plain language. It will make a plan, write the code, and ensure it works.
|
||||
- **Debug and fix issues**: Describe a bug or paste an error message. Qwen Code will analyze your codebase, identify the problem, and implement a fix.
|
||||
- **Navigate any codebase**: Ask anything about your team's codebase, and get a thoughtful answer back. Qwen Code maintains awareness of your entire project structure, can find up-to-date information from the web, and with [MCP](/users/features/mcp) can pull from external datasources like Google Drive, Figma, and Slack.
|
||||
- **Automate tedious tasks**: Fix fiddly lint issues, resolve merge conflicts, and write release notes. Do all this in a single command from your developer machines, or automatically in CI.
|
||||
|
||||
## ❤️ Why developers love Qwen Code
|
||||
## Why developers love Qwen Code
|
||||
|
||||
- **Works in your terminal**: Not another chat window. Not another IDE. Qwen Code meets you where you already work, with the tools you already love.
|
||||
- **Takes action**: Qwen Code can directly edit files, run commands, and create commits. Need more? [MCP](/users/features/mcp) lets Qwen Code read your design docs in Google Drive, update your tickets in Jira, or use _your_ custom developer tooling.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
This quickstart guide will have you using AI-powered coding assistance in just a few minutes. By the end, you'll understand how to use Qwen Code for common development tasks.
|
||||
|
||||
## 👉 Before you begin
|
||||
## Before you begin
|
||||
|
||||
Make sure you have:
|
||||
|
||||
@@ -16,7 +16,7 @@ Make sure you have:
|
||||
|
||||
To install Qwen Code, use one of the following methods:
|
||||
|
||||
### NPM(recommended)
|
||||
### NPM (recommended)
|
||||
|
||||
Requires [Node.js 20+](https://nodejs.org/download), you can use `node -v` check the version. If it's not installed, use the following command to install it.
|
||||
|
||||
@@ -69,7 +69,7 @@ qwen
|
||||
|
||||
You'll see the Qwen Code welcome screen with your session information, recent conversations, and latest updates. Type `/help` for available commands.
|
||||
|
||||
## 🤖 Chat with Qwen Code
|
||||
## Chat with Qwen Code
|
||||
|
||||
### Ask your first question
|
||||
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
# Qwen Code Command Reference
|
||||
|
||||
This document details all commands supported by Qwen Code, helping you efficiently manage sessions, customize the interface, and control its behavior.
|
||||
|
||||
Qwen Code commands are triggered through specific prefixes and fall into three categories:
|
||||
|
||||
| Prefix Type | Function Description | Typical Use Case |
|
||||
| -------------------------- | --------------------------------------------------- | ---------------------------------------------------------------- |
|
||||
| Slash Commands (`/`) | Meta-level control of Qwen Code itself | Managing sessions, modifying settings, getting help |
|
||||
| At Commands (`@`) | Quickly inject local file content into conversation | Allowing AI to analyze specified files or code under directories |
|
||||
| Exclamation Commands (`!`) | Direct interaction with system Shell | Executing system commands like `git status`, `ls`, etc. |
|
||||
|
||||
## 1. Slash Commands (`/`)
|
||||
|
||||
Slash commands are used to manage Qwen Code sessions, interface, and basic behavior.
|
||||
|
||||
### 1.1 Session and Project Management
|
||||
|
||||
These commands help you save, restore, and summarize work progress.
|
||||
|
||||
| Command | Description | Usage Examples |
|
||||
| ------------------ | --------------------------------------------------------- | ------------------------------------ |
|
||||
| `/chat` | Manually save and restore conversation history | Requires sub-commands |
|
||||
| → `save <label>` | Save current conversation state | `/chat save Feature Ideation` |
|
||||
| → `resume <label>` | Restore conversation from saved point | `/chat resume Feature Ideation` |
|
||||
| → `list` | List all recoverable conversation labels | `/chat list` |
|
||||
| → `delete <label>` | Delete saved conversation checkpoint | `/chat delete Feature Ideation` |
|
||||
| → `share [file]` | Export conversation as Markdown or JSON | `/chat share Discussion Record.md` |
|
||||
| `/summary` | Generate project summary based on conversation history | `/summary` |
|
||||
| `/compress` | Replace chat history with summary to save Tokens | `/compress` |
|
||||
| `/restore` | Restore files to state before tool execution | `/restore` (list) or `/restore <ID>` |
|
||||
| `/init` | Analyze current directory and create initial context file | `/init` |
|
||||
|
||||
### 1.2 Interface and Workspace Control
|
||||
|
||||
Commands for adjusting interface appearance and work environment.
|
||||
|
||||
| Command | Description | Usage Examples |
|
||||
| ------------ | ---------------------------------------- | ----------------------------- |
|
||||
| `/clear` | Clear terminal screen content | `/clear` (shortcut: `Ctrl+L`) |
|
||||
| `/theme` | Change Qwen Code visual theme | `/theme` |
|
||||
| `/vim` | Turn input area Vim editing mode on/off | `/vim` |
|
||||
| `/directory` | Manage multi-directory support workspace | `/dir add ./src,./tests` |
|
||||
| `/editor` | Open dialog to select supported editor | `/editor` |
|
||||
|
||||
### 1.3 Language Settings
|
||||
|
||||
Commands specifically for controlling interface and output language.
|
||||
|
||||
| Command | Description | Usage Examples |
|
||||
| --------------------- | -------------------------------- | -------------------------- |
|
||||
| `/language` | View or change language settings | `/language` |
|
||||
| → `ui [language]` | Set UI interface language | `/language ui zh-CN` |
|
||||
| → `output [language]` | Set LLM output language | `/language output Chinese` |
|
||||
|
||||
- Available UI languages: `zh-CN` (Simplified Chinese), `en-US` (English)
|
||||
- Output language examples: `Chinese`, `English`, `Japanese`, etc.
|
||||
|
||||
### 1.4 Tool and Model Management
|
||||
|
||||
Commands for managing AI tools and models.
|
||||
|
||||
| Command | Description | Usage Examples |
|
||||
| ---------------- | --------------------------------------------- | --------------------------------------------- |
|
||||
| `/mcp` | List configured MCP servers and tools | `/mcp`, `/mcp desc` |
|
||||
| `/tools` | Display currently available tool list | `/tools`, `/tools desc` |
|
||||
| `/approval-mode` | Change approval mode for tool usage | `/approval-mode <mode (auto-edit)> --project` |
|
||||
| →`plan` | Analysis only, no execution | Secure review |
|
||||
| →`default` | Require approval for edits | Daily use |
|
||||
| →`auto-edit` | Automatically approve edits | Trusted environment |
|
||||
| →`yolo` | Automatically approve all | Quick prototyping |
|
||||
| `/model` | Switch model used in current session | `/model` |
|
||||
| `/extensions` | List all active extensions in current session | `/extensions` |
|
||||
| `/memory` | Manage AI's instruction context | `/memory add Important Info` |
|
||||
|
||||
### 1.5 Information, Settings, and Help
|
||||
|
||||
Commands for obtaining information and performing system settings.
|
||||
|
||||
| Command | Description | Usage Examples |
|
||||
| --------------- | ----------------------------------------------- | ------------------------------------------------ |
|
||||
| `/help` | Display help information for available commands | `/help` or `/?` |
|
||||
| `/about` | Display version information | `/about` |
|
||||
| `/stats` | Display detailed statistics for current session | `/stats` |
|
||||
| `/settings` | Open settings editor | `/settings` |
|
||||
| `/auth` | Change authentication method | `/auth` |
|
||||
| `/bug` | Submit issue about Qwen Code | `/bug Button click unresponsive` |
|
||||
| `/copy` | Copy last output content to clipboard | `/copy` |
|
||||
| `/quit-confirm` | Show confirmation dialog before quitting | `/quit-confirm` (shortcut: press `Ctrl+C` twice) |
|
||||
| `/quit` | Exit Qwen Code immediately | `/quit` or `/exit` |
|
||||
|
||||
### 1.6 Common Shortcuts
|
||||
|
||||
| Shortcut | Function | Note |
|
||||
| ------------------ | ----------------------- | ---------------------- |
|
||||
| `Ctrl/cmd+L` | Clear screen | Equivalent to `/clear` |
|
||||
| `Ctrl/cmd+T` | Toggle tool description | MCP tool management |
|
||||
| `Ctrl/cmd+C`×2 | Exit confirmation | Secure exit mechanism |
|
||||
| `Ctrl/cmd+Z` | Undo input | Text editing |
|
||||
| `Ctrl/cmd+Shift+Z` | Redo input | Text editing |
|
||||
|
||||
## 2. @ Commands (Introducing Files)
|
||||
|
||||
@ commands are used to quickly add local file or directory content to the conversation.
|
||||
|
||||
| Command Format | Description | Examples |
|
||||
| ------------------- | -------------------------------------------- | ------------------------------------------------ |
|
||||
| `@<file path>` | Inject content of specified file | `@src/main.py Please explain this code` |
|
||||
| `@<directory path>` | Recursively read all text files in directory | `@docs/ Summarize content of this document` |
|
||||
| Standalone `@` | Used when discussing `@` symbol itself | `@ What is this symbol used for in programming?` |
|
||||
|
||||
Note: Spaces in paths need to be escaped with backslash (e.g., `@My\ Documents/file.txt`)
|
||||
|
||||
## 3. Exclamation Commands (`!`) - Shell Command Execution
|
||||
|
||||
Exclamation commands allow you to execute system commands directly within Qwen Code.
|
||||
|
||||
| Command Format | Description | Examples |
|
||||
| ------------------ | ------------------------------------------------------------------ | -------------------------------------- |
|
||||
| `!<shell command>` | Execute command in sub-Shell | `!ls -la`, `!git status` |
|
||||
| Standalone `!` | Switch Shell mode, any input is executed directly as Shell command | `!`(enter) → Input command → `!`(exit) |
|
||||
|
||||
Environment Variables: Commands executed via `!` will set the `QWEN_CODE=1` environment variable.
|
||||
|
||||
## 4. Custom Commands
|
||||
|
||||
Save frequently used prompts as shortcut commands to improve work efficiency and ensure consistency.
|
||||
|
||||
### 📋 Quick Overview
|
||||
|
||||
| Function | Description | Advantages | Priority | Applicable Scenarios |
|
||||
| ---------------- | ------------------------------------------ | -------------------------------------- | -------- | ---------------------------------------------------- |
|
||||
| Namespace | Subdirectory creates colon-named commands | Better command organization | | |
|
||||
| Global Commands | `~/.qwen/commands/` | Available in all projects | Low | Personal frequently used commands, cross-project use |
|
||||
| Project Commands | `<project root directory>/.qwen/commands/` | Project-specific, version-controllable | High | Team sharing, project-specific commands |
|
||||
|
||||
Priority Rules: Project commands > User commands (project command used when names are same)
|
||||
|
||||
### 🔤 Command Naming Rules
|
||||
|
||||
#### File Path to Command Name Mapping Table
|
||||
|
||||
| File Location | Generated Command | Example Call |
|
||||
| ---------------------------- | ----------------- | --------------------- |
|
||||
| `~/.qwen/commands/test.toml` | `/test` | `/test Parameter` |
|
||||
| `<project>/git/commit.toml` | `/git:commit` | `/git:commit Message` |
|
||||
|
||||
Naming Rules: Path separator (`/` or `\`) converted to colon (`:`)
|
||||
|
||||
### 📄 TOML File Format Specification
|
||||
|
||||
| Field | Required | Description | Example |
|
||||
| ------------- | -------- | ---------------------------------------- | ------------------------------------------ |
|
||||
| `prompt` | Required | Prompt content sent to model | `prompt = "Please analyze code: {{args}}"` |
|
||||
| `description` | Optional | Command description (displayed in /help) | `description = "Code analysis tool"` |
|
||||
|
||||
### 🔧 Parameter Processing Mechanism
|
||||
|
||||
| Processing Method | Syntax | Applicable Scenarios | Security Features |
|
||||
| ---------------------------- | ------------------ | ------------------------------------ | -------------------------------------- |
|
||||
| Context-aware Injection | `{{args}}` | Need precise parameter control | Automatic Shell escaping |
|
||||
| Default Parameter Processing | No special marking | Simple commands, parameter appending | Append as-is |
|
||||
| Shell Command Injection | `!{command}` | Need dynamic content | Execution confirmation required before |
|
||||
|
||||
#### 1. Context-aware Injection (`{{args}}`)
|
||||
|
||||
| Scenario | TOML Configuration | Call Method | Actual Effect |
|
||||
| ---------------- | --------------------------------------- | --------------------- | ------------------------ |
|
||||
| Raw Injection | `prompt = "Fix: {{args}}"` | `/fix "Button issue"` | `Fix: "Button issue"` |
|
||||
| In Shell Command | `prompt = "Search: !{grep {{args}} .}"` | `/search "hello"` | Execute `grep "hello" .` |
|
||||
|
||||
#### 2. Default Parameter Processing
|
||||
|
||||
| Input Situation | Processing Method | Example |
|
||||
| --------------- | ------------------------------------------------------ | ---------------------------------------------- |
|
||||
| Has parameters | Append to end of prompt (separated by two line breaks) | `/cmd parameter` → Original prompt + parameter |
|
||||
| No parameters | Send prompt as is | `/cmd` → Original prompt |
|
||||
|
||||
🚀 Dynamic Content Injection
|
||||
|
||||
| Injection Type | Syntax | Processing Order | Purpose |
|
||||
| --------------------- | -------------- | ------------------- | -------------------------------- |
|
||||
| File Content | `@{file path}` | Processed first | Inject static reference files |
|
||||
| Shell Commands | `!{command}` | Processed in middle | Inject dynamic execution results |
|
||||
| Parameter Replacement | `{{args}}` | Processed last | Inject user parameters |
|
||||
|
||||
#### 3. Shell Command Execution (`!{...}`)
|
||||
|
||||
| Operation | User Interaction |
|
||||
| -------------------------------- | ------------------- |
|
||||
| 1️⃣ Parse command and parameters | - |
|
||||
| 2️⃣ Automatic Shell escaping | - |
|
||||
| 3️⃣ Show confirmation dialog | ✅ User confirmation |
|
||||
| 4️⃣ Execute command | - |
|
||||
| 5️⃣ Inject output to prompt | - |
|
||||
|
||||
Example: Git Commit Message Generation
|
||||
|
||||
```
|
||||
# git/commit.toml
|
||||
description = "Generate Commit message based on staged changes"
|
||||
prompt = """
|
||||
Please generate a Commit message based on the following diff:
|
||||
diff
|
||||
!{git diff --staged}
|
||||
"""
|
||||
```
|
||||
|
||||
#### 4. File Content Injection (`@{...}`)
|
||||
|
||||
| File Type | Support Status | Processing Method |
|
||||
| ------------ | --------------------- | --------------------------- |
|
||||
| Text Files | ✅ Full Support | Directly inject content |
|
||||
| Images/PDF | ✅ Multi-modal Support | Encode and inject |
|
||||
| Binary Files | ⚠️ Limited Support | May be skipped or truncated |
|
||||
| Directory | ✅ Recursive Injection | Follow .gitignore rules |
|
||||
|
||||
Example: Code Review Command
|
||||
|
||||
```
|
||||
# review.toml
|
||||
description = "Code review based on best practices"
|
||||
prompt = """
|
||||
Review {{args}}, reference standards:
|
||||
|
||||
@{docs/code-standards.md}
|
||||
"""
|
||||
```
|
||||
|
||||
### 🛠️ Practical Creation Example
|
||||
|
||||
#### "Pure Function Refactoring" Command Creation Steps Table
|
||||
|
||||
| Operation | Command/Code |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1️⃣ Create directory structure | `mkdir -p ~/.qwen/commands/refactor` |
|
||||
| 2️⃣ Create command file | `touch ~/.qwen/commands/refactor/pure.toml` |
|
||||
| 3️⃣ Edit command content | ```<br># ~/.qwen/commands/refactor/pure.toml<br>description = "Refactor code to pure function"<br>prompt = """<br>Please analyze code in current context, refactor to pure function.<br>Requirements:<br>1. Provide refactored code<br>2. Explain key changes and pure function characteristic implementation<br>3. Maintain function unchanged<br>"""<br>``` |
|
||||
| 4️⃣ Test command | `@file.js` → `/refactor:pure` |
|
||||
|
||||
### 💡 Custom Command Best Practices Summary
|
||||
|
||||
#### Command Design Recommendations Table
|
||||
|
||||
| Practice Points | Recommended Approach | Avoid |
|
||||
| -------------------- | ----------------------------------- | ------------------------------------------- |
|
||||
| Command Naming | Use namespaces for organization | Avoid overly generic names |
|
||||
| Parameter Processing | Clearly use `{{args}}` | Rely on default appending (easy to confuse) |
|
||||
| Error Handling | Utilize Shell error output | Ignore execution failure |
|
||||
| File Organization | Organize by function in directories | All commands in root directory |
|
||||
| Description Field | Always provide clear description | Rely on auto-generated description |
|
||||
|
||||
#### Security Features Reminder Table
|
||||
|
||||
| Security Mechanism | Protection Effect | User Operation |
|
||||
| ---------------------- | -------------------------- | ---------------------- |
|
||||
| Shell Escaping | Prevent command injection | Automatic processing |
|
||||
| Execution Confirmation | Avoid accidental execution | Dialog confirmation |
|
||||
| Error Reporting | Help diagnose issues | View error information |
|
||||
@@ -225,12 +225,23 @@ Review {{args}}, reference standards:
|
||||
|
||||
#### "Pure Function Refactoring" Command Creation Steps Table
|
||||
|
||||
| Operation | Command/Code |
|
||||
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1️⃣ Create directory structure | `mkdir -p ~/.qwen/commands/refactor` |
|
||||
| 2️⃣ Create command file | `touch ~/.qwen/commands/refactor/pure.toml` |
|
||||
| 3️⃣ Edit command content | `<br># ~/.qwen/commands/refactor/pure.toml<br>description = "Refactor code to pure function"<br>prompt = """<br>Please analyze code in current context, refactor to pure function.<br>Requirements:<br>1. Provide refactored code<br>2. Explain key changes and pure function characteristic implementation<br>3. Maintain function unchanged<br>"""<br>` |
|
||||
| 4️⃣ Test command | `@file.js` → `/refactor:pure` |
|
||||
| Operation | Command/Code |
|
||||
| ----------------------------- | ------------------------------------------- |
|
||||
| 1️⃣ Create directory structure | `mkdir -p ~/.qwen/commands/refactor` |
|
||||
| 2️⃣ Create command file | `touch ~/.qwen/commands/refactor/pure.toml` |
|
||||
| 3️⃣ Edit command content | 参考下方代码 |
|
||||
| 4️⃣ Test command | `@file.js` → `/refactor:pure` |
|
||||
|
||||
```# ~/.qwen/commands/refactor/pure.toml
|
||||
description = "Refactor code to pure function"
|
||||
prompt = """
|
||||
Please analyze code in current context, refactor to pure function.
|
||||
Requirements:
|
||||
1. Provide refactored code
|
||||
2. Explain key changes and pure function characteristic implementation
|
||||
3. Maintain function unchanged
|
||||
"""
|
||||
```
|
||||
|
||||
### 💡 Custom Command Best Practices Summary
|
||||
|
||||
|
||||
Reference in New Issue
Block a user