Plugin System

Use Claude Code plugin system to create custom commands, agents, and workflows

Plugin SystemΒΆ

The Claude Code plugin system allows you to extend Claude's capabilities by creating custom slash commands, specialized agents, reusable skills, and automation hooks. With plugins, you can codify your team's best practices and workflows.

What are Plugins?ΒΆ

Core ConceptsΒΆ

A Claude Code plugin is a directory with a specific file structure that can add the following components:

Component Description File Format
Commands Custom slash commands .md files
Agents Specialized task subagents .md files
Skills Reusable knowledge and capabilities Directory + SKILL.md
Hooks Event-triggered automation hooks.json

Why Plugins?ΒΆ

  • Team standardization: Encode coding standards and review criteria as executable commands

  • Workflow automation: Automate repetitive tasks like commits, deployments, reviews

  • Knowledge sharing: Share best practices and expertise across team members

  • Custom experience: Customize Claude's behavior for project needs

Plugin Directory StructureΒΆ

my-plugin/
β”œβ”€β”€ .claude-plugin/
β”‚   └── plugin.json          # Required: Plugin manifest
β”œβ”€β”€ commands/                 # Slash commands (.md files)
β”‚   β”œβ”€β”€ review.md
β”‚   └── deploy.md
β”œβ”€β”€ agents/                   # Subagent definitions (.md files)
β”‚   └── code-reviewer.md
β”œβ”€β”€ skills/                   # Agent skills (subdirectories)
β”‚   └── coding-standards/
β”‚       └── SKILL.md
β”œβ”€β”€ hooks/
β”‚   └── hooks.json           # Event handler configuration
β”œβ”€β”€ .mcp.json                # MCP server definitions (optional)
└── scripts/                 # Helper scripts (optional)

Quick StartΒΆ

Install PluginsΒΆ

# Install from marketplace
/plugin install plugin-name@claude-code-marketplace

# Install from local directory
claude --plugin-dir /path/to/my-plugin

Use Plugin Creation WizardΒΆ

/plugin-dev:create-plugin

This command guides you through 8 phases to create a complete plugin.

Creating Custom CommandsΒΆ

Basic Command FormatΒΆ

Create .md files in the commands/ directory:

---
description: Perform code review
argument-hint: [file-path]
allowed-tools: Read, Bash(git:*)
---

Please review the code quality of: @$1

Focus on:
1. Code readability
2. Potential bugs
3. Performance issues
4. Security vulnerabilities

YAML Frontmatter ConfigurationΒΆ

Field Description Example
description Command description (shown in /help) Perform code review
argument-hint Parameter hints [file-path] [options]
allowed-tools Permitted tools Read, Bash(git:*)
model Specify model opus or sonnet

Using Dynamic ArgumentsΒΆ

  • $1, $2, $3... - Positional arguments

  • $ARGUMENTS - All arguments

  • @path/to/file - File reference

  • !command`` - Execute Bash command

Command ExamplesΒΆ

Code Review Command (commands/review.md):

---
description: Comprehensive code review
argument-hint: [file-or-directory]
allowed-tools: Read, Grep, Glob
model: opus
---

Perform a comprehensive code review of @$1.

Checklist:

- [ ] Code style follows project standards
- [ ] No potential security issues
- [ ] Error handling is complete
- [ ] Tests are needed

If it's a directory, first use Glob tool to find all relevant files.

Smart Commit Command (commands/commit.md):

---
description: Smart commit with generated message
allowed-tools: Bash(git:*)
---

1. Run `git status` to see changes
2. Run `git diff --staged` to analyze staged changes
3. Generate a conventional commit message based on changes
4. Execute `git commit`

Commit message format:

- feat: New feature
- fix: Bug fix
- docs: Documentation update
- refactor: Refactoring
- test: Test related

Creating Custom AgentsΒΆ

Agent Definition FormatΒΆ

Create .md files in the agents/ directory:

---
description: Specialized code review agent
model: opus
tools: Read, Grep, Glob
---

You are a professional code review agent. Your task is to:

1. Carefully read the provided code
2. Identify potential issues
3. Provide specific improvement suggestions
4. Focus on security and performance

Always be constructive and specific.

Agent TypesΒΆ

Type Purpose Example
Review Agent Code review, PR review code-reviewer
Test Agent Generate and run tests test-generator
Doc Agent Generate documentation doc-writer
Refactor Agent Code refactoring refactorer

