creating-a-plugin
Original:🇺🇸 English
Translated
Use when creating a new Claude Code plugin or setting up plugin structure - provides complete file organization, manifest format, and component definitions for commands, agents, skills, hooks, and MCP servers
1installs
Sourceed3dai/ed3d-plugins
Added on
NPX Install
npx skill4agent add ed3dai/ed3d-plugins creating-a-pluginTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Creating a Plugin
Overview
A Claude Code plugin packages reusable components (commands, agents, skills, hooks, MCP servers) for distribution. Create a plugin when you have components that work across multiple projects.
Don't create a plugin for:
- Project-specific configurations (use in project root)
.claude/ - One-off scripts or commands
- Experimental features still in development
Plugin storage locations:
- Development: Anywhere during development, installed via path
file:/// - User-level: (after installation)
~/.claude/plugins/ - Project-level: (project-specific installations)
.claude/plugins/
Quick Start Checklist
Minimal viable plugin:
- Create directory:
my-plugin/ - Create with at minimum:
.claude-plugin/plugin.jsonjson{ "name": "my-plugin" } - Add components (commands, agents, skills, hooks, or MCP servers)
- Test locally:
/plugin install file:///absolute/path/to/my-plugin - Reload:
/plugin reload
Directory Structure
my-plugin/
�� .claude-plugin/
�� plugin.json # Required: plugin manifest
�� commands/ # Optional: slash commands
�� my-command.md
�� agents/ # Optional: specialized subagents
�� my-agent.md
�� skills/ # Optional: reusable techniques
�� my-skill/
�� SKILL.md
�� hooks/ # Optional: event handlers
�� hooks.json
�� .mcp.json # Optional: MCP server configs
�� README.md # Recommended: documentationCritical: The directory with inside must exist at plugin root.
.claude-plugin/plugin.jsonComponent Reference
| Component | Location | File Format | When to Use |
|---|---|---|---|
| Commands | | Markdown + YAML frontmatter | Custom slash commands for repetitive tasks |
| Agents | | Markdown + YAML frontmatter | Specialized subagents for complex workflows |
| Skills | | Markdown + YAML frontmatter | Reusable techniques and patterns |
| Hooks | | JSON | Event handlers (format code, validate, etc.) |
| MCP Servers | | JSON | External tool integrations |
plugin.json Format
Minimal valid manifest:
json
{
"name": "my-plugin"
}Complete annotated manifest:
json
{
"name": "my-plugin", // Required: kebab-case identifier
"version": "1.0.0", // Recommended: semantic versioning
"description": "What this plugin does", // Recommended: brief description
"author": { // Optional but recommended
"name": "Your Name",
"email": "you@example.com",
"url": "https://github.com/yourname"
},
"homepage": "https://github.com/yourname/my-plugin",
"repository": "https://github.com/yourname/my-plugin",
"license": "MIT",
"keywords": ["productivity", "automation"],
"commands": [ // Optional: explicit command paths
"./commands/cmd1.md",
"./commands/cmd2.md"
],
"agents": [ // Optional: explicit agent paths
"./agents/agent1.md"
],
"hooks": [ // Optional: inline hooks
{
"event": "PostToolUse",
"matcher": "Edit|Write",
"command": "npx prettier --write \"$CLAUDE_FILE_PATHS\""
}
],
"mcpServers": { // Optional: inline MCP configs
"my-server": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/my-server",
"args": ["--port", "8080"],
"env": {
"API_KEY": "${API_KEY}"
}
}
}
}Key points:
- is required, everything else is optional
name - Use to reference plugin directory
${CLAUDE_PLUGIN_ROOT} - Commands/agents auto-discovered from and
commands/directories if not listed explicitlyagents/ - Skills auto-discovered from pattern
skills/*/SKILL.md
Creating Commands
File location: creates slash command
commands/my-command.md/my-commandNested commands: creates
commands/feature/sub-command.md/plugin-name:feature:sub-commandTemplate:
markdown
---
description: Brief description of what this command does
allowed-tools: Read, Grep, Glob, Bash
model: sonnet
argument-hint: "[file-path]"
---
# Command Name
Your command prompt goes here.
You can use:
- $1, $2, etc. for positional arguments
- $ARGUMENTS for all arguments as single string
- @filename to include file contents
- !bash command to execute shell commands
Example implementation instructions...Frontmatter fields:
- - Brief description shown in
description/help - - Comma-separated list:
allowed-toolsRead, Grep, Glob, Bash, Edit, Write, TodoWrite, Task - - Optional:
model,haiku, orsonnet(defaults to user's setting)opus - - Optional: shown in help text
argument-hint - - Optional:
disable-model-invocationto prevent auto-runtrue
Complete example ():
commands/review-pr.mdmarkdown
---
description: Review pull request for security and best practices
allowed-tools: Read, Grep, Glob, Bash
model: opus
argument-hint: "[pr-number]"
---
# Pull Request Review
Review pull request #$1 for:
1. Security vulnerabilities
2. Performance issues
3. Best practices compliance
4. Error handling
Steps:
1. Use Bash to run: gh pr diff $1
2. Use Read to examine changed files
3. Use Grep to search for common anti-patterns
4. Provide structured feedback with file:line references
Focus on critical issues first.Creating Agents
File location: creates agent named "code-reviewer"
agents/code-reviewer.mdTemplate:
markdown
---
name: agent-name
description: When and why to use this agent (critical for auto-delegation)
tools: Read, Edit, Write, Grep, Glob, Bash
model: opus
---
# Agent Name
Detailed instructions and system prompt for this agent.
## Responsibilities
- Task 1
- Task 2
## Tools Available
- Read: File operations
- Grep: Code search
- Bash: Shell commands
## Workflow
1. Step 1
2. Step 2Frontmatter fields:
- - Required: kebab-case identifier
name - - Required: Max 1024 chars, used for auto-delegation
description - - Comma-separated list of allowed tools
tools - - Optional:
model,haiku, orsonnetopus
Complete example ():
agents/security-auditor.mdmarkdown
---
name: security-auditor
description: Use when reviewing code for security vulnerabilities, analyzing authentication flows, or checking for common security anti-patterns like SQL injection, XSS, or insecure dependencies
tools: Read, Grep, Glob, Bash
model: opus
---
# Security Auditor Agent
You are a security expert specializing in web application security and secure coding practices.
## Your Responsibilities
1. Identify security vulnerabilities (SQL injection, XSS, CSRF, etc.)
2. Review authentication and authorization logic
3. Check for insecure dependencies
4. Verify input validation and sanitization
5. Review cryptographic implementations
## Workflow
1. **Scan for patterns:** Use Grep to find common vulnerability patterns
2. **Read suspicious code:** Use Read to examine flagged files
3. **Check dependencies:** Use Bash to run security audit tools
4. **Report findings:** Provide severity ratings and remediation steps
## Common Vulnerability Patterns
- SQL injection: String concatenation in queries
- XSS: Unescaped user input in templates
- CSRF: Missing CSRF tokens
- Auth bypass: Missing authorization checks
- Hardcoded secrets: API keys, passwords in code
## Reporting Format
For each finding:
- **Severity:** Critical/High/Medium/Low
- **Location:** `file:line`
- **Issue:** What's vulnerable
- **Impact:** What attacker could do
- **Fix:** How to remediateCreating Skills
REQUIRED SUB-SKILL: Use for complete guidance on skill structure, testing, and deployment.
writing-skillsSkills follow a specific structure.
File location:
skills/my-skill/SKILL.mdMinimal template:
markdown
---
name: my-skill-name
description: Use when [specific triggers] - [what it does]
---
# Skill Name
## Overview
Core principle in 1-2 sentences.
## When to Use
- Symptom 1
- Symptom 2
- When NOT to use
## Quick Reference
[Table or bullets for common operations]
## Implementation
[Code examples, patterns]
## Common Mistakes
[What goes wrong + fixes]Key principles:
- uses only letters, numbers, hyphens (no special chars)
name - starts with "Use when..." in third person
description - Keep token-efficient (<500 words if frequently loaded)
- One excellent example beats many mediocre ones
- Use skill for complete guidance
writing-skills
Creating Hooks
File location: or inline in
hooks/hooks.jsonplugin.jsonStandalone hooks file:
json
{
"hooks": [
{
"event": "PreToolUse",
"matcher": "Bash",
"command": "echo 'About to run: $CLAUDE_TOOL_NAME'"
},
{
"event": "PostToolUse",
"matcher": "Edit|Write",
"command": "npx prettier --write \"$CLAUDE_FILE_PATHS\""
},
{
"event": "SessionStart",
"matcher": "*",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/setup.sh"
}
]
}Hook events:
- - Before tool execution (can block)
PreToolUse - - After tool execution
PostToolUse - - When user submits prompt
UserPromptSubmit - - When Claude finishes responding
Stop - - Session initialization
SessionStart - - Session cleanup
SessionEnd - - On Claude Code notifications
Notification - - When subagent completes
SubagentStop - - Before context compaction
PreCompact
Matcher patterns:
- Specific tool:
"Bash" - Multiple tools:
"Edit|Write" - All tools:
"*"
Environment variables:
- - Event type
$CLAUDE_EVENT_TYPE - - Tool being used
$CLAUDE_TOOL_NAME - - Tool input (JSON)
$CLAUDE_TOOL_INPUT - - Space-separated file paths
$CLAUDE_FILE_PATHS
Creating MCP Server Configs
File location: at plugin root or inline in
.mcp.jsonplugin.jsonStandalone .mcp.json:
json
{
"mcpServers": {
"database-tools": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"],
"env": {
"DB_URL": "${DB_URL}",
"API_KEY": "${API_KEY:-default-key}"
}
},
"web-scraper": {
"command": "npx",
"args": ["web-mcp-server", "--port", "3000"]
}
}
}Configuration fields:
- - Executable path or command name
command - - Array of arguments
args - - Environment variables (supports
envor${VAR})${VAR:-default}
Special variable:
- - Resolves to plugin root directory
${CLAUDE_PLUGIN_ROOT}
Setting Up Dev Marketplace
For local development, create a marketplace to organize your plugins:
File:
dev-marketplace/.claude-plugin/marketplace.jsonjson
{
"$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
"name": "my-dev-marketplace",
"version": "1.0.0",
"owner": {
"name": "Your Name",
"email": "you@example.com"
},
"metadata": {
"description": "Local development marketplace for my plugins",
"pluginRoot": "./plugins"
},
"plugins": [
{
"name": "my-plugin-one",
"version": "1.0.0",
"description": "What this plugin does",
"source": "./plugins/my-plugin-one",
"category": "development",
"author": {
"name": "Your Name",
"email": "you@example.com"
}
},
{
"name": "my-plugin-two",
"version": "0.1.0",
"description": "Experimental plugin",
"source": "./plugins/my-plugin-two",
"category": "productivity",
"strict": false
}
]
}Directory structure:
dev-marketplace/
�� .claude-plugin/
�� marketplace.json
�� plugins/
�� my-plugin-one/
�� .claude-plugin/
�� plugin.json
�� commands/
�� my-plugin-two/
�� .claude-plugin/
�� plugin.json
�� agents/Install dev marketplace:
bash
/plugin marketplace add file:///absolute/path/to/dev-marketplace
/plugin browse
/plugin install my-plugin-one@my-dev-marketplacePlugin entry fields:
- - Required: plugin identifier
name - - Required: relative path or git URL
source - - Recommended: semantic version
version - - Recommended: brief description
description - - Optional: development, productivity, security, etc.
category - - Optional: author details
author - - Optional: default
strict(requires plugin.json), settrueto use marketplace entry as manifestfalse
Source formats:
json
// Local relative path
"source": "./plugins/my-plugin"
// GitHub repository
"source": {
"source": "github",
"repo": "owner/repo"
}
// Git URL
"source": {
"source": "url",
"url": "https://gitlab.com/team/plugin.git"
}Naming Conventions
Use kebab-case everywhere:
- Plugin names:
my-awesome-plugin - Command names:
review-code - Agent names:
security-auditor - Skill names:
test-driven-development
Filename mapping:
- �
commands/my-command.md/my-command - �
commands/project/build.md/plugin-name:project:build - � agent name
agents/code-reviewer.mdcode-reviewer - � skill name
skills/my-skill/SKILL.mdmy-skill
Testing Locally
Development workflow:
-
Create plugin structure:bash
mkdir -p my-plugin/.claude-plugin echo '{"name":"my-plugin"}' > my-plugin/.claude-plugin/plugin.json -
Add components (commands, agents, skills)
-
Install locally:bash
/plugin install file:///absolute/path/to/my-plugin -
Test functionality:bash
/my-command arg1 arg2 # Use Task tool with your agent # Use Skill tool with your skill -
Iterate:
- Edit plugin files
- Run
/plugin reload - Test again
Using dev marketplace:
- Create marketplace structure
- Add marketplace:
bash
/plugin marketplace add file:///absolute/path/to/dev-marketplace - Browse and install:
bash
/plugin browse /plugin install my-plugin@my-dev-marketplace
Common Mistakes
| Issue | Symptom | Fix |
|---|---|---|
Missing | Plugin not recognized | Create |
| Invalid plugin.json | Parse error on load | Validate JSON syntax, ensure |
| Wrong tool name | Tool not available in command/agent | Check spelling: |
| Description too long | Warning or truncation | Keep under 1024 characters total |
| Not using third person | Description sounds wrong | Use "Use when..." not "I will..." |
| Absolute paths in plugin.json | Breaks on other machines | Use relative paths or |
Forgetting | Changes not visible | Run |
| Command not found | Slash command doesn't work | Check filename matches expected command, reload plugin |
| Agent not auto-delegated | Agent never gets used | Improve |
Distribution
For production/team use:
- Push plugin to Git repository (GitHub, GitLab, etc.)
- Create or update team's marketplace repository
- Add plugin entry to marketplace.json
- Team members install:
bash
/plugin marketplace add user-or-org/marketplace-repo /plugin install plugin-name@marketplace-name
For public distribution:
Refer to official Claude Code documentation for publishing to public marketplaces.
Reference Links
- Official plugin docs: https://docs.claude.com/en/docs/claude-code/plugins
- Plugin reference: https://docs.claude.com/en/docs/claude-code/plugins-reference
- MCP servers: https://docs.claude.com/en/docs/claude-code/mcp-servers