plugins/plugin-dev/skills/plugin-structure/SKILL.md
当用户要求 "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", 或需要关于插件目录布局, 清单配置, 组件组织, 文件命名约定或 Claude Code 插件架构最佳实践的指导时应使用此技能.
npx skillsauth add phpmac/skills plugin-structureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Claude Code 插件遵循标准化的目录结构, 具有自动组件发现功能. 理解此结构可以创建组织良好, 可维护的插件, 与 Claude Code 无缝集成.
关键概念:
.claude-plugin/plugin.json 中的清单驱动配置${CLAUDE_PLUGIN_ROOT} 的可移植路径引用每个 Claude Code 插件都遵循此组织模式:
plugin-name/
├── .claude-plugin/
│ └── plugin.json # 必需: 插件清单
├── commands/ # 斜杠命令 (.md 文件)
├── agents/ # 子 agent 定义 (.md 文件)
├── skills/ # Agent 技能 (子目录)
│ └── skill-name/
│ └── SKILL.md # 每个技能必需
├── hooks/
│ └── hooks.json # 事件处理器配置
├── .mcp.json # MCP 服务器定义
└── scripts/ # 辅助脚本和工具
关键规则:
plugin.json 清单必须在 .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": "[email protected]",
"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 frontmatter 的 Markdown 文件
自动发现: commands/ 中的所有 .md 文件自动加载
示例结构:
commands/
├── review.md # /review 命令
├── test.md # /test 命令
└── deploy.md # /deploy 命令
文件格式:
---
name: command-name
description: 命令描述
---
命令实现指令...
用法: 命令作为原生斜杠命令集成到 Claude Code 中
位置: agents/ 目录
格式: 带 YAML frontmatter 的 Markdown 文件
自动发现: agents/ 中的所有 .md 文件自动加载
示例结构:
agents/
├── code-reviewer.md
├── test-generator.md
└── refactorer.md
文件格式:
---
description: Agent 角色和专业知识
capabilities:
- 特定任务 1
- 特定任务 2
---
详细的 agent 指令和知识...
用法: 用户可以手动调用 agents, 或 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/
├── hooks.json # Hook 配置
└── scripts/
├── validate.sh # Hook 脚本
└── check-style.sh # Hook 脚本
配置格式:
{
"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
用法: Hooks 自动执行以响应 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 字段中 (hooks, MCP 服务器):
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/tool.sh"
在组件文件中 (commands, agents, skills):
引用脚本位于: ${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-docsAgents: 使用描述角色的 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, 命名相关 agent 为 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 # 仅名称字段
└── commands/
└── hello.md # 单个命令
包含所有组件类型的完整插件:
my-plugin/
├── .claude-plugin/
│ └── plugin.json
├── commands/ # 面向用户的命令
├── agents/ # 专门的子 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/ 目录中的文件.
data-ai
当用户提到 Linux 提权/本地提权/local privilege escalation/获取root权限/内核漏洞利用/LPE/SUID/sudo滥用/容器逃逸/权限提升检测; 或要求在Linux系统上从普通用户提升到root权限; 或查询CVE提权漏洞(如Dirty Pipe/CopyFail/Dirty Frag/PwnKit/Looney Tunables); 或需要安全加固建议时应使用此技能
tools
当用户要求 "计算仓位", "仓位管理", "止损比例", "凯利公式", "盈亏比", "资金管理", "半凯利", "反马丁格尔", "固定风险", "position sizing", "策略评估", "策略体检", "SQN", "夏普比率", "卡玛比率", "期望值", "获利因子", "MAE", "MFE", "R乘数", "索提诺", "蒙特卡洛", "样本外测试", "策略回测" 或需要计算合约交易的最优仓位/止损/资金分配/策略质量评估时应使用此技能. 覆盖仓位管理/策略评估/交易解剖/压力测试的完整框架. 即使用户只是提到 "这笔交易该下多少", "策略好不好", "复盘怎么算" 等模糊描述也应触发.
development
当用户要求 "提取API", "逆向APK", "分析APP接口", "提取业务端点", "React Native逆向", "Flutter逆向" 或需要从移动应用提取后端API信息时使用此技能. 覆盖APK解包/JS bundle分析/kernel_blob.bin分析/H5页面参数发现/Spring Boot API验证全流程. 支持React Native和Flutter两种框架.
research
当用户要求 "推荐VPS", "选服务器", "对比服务商", "建站VPS", "便宜VPS", "VPS推荐" 或需要研究/筛选/对比VPS服务商时应使用此技能. 从 hostloc/lowendtalk/lowendbox/测评站搜集真实评测数据, 交叉验证后给出可溯源排名.