Plugin Structure by anthropics/claude-code
npx skills add https://github.com/anthropics/claude-code --skill 'Plugin Structure'Claude 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/ 中为不同目的创建子目录最小化清单:保持 plugin.json 简洁
文档:包含 README 文件
一致性:跨组件使用一致的命名
test-runner,则将相关代理命名为 test-runner-agent清晰性:使用能表明用途的描述性名称
api-integration-testing/, code-quality-checker.mdutils/, misc.md, temp.sh长度:在简洁性和清晰性之间取得平衡
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/ 目录中的文件。
每周安装次数
0
代码仓库
GitHub 星标数
75.9K
首次出现
1970年1月1日
安全审计
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
0
Repository
GitHub Stars
75.9K
First Seen
Jan 1, 1970
Security Audits
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
138,300 周安装
通用发布工作流技能 - 支持多语言更新日志,自动检测项目配置
12,000 周安装
Tavily AI 搜索技能:为 LLM 优化的网络搜索 API,支持高级过滤与 OAuth 认证
11,900 周安装
OpenClaw技能安全审计指南:skill-vetter工具详解与安装前安全检查
12,200 周安装
Gemini Web API 客户端:文本与图像生成工具,支持多轮对话和逆向工程API
12,100 周安装
Google Workspace Drive API v3 命令行工具 - 管理云端硬盘文件与权限
12,200 周安装
知识漫画创作器 - AI漫画生成工具,支持多种画风和基调组合
12,600 周安装
review-prrun-cicode-reviewer, test-generator)error-handling, api-design)