Skip to main content

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:
Available templates:
  • mcp-server - MCP server with example tools
  • commands - Custom command examples
  • skills - Skill examples
  • agent - Subagent examples
  • context - Context provider example

Manual Setup

To create an extension manually:

Step 1: Create the Extension Directory

Step 2: Create the Manifest File

Create qwen-extension.json:
Naming rules:
  • Use lowercase letters, numbers, and dashes only
  • No spaces or underscores
  • Must be unique among your installed extensions
  • Directory name should match the name field

Step 3: Add an MCP Server (Optional)

MCP servers provide tools the AI can use. Let’s create a simple server.

Create Package Files

Create package.json:
Create tsconfig.json:

Create the MCP Server

Create server.ts:

Update the Manifest

Update qwen-extension.json to reference the MCP server:
Variable substitution:
  • ${extensionPath} - Full path to extension directory
  • ${workspacePath} - Current workspace directory
  • ${/} or ${pathSeparator} - OS-specific path separator

Build the Server

This compiles server.ts to dist/server.js.

Step 4: Add Custom Commands (Optional)

Create a commands directory:
Create commands/utils/summarize.md:
Create commands/search.md:
Command naming:
  • 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:
Create skills/code-reviewer/SKILL.md:
Update qwen-extension.json:

Step 6: Add a Subagent (Optional)

Create an agents directory:
Create agents/test-writer.md:
Update qwen-extension.json:

Step 7: Add Context (Optional)

Create QWEN.md:
Update qwen-extension.json:

Step 8: Add Settings (Optional)

If your extension needs configuration, add settings:
Settings are:
  • Prompted during installation
  • Stored securely (sensitive values in system keychain)
  • Passed as environment variables to MCP servers
  • Manageable via qwen extensions settings command

Testing Your Extension

Create a symlink to your extension for development:
This allows you to test changes without reinstalling. However, you’ll need to restart Qwen Code sessions to see changes (except for runtime commands which hot-reload).

Test the Extension

Restart Qwen Code and try:
To remove the symlink:

Final Directory Structure

Your complete extension:

Next Steps