Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Directory structure and conventions for building Claude Code plugins (from the official Anthropic claude-code repo).
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: Plugin Structure3description: This skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.4version: 0.1.05---67# Plugin Structure for Claude Code89## Overview1011Claude Code plugins follow a standardized directory structure with automatic component discovery. Understanding this structure enables creating well-organized, maintainable plugins that integrate seamlessly with Claude Code.1213**Key concepts:**14- Conventional directory layout for automatic discovery15- Manifest-driven configuration in `.claude-plugin/plugin.json`16- Component-based organization (commands, agents, skills, hooks)17- Portable path references using `${CLAUDE_PLUGIN_ROOT}`18- Explicit vs. auto-discovered component loading1920## Directory Structure2122Every Claude Code plugin follows this organizational pattern:2324```25plugin-name/26├── .claude-plugin/27│ └── plugin.json # Required: Plugin manifest28├── commands/ # Slash commands (.md files)29├── agents/ # Subagent definitions (.md files)30├── skills/ # Agent skills (subdirectories)31│ └── skill-name/32│ └── SKILL.md # Required for each skill33├── hooks/34│ └── hooks.json # Event handler configuration35├── .mcp.json # MCP server definitions36└── scripts/ # Helper scripts and utilities37```3839**Critical rules:**40411. **Manifest location**: The `plugin.json` manifest MUST be in `.claude-plugin/` directory422. **Component locations**: All component directories (commands, agents, skills, hooks) MUST be at plugin root level, NOT nested inside `.claude-plugin/`433. **Optional components**: Only create directories for components the plugin actually uses444. **Naming convention**: Use kebab-case for all directory and file names4546## Plugin Manifest (plugin.json)4748The manifest defines plugin metadata and configuration. Located at `.claude-plugin/plugin.json`:4950### Required Fields5152```json53{54"name": "plugin-name"55}56```5758**Name requirements:**59- Use kebab-case format (lowercase with hyphens)60- Must be unique across installed plugins61- No spaces or special characters62- Example: `code-review-assistant`, `test-runner`, `api-docs`6364### Recommended Metadata6566```json67{68"name": "plugin-name",69"version": "1.0.0",70"description": "Brief explanation of plugin purpose",71"author": {72"name": "Author Name",73"email": "[email protected]",74"url": "https://example.com"75},76"homepage": "https://docs.example.com",77"repository": "https://github.com/user/plugin-name",78"license": "MIT",79"keywords": ["testing", "automation", "ci-cd"]80}81```8283**Version format**: Follow semantic versioning (MAJOR.MINOR.PATCH)84**Keywords**: Use for plugin discovery and categorization8586### Component Path Configuration8788Specify custom paths for components (supplements default directories):8990```json91{92"name": "plugin-name",93"commands": "./custom-commands",94"agents": ["./agents", "./specialized-agents"],95"hooks": "./config/hooks.json",96"mcpServers": "./.mcp.json"97}98```99100**Important**: Custom paths supplement defaults—they don't replace them. Components in both default directories and custom paths will load.101102**Path rules:**103- Must be relative to plugin root104- Must start with `./`105- Cannot use absolute paths106- Support arrays for multiple locations107108## Component Organization109110### Commands111112**Location**: `commands/` directory113**Format**: Markdown files with YAML frontmatter114**Auto-discovery**: All `.md` files in `commands/` load automatically115116**Example structure**:117```118commands/119├── review.md # /review command120├── test.md # /test command121└── deploy.md # /deploy command122```123124**File format**:125```markdown126---127name: command-name128description: Command description129---130131Command implementation instructions...132```133134**Usage**: Commands integrate as native slash commands in Claude Code135136### Agents137138**Location**: `agents/` directory139**Format**: Markdown files with YAML frontmatter140**Auto-discovery**: All `.md` files in `agents/` load automatically141142**Example structure**:143```144agents/145├── code-reviewer.md146├── test-generator.md147└── refactorer.md148```149150**File format**:151```markdown152---153description: Agent role and expertise154capabilities:155- Specific task 1156- Specific task 2157---158159Detailed agent instructions and knowledge...160```161162**Usage**: Users can invoke agents manually, or Claude Code selects them automatically based on task context163164### Skills165166**Location**: `skills/` directory with subdirectories per skill167**Format**: Each skill in its own directory with `SKILL.md` file168**Auto-discovery**: All `SKILL.md` files in skill subdirectories load automatically169170**Example structure**:171```172skills/173├── api-testing/174│ ├── SKILL.md175│ ├── scripts/176│ │ └── test-runner.py177│ └── references/178│ └── api-spec.md179└── database-migrations/180├── SKILL.md181└── examples/182└── migration-template.sql183```184185**SKILL.md format**:186```markdown187---188name: Skill Name189description: When to use this skill190version: 1.0.0191---192193Skill instructions and guidance...194```195196**Supporting files**: Skills can include scripts, references, examples, or assets in subdirectories197198**Usage**: Claude Code autonomously activates skills based on task context matching the description199200### Hooks201202**Location**: `hooks/hooks.json` or inline in `plugin.json`203**Format**: JSON configuration defining event handlers204**Registration**: Hooks register automatically when plugin enables205206**Example structure**:207```208hooks/209├── hooks.json # Hook configuration210└── scripts/211├── validate.sh # Hook script212└── check-style.sh # Hook script213```214215**Configuration format**:216```json217{218"PreToolUse": [{219"matcher": "Write|Edit",220"hooks": [{221"type": "command",222"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/validate.sh",223"timeout": 30224}]225}]226}227```228229**Available events**: PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification230231**Usage**: Hooks execute automatically in response to Claude Code events232233### MCP Servers234235**Location**: `.mcp.json` at plugin root or inline in `plugin.json`236**Format**: JSON configuration for MCP server definitions237**Auto-start**: Servers start automatically when plugin enables238239**Example format**:240```json241{242"mcpServers": {243"server-name": {244"command": "node",245"args": ["${CLAUDE_PLUGIN_ROOT}/servers/server.js"],246"env": {247"API_KEY": "${API_KEY}"248}249}250}251}252```253254**Usage**: MCP servers integrate seamlessly with Claude Code's tool system255256## Portable Path References257258### ${CLAUDE_PLUGIN_ROOT}259260Use `${CLAUDE_PLUGIN_ROOT}` environment variable for all intra-plugin path references:261262```json263{264"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/run.sh"265}266```267268**Why it matters**: Plugins install in different locations depending on:269- User installation method (marketplace, local, npm)270- Operating system conventions271- User preferences272273**Where to use it**:274- Hook command paths275- MCP server command arguments276- Script execution references277- Resource file paths278279**Never use**:280- Hardcoded absolute paths (`/Users/name/plugins/...`)281- Relative paths from working directory (`./scripts/...` in commands)282- Home directory shortcuts (`~/plugins/...`)283284### Path Resolution Rules285286**In manifest JSON fields** (hooks, MCP servers):287```json288"command": "${CLAUDE_PLUGIN_ROOT}/scripts/tool.sh"289```290291**In component files** (commands, agents, skills):292```markdown293Reference scripts at: ${CLAUDE_PLUGIN_ROOT}/scripts/helper.py294```295296**In executed scripts**:297```bash298#!/bin/bash299# ${CLAUDE_PLUGIN_ROOT} available as environment variable300source "${CLAUDE_PLUGIN_ROOT}/lib/common.sh"301```302303## File Naming Conventions304305### Component Files306307**Commands**: Use kebab-case `.md` files308- `code-review.md` → `/code-review`309- `run-tests.md` → `/run-tests`310- `api-docs.md` → `/api-docs`311312**Agents**: Use kebab-case `.md` files describing role313- `test-generator.md`314- `code-reviewer.md`315- `performance-analyzer.md`316317**Skills**: Use kebab-case directory names318- `api-testing/`319- `database-migrations/`320- `error-handling/`321322### Supporting Files323324**Scripts**: Use descriptive kebab-case names with appropriate extensions325- `validate-input.sh`326- `generate-report.py`327- `process-data.js`328329**Documentation**: Use kebab-case markdown files330- `api-reference.md`331- `migration-guide.md`332- `best-practices.md`333334**Configuration**: Use standard names335- `hooks.json`336- `.mcp.json`337- `plugin.json`338339## Auto-Discovery Mechanism340341Claude Code automatically discovers and loads components:3423431. **Plugin manifest**: Reads `.claude-plugin/plugin.json` when plugin enables3442. **Commands**: Scans `commands/` directory for `.md` files3453. **Agents**: Scans `agents/` directory for `.md` files3464. **Skills**: Scans `skills/` for subdirectories containing `SKILL.md`3475. **Hooks**: Loads configuration from `hooks/hooks.json` or manifest3486. **MCP servers**: Loads configuration from `.mcp.json` or manifest349350**Discovery timing**:351- Plugin installation: Components register with Claude Code352- Plugin enable: Components become available for use353- No restart required: Changes take effect on next Claude Code session354355**Override behavior**: Custom paths in `plugin.json` supplement (not replace) default directories356357## Best Practices358359### Organization3603611. **Logical grouping**: Group related components together362- Put test-related commands, agents, and skills together363- Create subdirectories in `scripts/` for different purposes3643652. **Minimal manifest**: Keep `plugin.json` lean366- Only specify custom paths when necessary367- Rely on auto-discovery for standard layouts368- Use inline configuration only for simple cases3693703. **Documentation**: Include README files371- Plugin root: Overall purpose and usage372- Component directories: Specific guidance373- Script directories: Usage and requirements374375### Naming3763771. **Consistency**: Use consistent naming across components378- If command is `test-runner`, name related agent `test-runner-agent`379- Match skill directory names to their purpose3803812. **Clarity**: Use descriptive names that indicate purpose382- Good: `api-integration-testing/`, `code-quality-checker.md`383- Avoid: `utils/`, `misc.md`, `temp.sh`3843853. **Length**: Balance brevity with clarity386- Commands: 2-3 words (`review-pr`, `run-ci`)387- Agents: Describe role clearly (`code-reviewer`, `test-generator`)388- Skills: Topic-focused (`error-handling`, `api-design`)389390### Portability3913921. **Always use ${CLAUDE_PLUGIN_ROOT}**: Never hardcode paths3932. **Test on multiple systems**: Verify on macOS, Linux, Windows3943. **Document dependencies**: List required tools and versions3954. **Avoid system-specific features**: Use portable bash/Python constructs396397### Maintenance3983991. **Version consistently**: Update version in plugin.json for releases4002. **Deprecate gracefully**: Mark old components clearly before removal4013. **Document breaking changes**: Note changes affecting existing users4024. **Test thoroughly**: Verify all components work after changes403404## Common Patterns405406### Minimal Plugin407408Single command with no dependencies:409```410my-plugin/411├── .claude-plugin/412│ └── plugin.json # Just name field413└── commands/414└── hello.md # Single command415```416417### Full-Featured Plugin418419Complete plugin with all component types:420```421my-plugin/422├── .claude-plugin/423│ └── plugin.json424├── commands/ # User-facing commands425├── agents/ # Specialized subagents426├── skills/ # Auto-activating skills427├── hooks/ # Event handlers428│ ├── hooks.json429│ └── scripts/430├── .mcp.json # External integrations431└── scripts/ # Shared utilities432```433434### Skill-Focused Plugin435436Plugin providing only skills:437```438my-plugin/439├── .claude-plugin/440│ └── plugin.json441└── skills/442├── skill-one/443│ └── SKILL.md444└── skill-two/445└── SKILL.md446```447448## Troubleshooting449450**Component not loading**:451- Verify file is in correct directory with correct extension452- Check YAML frontmatter syntax (commands, agents, skills)453- Ensure skill has `SKILL.md` (not `README.md` or other name)454- Confirm plugin is enabled in Claude Code settings455456**Path resolution errors**:457- Replace all hardcoded paths with `${CLAUDE_PLUGIN_ROOT}`458- Verify paths are relative and start with `./` in manifest459- Check that referenced files exist at specified paths460- Test with `echo $CLAUDE_PLUGIN_ROOT` in hook scripts461462**Auto-discovery not working**:463- Confirm directories are at plugin root (not in `.claude-plugin/`)464- Check file naming follows conventions (kebab-case, correct extensions)465- Verify custom paths in manifest are correct466- Restart Claude Code to reload plugin configuration467468**Conflicts between plugins**:469- Use unique, descriptive component names470- Namespace commands with plugin name if needed471- Document potential conflicts in plugin README472- Consider command prefixes for related functionality473474---475476For detailed examples and advanced patterns, see files in `references/` and `examples/` directories.477