Claude Code Plugin Reference Manual
Plugins are Claude Code'score of functional extension, helping you add capabilities such as custom slash commands, Subagents, and automated hooks. This tutorial approaches the topic fromCore Components、configuration specification、CLI managementthree dimensions, helping you quickly master the key points of plugin usage and development.
Core plugin components: 5 types of extension capabilities
Plugins achieve functional extension through 5 types of components, each with a fixed storage location and format requirements.
| Component types | Storage location | File format | Core Role |
|---|---|---|---|
| Command | Plugin root directory commands/ |
Markdown files with frontmatter | Add custom slash commands, such as /deploy /code-review |
| Proxy / agent | Plugin root directory agents/ |
Markdown file | Provide dedicated Subagents, such as code review agents and performance testing agents |
| Skills | Plugin root directory skills/ |
Contains SKILL.md directory |
Let Claude automatically recognize scenarios and invoke them, such as PDF parsing and data visualization |
| Hook | Plugin root directory hooks/hooks.json or plugin.json inline |
JSON configuration files | Listen for Claude events and respond automatically, such as auto-formatting code after file edits |
| MCP servers | Plugin root directory .mcp.json or plugin.json inline |
JSON configuration files | Connect external tools (such as GitHub, Jira) and turn their functionality into tools Claude can use |
| LSP Server | Plugin root directory .lsp.json or plugin.json inline |
JSON configuration files | Provide code intelligence capabilities, such as syntax checking, go-to-definition, and hover hints |
Key component examples
1. Hook configuration example: auto-format after file edits
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/format-code.sh"
}
]
}
]
}
}
{
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go"
}
}
}
Plugin fundamentals: installation scope and manifest
1. Installation scope: determines a plugin's availability
When installing a plugin, you must choose a scope; different scopes correspond to different configuration files and use cases:
| Range | Configuration file paths | Applicable scenarios |
|---|---|---|
user |
~/.claude/settings.json |
Personal, common to all projects (default) |
project |
.claude/settings.json |
Shared with the team, synced with the repository |
local |
.claude/settings.local.json |
Project-specific, governed by .gitignore Ignore |
managed |
managed-settings.json |
Managed plugin, read-only and auto-updated |
2. Plugin manifest:plugin.json Key points to know
plugin.json is the plugin'sCore configuration file, stored in the .claude-plugin/ directory, used to define plugin metadata and component paths.
a. Required fields
| Field | Type | Requirement | Example |
|---|---|---|---|
name |
string | Unique identifier, in kebab-case format | "go-code-helper" |
b. Core metadata fields
{
"version": "1.0.0", // 语义化版本
"description": "提供 Go 语言代码智能和调试能力",
"author": {
"name": "Dev Team",
"email": "dev@example.com"
},
"license": "MIT"
}
c. Component path fields
Used to specify the locations of custom components; paths mustRelative to the plugin root directoryand starting with ./ at the beginning:
{
"commands": ["./custom-commands/deploy.md"],
"agents": "./custom-agents/",
"hooks": "./hooks.json"
}
d. Environment variables
${CLAUDE_PLUGIN_ROOT}: The absolute path of the plugin root directory, used to reference files within the plugin in scripts and configurations to avoid path errors.
3. Standard plugin directory structure
my-plugin/
├── .claude-plugin/ # 元数据目录
│ └── plugin.json # 插件清单(必需)
├── commands/ # 自定义斜杠命令
├── agents/ # 子代理定义
├── skills/ # 自动技能
├── hooks/ # 事件钩子配置
├── .mcp.json # MCP 服务器配置
├── .lsp.json # LSP 服务器配置
└── scripts/ # 钩子执行脚本
Note:
commands/agents/and other component directories must be inside the pluginRoot Directory, cannot be placed in.claude-plugin/directory.
Plugin Management: CLI Command Quick Reference
Through the Claude Code CLI you can quickly install, uninstall, enable/disable plugins and more, making it suitable for scripts and automation scenarios.
| Command | Purpose | Example |
|---|---|---|
claude plugin install <插件名> -s <范围> |
Install plugins | claude plugin install go-lsp --scope project |
claude plugin uninstall <插件名> |
Uninstall plugin | claude plugin uninstall go-lsp |
claude plugin enable <插件名> |
Enable a disabled plugin | claude plugin enable go-lsp |
claude plugin disable <插件名> |
Disable plugin (without uninstalling) | claude plugin disable go-lsp |
claude plugin update <插件名> |
Update plugin to latest version | claude plugin update go-lsp |
Debugging and Troubleshooting: Common Problem Solutions
1. Debug commands
Run the following command to view plugin loading details and locate configuration and loading issues:
claude --debug
You can view: plugin loading status, manifest syntax errors, component registration, MCP/LSP server initialization logs.
2. High-frequency problems and solutions
| Problem | Reason | Solution |
|---|---|---|
| Plugin not loaded | plugin.json Syntax error or missing required fields |
Using claude plugin validate Verify JSON syntax, supplement name Field |
| Custom commands not showing | Command files placed in .claude-plugin/ block. |
data to the child component via commands/ directory move to plugin root directory |
| Hook scripts not executing | Script lacks executable permission | Run chmod +x scripts/your-script.sh Grant permission |
LSP prompt Executable not found |
Corresponding language server not installed | Install the binary (e.g., Go requires installing gopls) |
| MCP server fails to start | Path uses an absolute path, not ${CLAUDE_PLUGIN_ROOT} |
Replace with environment variable reference, e.g. ${CLAUDE_PLUGIN_ROOT}/server |
Version Management and Distribution
- Version specification: Follow semantic versioning
MAJOR.MINOR.PATCH, for example1.2.3 - Distribution channels: Distribute through the plugin marketplace, or directly share the plugin directory (must include the complete structure)
- Changelog: It is recommended to add in the plugin root directory
CHANGELOG.md, recording version update content