Building Plugins for Claude Code
Expert guidance for creating well-structured plugins, skills, hooks, agents, commands, and MCP configurations.
Core Principles (Anthropic Official)
- Composable - Multiple skills work together seamlessly, Claude coordinates automatically
- Portable - Same format works across Claude apps, Claude Code, and Claude API
- Efficient - Progressive disclosure loads only what's needed (description → SKILL.md → references)
- Powerful - Combines prompts + executable code for complete workflows
- Secure - Never hardcode secrets, use
${CLAUDE_PLUGIN_ROOT} for paths
Critical Budget Limits
| Limit |
Value |
Consequence if Exceeded |
| All skill descriptions combined |
15,000 chars |
Silent filtering, skills won't activate |
| Individual description |
1,024 chars |
Truncation |
| SKILL.md body |
5,000 words |
Context saturation, partial execution |
| Target per description |
300-400 chars |
Allows ~40 skills safely |
Plugin Structure
my-plugin/
├── plugin.json # Manifest (at root for marketplace plugins)
├── commands/ # Slash commands (.md files)
├── skills/ # Skills with SKILL.md
│ └── skill-name/
│ ├── SKILL.md
│ └── references/
├── agents/ # Sub-agents (.md files)
├── hooks/
│ └── hooks.json # Event handlers
├── .mcp.json # MCP servers
└── README.md
Quick Reference
plugin.json (Minimum)
{
"name": "plugin-name",
"version": "1.0.0",
"description": "What this plugin does"
}
SKILL.md Frontmatter
---
name: skill-name
description: Use when [trigger]. For [use cases].
allowed-tools: Read, Glob, Grep
model: sonnet
context: fork
user-invocable: true
---
Agent Frontmatter
---
name: agent-name
description: Expert in [domain]. Use for [tasks].
tools: [Read, Grep, Glob]
disallowedTools: [Write]
model: sonnet
permissionMode: default
color: blue
---
Command Frontmatter
---
description: What this command does
allowed-tools: Read, Write, Edit
argument-hint: "<required> [optional]"
---
Hook Configuration
{
"hooks": {
"PreToolUse": [{
"matcher": "Write|Edit",
"hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh" }]
}]
}
}
Detailed References
Load these for comprehensive documentation:
| Topic |
Reference |
| Plugin manifest, installation, validation |
references/plugin-reference.md |
| SKILL.md format, progressive disclosure, scoped hooks |
references/skills-reference.md |
| Agent configuration, permission modes, built-ins |
references/agents-reference.md |
| Slash command format, arguments, execution |
references/commands-reference.md |
| Hook events, matchers, response formats |
references/hooks-reference.md |
| MCP server types, CLI, configuration |
references/mcp-reference.md |
| Marketplace creation and distribution |
references/marketplace-reference.md |
Common Tasks
Creating a New Plugin
- Create directory with
plugin.json at root
- Add skills in
skills/skill-name/SKILL.md
- Add commands in
commands/command-name.md
- Test with
claude --plugin-dir ./my-plugin
- Validate with
claude plugin validate .
Creating a Skill
- Create
skills/my-skill/SKILL.md with frontmatter
- Write concise instructions (<500 lines)
- Add
references/ for detailed documentation
- Test by invoking
/my-skill
Adding Hooks
- Create
hooks/hooks.json
- Define event matchers and hook types
- Restart Claude Code (hooks load at session start)
Creating a Marketplace
- Create
.claude-plugin/marketplace.json at repo root
- Add plugins with
plugin.json at each plugin root
- Test:
/plugin marketplace add ./my-marketplace
Development Methodology (Anthropic Engineering)
Evaluation-First Approach:
- Run representative tasks WITHOUT skills first
- Observe where Claude struggles or requires additional context
- Build skills incrementally to address specific gaps
- Use Claude-assisted skill authoring (ask Claude to draft skills after successful workflows)
Self-Reflection Pattern:
After completing a task successfully, ask Claude:
"What worked well? Draft a SKILL.md that captures this workflow for next time."
Best Practices Checklist
1---2name: buildingplugins3description: Use when creating, developing, or troubleshooting Claude Code plugins, skills, hooks, agents, commands, or MCP servers. For questions like "How do I create a plugin?", "What goes in plugin.json?", "How do skills work?", "Create a hook", or "Help me build a marketplace".4---5
6# Building Plugins for Claude Code
7
8Expert guidance for creating well-structured plugins, skills, hooks, agents, commands, and MCP configurations.
9
10## Core Principles (Anthropic Official)
11
121. **Composable** - Multiple skills work together seamlessly, Claude coordinates automatically
132. **Portable** - Same format works across Claude apps, Claude Code, and Claude API
143. **Efficient** - Progressive disclosure loads only what's needed (description → SKILL.md → references)
154. **Powerful** - Combines prompts + executable code for complete workflows
165. **Secure** - Never hardcode secrets, use `${CLAUDE_PLUGIN_ROOT}` for paths
17
18## Critical Budget Limits
19
20| Limit | Value | Consequence if Exceeded |
21|-------|-------|------------------------|
22| All skill descriptions combined | 15,000 chars | Silent filtering, skills won't activate |
23| Individual description | 1,024 chars | Truncation |
24| SKILL.md body | 5,000 words | Context saturation, partial execution |
25| Target per description | 300-400 chars | Allows ~40 skills safely |
26
27## Plugin Structure
28
29```
30my-plugin/
31├── plugin.json # Manifest (at root for marketplace plugins)
32├── commands/ # Slash commands (.md files)
33├── skills/ # Skills with SKILL.md
34│ └── skill-name/
35│ ├── SKILL.md
36│ └── references/
37├── agents/ # Sub-agents (.md files)
38├── hooks/
39│ └── hooks.json # Event handlers
40├── .mcp.json # MCP servers
41└── README.md
42```
43
44## Quick Reference
45
46### plugin.json (Minimum)
47```json
48{
49 "name": "plugin-name",
50 "version": "1.0.0",
51 "description": "What this plugin does"
52}
53```
54
55### SKILL.md Frontmatter
56```yaml
57---
58name: skill-name
59description: Use when [trigger]. For [use cases].
60allowed-tools: Read, Glob, Grep
61model: sonnet
62context: fork
63user-invocable: true
64---
65```
66
67### Agent Frontmatter
68```yaml
69---
70name: agent-name
71description: Expert in [domain]. Use for [tasks].
72tools: [Read, Grep, Glob]
73disallowedTools: [Write]
74model: sonnet
75permissionMode: default
76color: blue
77---
78```
79
80### Command Frontmatter
81```yaml
82---
83description: What this command does
84allowed-tools: Read, Write, Edit
85argument-hint: "<required> [optional]"
86---
87```
88
89### Hook Configuration
90```json
91{
92 "hooks": {
93 "PreToolUse": [{
94 "matcher": "Write|Edit",
95 "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh" }]
96 }]
97 }
98}
99```
100
101## Detailed References
102
103Load these for comprehensive documentation:
104
105| Topic | Reference |
106|-------|-----------|
107| Plugin manifest, installation, validation | [references/plugin-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/plugin-reference.md) |
108| SKILL.md format, progressive disclosure, scoped hooks | [references/skills-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/skills-reference.md) |
109| Agent configuration, permission modes, built-ins | [references/agents-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/agents-reference.md) |
110| Slash command format, arguments, execution | [references/commands-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/commands-reference.md) |
111| Hook events, matchers, response formats | [references/hooks-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/hooks-reference.md) |
112| MCP server types, CLI, configuration | [references/mcp-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/mcp-reference.md) |
113| Marketplace creation and distribution | [references/marketplace-reference.md](${CLAUDE_PLUGIN_ROOT}/skills/buildingplugins/references/marketplace-reference.md) |
114
115## Common Tasks
116
117### Creating a New Plugin
1181. Create directory with `plugin.json` at root
1192. Add skills in `skills/skill-name/SKILL.md`
1203. Add commands in `commands/command-name.md`
1214. Test with `claude --plugin-dir ./my-plugin`
1225. Validate with `claude plugin validate .`
123
124### Creating a Skill
1251. Create `skills/my-skill/SKILL.md` with frontmatter
1262. Write concise instructions (<500 lines)
1273. Add `references/` for detailed documentation
1284. Test by invoking `/my-skill`
129
130### Adding Hooks
1311. Create `hooks/hooks.json`
1322. Define event matchers and hook types
1333. Restart Claude Code (hooks load at session start)
134
135### Creating a Marketplace
1361. Create `.claude-plugin/marketplace.json` at repo root
1372. Add plugins with `plugin.json` at each plugin root
1383. Test: `/plugin marketplace add ./my-marketplace`
139
140## Development Methodology (Anthropic Engineering)
141
142**Evaluation-First Approach:**
1431. Run representative tasks WITHOUT skills first
1442. Observe where Claude struggles or requires additional context
1453. Build skills incrementally to address specific gaps
1464. Use Claude-assisted skill authoring (ask Claude to draft skills after successful workflows)
147
148**Self-Reflection Pattern:**
149After completing a task successfully, ask Claude:
150> "What worked well? Draft a SKILL.md that captures this workflow for next time."
151
152## Best Practices Checklist
153
154- [ ] Plugin name is lowercase with hyphens, 3-64 characters
155- [ ] Description includes trigger phrases for auto-discovery
156- [ ] Description under 400 chars (not 1024 max) to preserve budget
157- [ ] Description uses third person voice
158- [ ] Secrets use environment variables, never hardcoded
159- [ ] Main files are concise, details in reference files
160- [ ] Uses `${CLAUDE_PLUGIN_ROOT}` for all internal paths
161- [ ] Semantic versioning (MAJOR.MINOR.PATCH)
162- [ ] README with examples
163- [ ] Tested with Haiku, Sonnet, and Opus
164- [ ] Skills trigger on expected phrases (test auto-activation)