Skip to main content

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)

Currently, only description is supported.

Template Variables

Use {{args}} to insert user-provided arguments:
Invoked as: /search "TODO"

Shell Command Execution

Execute shell commands and include their output:
Important: The shell command output is included in the prompt, not executed by the AI. Use this to gather information before sending to the AI.

Extension Structure

Place command files in a commands/ directory:

Configure in Manifest

Update qwen-extension.json:
The 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:
Extension commands have the lowest precedence. The extension name is automatically prefixed when conflicts occur.

Example: Search and Summarize

From the built-in examples: File: commands/fs/grep-code.md
Usage:

Example: File Summarizer

File: commands/summarize.md
Usage:

Example: Code Review

File: commands/review.md
Usage:

Example: Git Analysis

File: commands/git/recent-changes.md
Usage:

Example: Test Generator

File: commands/generate-tests.md
Usage:

Example: Dependency Analyzer

File: commands/analyze-deps.md
Usage:

Advanced Patterns

Multiple Shell Commands

Conditional Logic

Complex Workflows

Best Practices

1. Clear Descriptions

Be specific about what the command does.

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:
Large outputs can exceed context limits.

Command Organization

Group by Domain

Naming Conventions

  • Use kebab-case: analyze-deps.md
  • Be descriptive: generate-unit-tests.md not gen.md
  • Use verbs: review-code.md, search-todos.md

Migration from TOML

Older extensions used TOML format:
TOML files are still supported but deprecated. Qwen Code will prompt you to migrate when detected. Markdown is now the standard format and is much simpler to work with.

Command Discovery

Users can discover commands through:
Extension commands are marked with [extension-name] in help output.

Testing Commands

During development:
  1. Link your extension: qwen extensions link .
  2. Restart Qwen Code
  3. Try your commands
  4. Edit command files
  5. Restart to see changes (or use runtime hot-reload for some changes)

Next Steps