Creating SkillsΒΆ

Skill Directory StructureΒΆ

skills/
└── coding-standards/
    β”œβ”€β”€ SKILL.md              # Required: Skill definition
    β”œβ”€β”€ references/           # Reference materials
    β”‚   └── style-guide.md
    └── examples/             # Example code
        └── good-practices.md

SKILL.md FormatΒΆ

# Coding Standards Skill

## Overview
This skill contains team coding standards and best practices.

## Knowledge Content

### Naming Conventions

- Variables: camelCase
- Constants: UPPER_SNAKE_CASE
- Classes: PascalCase
- Files: kebab-case

### Code Style

- Use 2-space indentation
- Max line width 100 characters
- Use semicolons

### Error Handling

- Always use try-catch
- Log errors
- Provide meaningful error messages

Creating HooksΒΆ

hooks.json FormatΒΆ

{
  "hooks": [
    {
      "event": "on_commit",
      "command": "npm run lint",
      "description": "Run lint check before commit"
    },
    {
      "event": "on_file_change",
      "pattern": "*.ts",
      "command": "npm run typecheck",
      "description": "Type check when TypeScript files change"
    }
  ]
}

Supported EventsΒΆ

Event Triggered When
on_commit Committing code
on_file_change File changes
on_session_start Session starts
on_command Command execution

Plugin ManifestΒΆ

plugin.json FormatΒΆ

{
  "name": "my-plugin",
  "version": "1.0.0",
  "description": "My custom plugin",
  "author": "Your Name",
  "components": {
    "commands": ["commands/*.md"],
    "agents": ["agents/*.md"],
    "skills": ["skills/*/SKILL.md"],
    "hooks": "hooks/hooks.json"
  },
  "mcpServers": ".mcp.json"
}

Practical ExamplesΒΆ

Example 1: Team Code Review PluginΒΆ

team-review-plugin/
β”œβ”€β”€ .claude-plugin/
β”‚   └── plugin.json
β”œβ”€β”€ commands/
β”‚   β”œβ”€β”€ review-pr.md          # PR review command
β”‚   β”œβ”€β”€ security-check.md     # Security check command
β”‚   └── perf-audit.md         # Performance audit command
β”œβ”€β”€ agents/
β”‚   β”œβ”€β”€ security-reviewer.md  # Security review agent
β”‚   └── perf-analyzer.md      # Performance analysis agent
└── skills/
    └── team-standards/
        └── SKILL.md          # Team standards skill

Example 2: Deployment Automation PluginΒΆ

deploy-plugin/
β”œβ”€β”€ .claude-plugin/
β”‚   └── plugin.json
β”œβ”€β”€ commands/
β”‚   β”œβ”€β”€ deploy-staging.md     # Deploy to staging
β”‚   β”œβ”€β”€ deploy-prod.md        # Deploy to production
β”‚   └── rollback.md           # Rollback command
β”œβ”€β”€ hooks/
β”‚   └── hooks.json            # Pre-deploy check hooks
└── .mcp.json                 # Kubernetes MCP config

Best PracticesΒΆ

Command DesignΒΆ

  1. Single responsibility: Each command does one thing

  2. Clear descriptions: Keep description concise

  3. Document parameters: Use argument-hint to explain parameters

  4. Minimal permissions: Only include necessary tools in allowed-tools

  5. Error handling: Consider failure scenarios

Plugin OrganizationΒΆ

  1. Modular: Organize related functionality together

  2. Reusable: Skills should be usable by multiple commands

  3. Documented: Add README and usage instructions

  4. Versioned: Use semantic versioning

Security ConsiderationsΒΆ

  1. No hardcoded secrets: Use environment variables

  2. Limit file access: Only access necessary paths

  3. Validate input: Validate parameters

  4. Audit logs: Log sensitive operations

Debugging PluginsΒΆ

# View plugin load status
/plugin list

# View command details
/help my-command

# Test command
/my-command test-argument

Next StepsΒΆ

πŸš€
Get Started with QCode β€” Claude Code & Codex
One plan for both Claude Code and Codex, Asia-Pacific low latency
View Pricing Plans β†’ Create Account
Team of 3+?
Enterprise: dedicated domain + sub-key management + ban protection, from Β₯250/person/mo
Learn Enterprise β†’