Creating Command Extensions
Custom commands are reusable prompt shortcuts that users can invoke with slash syntax (e.g.,/deploy, /test). Extensions can package and distribute commands to share workflows and best practices.
What are Custom Commands?
Custom commands:- Are Markdown files with optional YAML frontmatter
- Support template variables for dynamic content
- Can execute shell commands and include output
- Use slash syntax for invocation:
/command-name - Support nested organization with
:
Command File Format
Commands are Markdown files:Frontmatter (Optional)
description is supported.
Template Variables
Use{{args}} to insert user-provided arguments:
/search "TODO"
Shell Command Execution
Execute shell commands and include their output:Extension Structure
Place command files in acommands/ directory:
Configure in Manifest
Updateqwen-extension.json:
commands field specifies the directory (defaults to "commands" if not specified).
Command Naming
Command names are derived from file paths:Top-Level Commands
Nested Commands
Conflict Resolution
If a command name conflicts with user or project commands:Example: Search and Summarize
From the built-in examples: File:commands/fs/grep-code.md
Example: File Summarizer
File:commands/summarize.md
Example: Code Review
File:commands/review.md
Example: Git Analysis
File:commands/git/recent-changes.md
Example: Test Generator
File:commands/generate-tests.md
Example: Dependency Analyzer
File:commands/analyze-deps.md
Advanced Patterns
Multiple Shell Commands
Conditional Logic
Complex Workflows
Best Practices
1. Clear Descriptions
2. Validate Input
Check for required arguments:3. Error Handling
Handle command failures gracefully:4. Helpful Output
Structure prompts for useful AI responses:5. Scope Appropriately
Limit shell command output:Command Organization
Group by Domain
Naming Conventions
- Use kebab-case:
analyze-deps.md - Be descriptive:
generate-unit-tests.mdnotgen.md - Use verbs:
review-code.md,search-todos.md
Migration from TOML
Older extensions used TOML format:Command Discovery
Users can discover commands through:[extension-name] in help output.
Testing Commands
During development:- Link your extension:
qwen extensions link . - Restart Qwen Code
- Try your commands
- Edit command files
- Restart to see changes (or use runtime hot-reload for some changes)
Next Steps
- Creating Extensions - Build a complete extension
- Skills - Create AI-invoked capabilities
- Agents - Build specialized assistants
- Best Practices - Extension development guidelines
