plugin-structure by anthropics/claude-plugins-official
npx skills add https://github.com/anthropics/claude-plugins-official --skill plugin-structureClaude Code 插件遵循标准化的目录结构,支持自动组件发现。理解此结构有助于创建组织良好、易于维护且能与 Claude Code 无缝集成的插件。
核心概念:
.claude-plugin/plugin.json 中进行清单驱动的配置${CLAUDE_PLUGIN_ROOT} 实现可移植的路径引用每个 Claude Code 插件都遵循以下组织模式:
plugin-name/
├── .claude-plugin/
│ └── plugin.json # 必需:插件清单
├── commands/ # 斜杠命令(.md 文件)
├── agents/ # 子智能体定义(.md 文件)
├── skills/ # 智能体技能(子目录)
│ └── skill-name/
│ └── SKILL.md # 每个技能必需的文件
├── hooks/
│ └── hooks.json # 事件处理器配置
├── .mcp.json # MCP 服务器定义
└── scripts/ # 辅助脚本和实用工具
关键规则:
plugin.json 清单文件位于 目录中广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
.claude-plugin/.claude-plugin/ 内部清单定义了插件的元数据和配置。位于 .claude-plugin/plugin.json:
{
"name": "plugin-name"
}
名称要求:
code-review-assistant、test-runner、api-docs{
"name": "plugin-name",
"version": "1.0.0",
"description": "插件用途的简要说明",
"author": {
"name": "作者姓名",
"email": "author@example.com",
"url": "https://example.com"
},
"homepage": "https://docs.example.com",
"repository": "https://github.com/user/plugin-name",
"license": "MIT",
"keywords": ["testing", "automation", "ci-cd"]
}
版本格式 :遵循语义化版本控制(MAJOR.MINOR.PATCH) 关键词 :用于插件发现和分类
为组件指定自定义路径(补充默认目录):
{
"name": "plugin-name",
"commands": "./custom-commands",
"agents": ["./agents", "./specialized-agents"],
"hooks": "./config/hooks.json",
"mcpServers": "./.mcp.json"
}
重要 :自定义路径补充默认路径——它们不会替换默认路径。位于默认目录和自定义路径中的组件都会被加载。
路径规则:
./ 开头位置 :commands/ 目录 格式 :带有 YAML 前置元数据的 Markdown 文件 自动发现 :commands/ 目录中的所有 .md 文件都会自动加载
示例结构:
commands/
├── review.md # /review 命令
├── test.md # /test 命令
└── deploy.md # /deploy 命令
文件格式:
---
name: command-name
description: 命令描述
---
命令实现说明...
用法 :命令作为原生斜杠命令集成到 Claude Code 中
位置 :agents/ 目录 格式 :带有 YAML 前置元数据的 Markdown 文件 自动发现 :agents/ 目录中的所有 .md 文件都会自动加载
示例结构:
agents/
├── code-reviewer.md
├── test-generator.md
└── refactorer.md
文件格式:
---
description: 智能体的角色和专长
capabilities:
- 具体任务 1
- 具体任务 2
---
详细的智能体指令和知识...
用法 :用户可以手动调用智能体,或者 Claude Code 根据任务上下文自动选择它们
位置 :skills/ 目录,每个技能在其自己的子目录中 格式 :每个技能在其自己的目录中包含 SKILL.md 文件 自动发现 :技能子目录中的所有 SKILL.md 文件都会自动加载
示例结构:
skills/
├── api-testing/
│ ├── SKILL.md
│ ├── scripts/
│ │ └── test-runner.py
│ └── references/
│ └── api-spec.md
└── database-migrations/
├── SKILL.md
└── examples/
└── migration-template.sql
SKILL.md 格式:
---
name: 技能名称
description: 何时使用此技能
version: 1.0.0
---
技能指令和指导...
支持文件 :技能可以在子目录中包含脚本、参考资料、示例或资源文件
用法 :Claude Code 根据任务上下文与技能描述的匹配情况,自动激活技能
位置 :hooks/hooks.json 或内联在 plugin.json 中 格式 :定义事件处理器的 JSON 配置 注册 :插件启用时,钩子会自动注册
示例结构:
hooks/
├── hooks.json # 钩子配置
└── scripts/
├── validate.sh # 钩子脚本
└── check-style.sh # 钩子脚本
配置格式:
{
"PreToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/validate.sh",
"timeout": 30
}]
}]
}
可用事件 :PreToolUse、PostToolUse、Stop、SubagentStop、SessionStart、SessionEnd、UserPromptSubmit、PreCompact、Notification
用法 :钩子响应 Claude Code 事件自动执行
位置 :插件根目录的 .mcp.json 或内联在 plugin.json 中 格式 :MCP 服务器定义的 JSON 配置 自动启动 :插件启用时,服务器自动启动
示例格式:
{
"mcpServers": {
"server-name": {
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/servers/server.js"],
"env": {
"API_KEY": "${API_KEY}"
}
}
}
}
用法 :MCP 服务器与 Claude Code 的工具系统无缝集成
对所有插件内部的路径引用使用 ${CLAUDE_PLUGIN_ROOT} 环境变量:
{
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/run.sh"
}
为何重要 :插件根据以下因素安装在不同位置:
在何处使用:
切勿使用:
/Users/name/plugins/...)./scripts/...)~/plugins/...)在清单 JSON 字段中(钩子、MCP 服务器):
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/tool.sh"
在组件文件中(命令、智能体、技能):
引用脚本位置:${CLAUDE_PLUGIN_ROOT}/scripts/helper.py
在执行的脚本中:
#!/bin/bash
# ${CLAUDE_PLUGIN_ROOT} 作为环境变量可用
source "${CLAUDE_PLUGIN_ROOT}/lib/common.sh"
命令 :使用 kebab-case 的 .md 文件
code-review.md → /code-reviewrun-tests.md → /run-testsapi-docs.md → /api-docs智能体 :使用描述角色的 kebab-case .md 文件
test-generator.mdcode-reviewer.mdperformance-analyzer.md技能 :使用 kebab-case 目录名
api-testing/database-migrations/error-handling/脚本 :使用描述性的 kebab-case 名称,并带有适当的扩展名
validate-input.shgenerate-report.pyprocess-data.js文档 :使用 kebab-case 的 markdown 文件
api-reference.mdmigration-guide.mdbest-practices.md配置 :使用标准名称
hooks.json.mcp.jsonplugin.jsonClaude Code 自动发现并加载组件:
.claude-plugin/plugin.jsoncommands/ 目录中的 .md 文件agents/ 目录中的 .md 文件skills/ 目录中包含 SKILL.md 的子目录hooks/hooks.json 或清单中加载配置.mcp.json 或清单中加载配置发现时机:
覆盖行为 :plugin.json 中的自定义路径补充(而非替换)默认目录
* 将测试相关的命令、智能体和技能放在一起
* 在 `scripts/` 中为不同目的创建子目录
2. 最小化清单 :保持 plugin.json 简洁
* 仅在必要时指定自定义路径
* 对于标准布局,依赖自动发现
* 仅对简单情况使用内联配置
3. 文档 :包含 README 文件
* 插件根目录:整体用途和用法
* 组件目录:具体指导
* 脚本目录:使用方法和要求
* 如果命令是 `test-runner`,则将相关智能体命名为 `test-runner-agent`
* 技能目录名与其用途相匹配
2. 清晰性 :使用能表明用途的描述性名称
* 良好示例:`api-integration-testing/`、`code-quality-checker.md`
* 避免示例:`utils/`、`misc.md`、`temp.sh`
3. 长度 :在简洁性和清晰性之间取得平衡
* 命令:2-3 个单词(`review-pr`、`run-ci`)
* 智能体:清晰地描述角色(`code-reviewer`、`test-generator`)
* 技能:主题聚焦(`error-handling`、`api-design`)
单一命令,无依赖:
my-plugin/
├── .claude-plugin/
│ └── plugin.json # 仅包含 name 字段
└── commands/
└── hello.md # 单一命令
包含所有组件类型的完整插件:
my-plugin/
├── .claude-plugin/
│ └── plugin.json
├── commands/ # 面向用户的命令
├── agents/ # 专业化的子智能体
├── skills/ # 自动激活的技能
├── hooks/ # 事件处理器
│ ├── hooks.json
│ └── scripts/
├── .mcp.json # 外部集成
└── scripts/ # 共享实用工具
仅提供技能的插件:
my-plugin/
├── .claude-plugin/
│ └── plugin.json
└── skills/
├── skill-one/
│ └── SKILL.md
└── skill-two/
└── SKILL.md
组件未加载:
SKILL.md(而不是 README.md 或其他名称)路径解析错误:
${CLAUDE_PLUGIN_ROOT}./ 开头echo $CLAUDE_PLUGIN_ROOT 进行测试自动发现不工作:
.claude-plugin/ 中)插件间冲突:
有关详细示例和高级模式,请参阅 references/ 和 examples/ 目录中的文件。
每周安装次数
297
代码仓库
GitHub 星标数
9.6K
首次出现
2026年2月5日
安全审计
安装于
opencode255
codex254
gemini-cli252
github-copilot245
amp236
claude-code236
Claude 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.
Key concepts:
.claude-plugin/plugin.json${CLAUDE_PLUGIN_ROOT}Every Claude Code plugin follows this organizational pattern:
plugin-name/
├── .claude-plugin/
│ └── plugin.json # Required: Plugin manifest
├── commands/ # Slash commands (.md files)
├── agents/ # Subagent definitions (.md files)
├── skills/ # Agent skills (subdirectories)
│ └── skill-name/
│ └── SKILL.md # Required for each skill
├── hooks/
│ └── hooks.json # Event handler configuration
├── .mcp.json # MCP server definitions
└── scripts/ # Helper scripts and utilities
Critical rules:
plugin.json manifest MUST be in .claude-plugin/ directory.claude-plugin/The manifest defines plugin metadata and configuration. Located at .claude-plugin/plugin.json:
{
"name": "plugin-name"
}
Name requirements:
code-review-assistant, test-runner, api-docs{
"name": "plugin-name",
"version": "1.0.0",
"description": "Brief explanation of plugin purpose",
"author": {
"name": "Author Name",
"email": "author@example.com",
"url": "https://example.com"
},
"homepage": "https://docs.example.com",
"repository": "https://github.com/user/plugin-name",
"license": "MIT",
"keywords": ["testing", "automation", "ci-cd"]
}
Version format : Follow semantic versioning (MAJOR.MINOR.PATCH) Keywords : Use for plugin discovery and categorization
Specify custom paths for components (supplements default directories):
{
"name": "plugin-name",
"commands": "./custom-commands",
"agents": ["./agents", "./specialized-agents"],
"hooks": "./config/hooks.json",
"mcpServers": "./.mcp.json"
}
Important : Custom paths supplement defaults—they don't replace them. Components in both default directories and custom paths will load.
Path rules:
./Location : commands/ directory Format : Markdown files with YAML frontmatter Auto-discovery : All .md files in commands/ load automatically
Example structure :
commands/
├── review.md # /review command
├── test.md # /test command
└── deploy.md # /deploy command
File format :
---
name: command-name
description: Command description
---
Command implementation instructions...
Usage : Commands integrate as native slash commands in Claude Code
Location : agents/ directory Format : Markdown files with YAML frontmatter Auto-discovery : All .md files in agents/ load automatically
Example structure :
agents/
├── code-reviewer.md
├── test-generator.md
└── refactorer.md
File format :
---
description: Agent role and expertise
capabilities:
- Specific task 1
- Specific task 2
---
Detailed agent instructions and knowledge...
Usage : Users can invoke agents manually, or Claude Code selects them automatically based on task context
Location : skills/ directory with subdirectories per skill Format : Each skill in its own directory with SKILL.md file Auto-discovery : All SKILL.md files in skill subdirectories load automatically
Example structure :
skills/
├── api-testing/
│ ├── SKILL.md
│ ├── scripts/
│ │ └── test-runner.py
│ └── references/
│ └── api-spec.md
└── database-migrations/
├── SKILL.md
└── examples/
└── migration-template.sql
SKILL.md format :
---
name: Skill Name
description: When to use this skill
version: 1.0.0
---
Skill instructions and guidance...
Supporting files : Skills can include scripts, references, examples, or assets in subdirectories
Usage : Claude Code autonomously activates skills based on task context matching the description
Location : hooks/hooks.json or inline in plugin.json Format : JSON configuration defining event handlers Registration : Hooks register automatically when plugin enables
Example structure :
hooks/
├── hooks.json # Hook configuration
└── scripts/
├── validate.sh # Hook script
└── check-style.sh # Hook script
Configuration format :
{
"PreToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/validate.sh",
"timeout": 30
}]
}]
}
Available events : PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification
Usage : Hooks execute automatically in response to Claude Code events
Location : .mcp.json at plugin root or inline in plugin.json Format : JSON configuration for MCP server definitions Auto-start : Servers start automatically when plugin enables
Example format :
{
"mcpServers": {
"server-name": {
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/servers/server.js"],
"env": {
"API_KEY": "${API_KEY}"
}
}
}
}
Usage : MCP servers integrate seamlessly with Claude Code's tool system
Use ${CLAUDE_PLUGIN_ROOT} environment variable for all intra-plugin path references:
{
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/run.sh"
}
Why it matters : Plugins install in different locations depending on:
Where to use it :
Never use :
/Users/name/plugins/...)./scripts/... in commands)~/plugins/...)In manifest JSON fields (hooks, MCP servers):
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/tool.sh"
In component files (commands, agents, skills):
Reference scripts at: ${CLAUDE_PLUGIN_ROOT}/scripts/helper.py
In executed scripts :
#!/bin/bash
# ${CLAUDE_PLUGIN_ROOT} available as environment variable
source "${CLAUDE_PLUGIN_ROOT}/lib/common.sh"
Commands : Use kebab-case .md files
code-review.md → /code-reviewrun-tests.md → /run-testsapi-docs.md → /api-docsAgents : Use kebab-case .md files describing role
test-generator.mdcode-reviewer.mdperformance-analyzer.mdSkills : Use kebab-case directory names
api-testing/database-migrations/error-handling/Scripts : Use descriptive kebab-case names with appropriate extensions
validate-input.shgenerate-report.pyprocess-data.jsDocumentation : Use kebab-case markdown files
api-reference.mdmigration-guide.mdbest-practices.mdConfiguration : Use standard names
hooks.json.mcp.jsonplugin.jsonClaude Code automatically discovers and loads components:
.claude-plugin/plugin.json when plugin enablescommands/ directory for .md filesagents/ directory for .md filesskills/ for subdirectories containing SKILL.mdhooks/hooks.json or manifest.mcp.json or manifestDiscovery timing :
Override behavior : Custom paths in plugin.json supplement (not replace) default directories
Logical grouping : Group related components together
scripts/ for different purposesMinimal manifest : Keep plugin.json lean
Documentation : Include README files
Consistency : Use consistent naming across components
test-runner, name related agent test-runner-agentClarity : Use descriptive names that indicate purpose
api-integration-testing/, code-quality-checker.mdutils/, misc.md, temp.shLength : Balance brevity with clarity
Single command with no dependencies:
my-plugin/
├── .claude-plugin/
│ └── plugin.json # Just name field
└── commands/
└── hello.md # Single command
Complete plugin with all component types:
my-plugin/
├── .claude-plugin/
│ └── plugin.json
├── commands/ # User-facing commands
├── agents/ # Specialized subagents
├── skills/ # Auto-activating skills
├── hooks/ # Event handlers
│ ├── hooks.json
│ └── scripts/
├── .mcp.json # External integrations
└── scripts/ # Shared utilities
Plugin providing only skills:
my-plugin/
├── .claude-plugin/
│ └── plugin.json
└── skills/
├── skill-one/
│ └── SKILL.md
└── skill-two/
└── SKILL.md
Component not loading :
SKILL.md (not README.md or other name)Path resolution errors :
${CLAUDE_PLUGIN_ROOT}./ in manifestecho $CLAUDE_PLUGIN_ROOT in hook scriptsAuto-discovery not working :
.claude-plugin/)Conflicts between plugins :
For detailed examples and advanced patterns, see files in references/ and examples/ directories.
Weekly Installs
297
Repository
GitHub Stars
9.6K
First Seen
Feb 5, 2026
Security Audits
Gen Agent Trust HubPassSocketWarnSnykPass
Installed on
opencode255
codex254
gemini-cli252
github-copilot245
amp236
claude-code236
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
136,300 周安装
review-prrun-cicode-reviewer, test-generator)error-handling, api-design)