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ΒΆ
-
Single responsibility: Each command does one thing
-
Clear descriptions: Keep description concise
-
Document parameters: Use argument-hint to explain parameters
-
Minimal permissions: Only include necessary tools in allowed-tools
-
Error handling: Consider failure scenarios
Plugin OrganizationΒΆ
-
Modular: Organize related functionality together
-
Reusable: Skills should be usable by multiple commands
-
Documented: Add README and usage instructions
-
Versioned: Use semantic versioning
Security ConsiderationsΒΆ
-
No hardcoded secrets: Use environment variables
-
Limit file access: Only access necessary paths
-
Validate input: Validate parameters
-
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ΒΆ
-
Learn about MCP Servers to extend external integrations
-
Check CLI Tips to boost efficiency
-
Explore Workflow Tips to optimize development flow