Creating Your First Extension
This guide walks you through creating a complete Qwen Code extension from scratch. You’ll learn how to set up the project structure, add an MCP server with custom tools, create commands, and configure everything properly.Prerequisites
Before starting, ensure you have:- Qwen Code installed and working
- Node.js 20+ (if creating MCP servers)
- Basic understanding of TypeScript/JavaScript
- A text editor or IDE
Quick Start: Using Templates
The fastest way to start is using the built-in templates:mcp-server- MCP server with example toolscommands- Custom command examplesskills- Skill examplesagent- Subagent examplescontext- Context provider example
Manual Setup
To create an extension manually:Step 1: Create the Extension Directory
Step 2: Create the Manifest File
Createqwen-extension.json:
- Use lowercase letters, numbers, and dashes only
- No spaces or underscores
- Must be unique among your installed extensions
- Directory name should match the
namefield
Step 3: Add an MCP Server (Optional)
MCP servers provide tools the AI can use. Let’s create a simple server.Create Package Files
Createpackage.json:
tsconfig.json:
Create the MCP Server
Createserver.ts:
Update the Manifest
Updateqwen-extension.json to reference the MCP server:
${extensionPath}- Full path to extension directory${workspacePath}- Current workspace directory${/}or${pathSeparator}- OS-specific path separator
Build the Server
server.ts to dist/server.js.
Step 4: Add Custom Commands (Optional)
Create a commands directory:commands/utils/summarize.md:
commands/search.md:
- Top-level files:
/search - Nested files:
/utils:summarize - If conflicts exist:
/my-first-extension.search
Step 5: Add a Skill (Optional)
Create a skill directory:skills/code-reviewer/SKILL.md:
qwen-extension.json:
Step 6: Add a Subagent (Optional)
Create an agents directory:agents/test-writer.md:
qwen-extension.json:
Step 7: Add Context (Optional)
CreateQWEN.md:
qwen-extension.json:
Step 8: Add Settings (Optional)
If your extension needs configuration, add settings:- Prompted during installation
- Stored securely (sensitive values in system keychain)
- Passed as environment variables to MCP servers
- Manageable via
qwen extensions settingscommand
Testing Your Extension
Link for Development
Create a symlink to your extension for development:Test the Extension
Restart Qwen Code and try:Unlink When Done
To remove the symlink:Final Directory Structure
Your complete extension:Next Steps
- Publishing Your Extension - Share with others
- Best Practices - Extension development guidelines
- MCP Servers - Deep dive into MCP development
- Commands - Advanced command features
- Skills - Creating effective skills
- Agents - Building powerful subagents
