教程

Claude Code 插件系统完全指南:创建、分发和管理自定义插件

Claude Code 插件系统完全指南:创建自定义 Skills、Agents、Hooks,支持团队共享和 Marketplace 分发。含完整目录结构、组件详解和开发技巧。

2026/4/73分钟 阅读ClaudeEagle

想让 Claude Code 学会新技能?插件系统允许你创建自定义 Skills、Agents、Hooks 和 MCP Server,并在项目和团队之间共享。


插件 vs 独立配置

方式Skill 命名适用场景
独立配置(.claude/ 目录)/hello个人工作流、单项目定制、快速实验
插件(.claude-plugin//plugin-name:hello团队共享、社区分发、跨项目复用

建议:先用独立配置快速迭代,准备好分享时再转为插件。

创建第一个插件

1. 创建目录结构

bash
mkdir my-first-plugin
mkdir my-first-plugin/.claude-plugin

2. 编写 Manifest

json
// my-first-plugin/.claude-plugin/plugin.json
{
  "name": "my-first-plugin",
  "description": "A greeting plugin to learn the basics",
  "version": "1.0.0",
  "author": {
    "name": "Your Name"
  }
}

3. 添加 Skill

bash
mkdir -p my-first-plugin/skills/hello
markdown
<!-- my-first-plugin/skills/hello/SKILL.md -->
---
description: Greet the user with a friendly message
disable-model-invocation: true
---

Greet the user warmly and ask how you can help them today.

4. 测试

bash
claude --plugin-dir ./my-first-plugin
# 在会话中输入:
/my-first-plugin:hello

插件目录结构

text
my-plugin/
├── .claude-plugin/
│   └── plugin.json        # Manifest(只有这个放在 .claude-plugin 里)
├── skills/                 # 自定义 Skills
│   └── pdf-processor/
│       ├── SKILL.md
│       ├── reference.md
│       └── scripts/
├── agents/                 # 自定义 Agent
│   └── code-reviewer.md
├── hooks/                  # 事件钩子
│   └── hooks.json
├── commands/               # 简单命令
│   └── deploy.md
└── mcp/                    # MCP Server 配置

⚠️ 常见错误:不要把 skills/agents/ 等目录放在 .claude-plugin/ 里面。只有 plugin.json 放在 .claude-plugin/ 中。

组件详解

Skills

$ARGUMENTS 占位符支持动态参数:

markdown
---
description: Greet the user with a personalized message
---
# Hello Skill
Greet the user named "$ARGUMENTS" warmly.

使用:/my-plugin:hello Alex

Agents

自定义子 Agent,支持模型选择和工具限制:

markdown
---
name: code-reviewer
description: Specialized code review agent
model: sonnet
effort: medium
maxTurns: 20
disallowedTools: Write, Edit
---

You are a code review specialist...

Hooks

响应 Claude Code 生命周期事件:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PLUGIN_ROOT}/scripts/format-code.sh"
          }
        ]
      }
    ]
  }
}

支持的事件:

事件触发时机
SessionStart会话开始
PreToolUse工具调用前(可阻止)
PostToolUse工具调用成功后
SubagentStart子 Agent 启动
SubagentStop子 Agent 完成
TaskCreated任务创建

分发插件

通过 Marketplace

  1. 创建 Marketplace 仓库(GitHub)
  2. 添加 marketplace.json 索引
  3. 用户通过 /plugin marketplace add 安装

本地安装

bash
# 从目录安装
/plugin install-dir ./path/to/plugin

# 从 Marketplace 安装
/plugin install my-plugin@marketplace-name

版本管理

使用语义化版本号:

json
{
  "version": "2.1.0"
}
  • 主版本号:不兼容变更
  • 次版本号:新功能(向后兼容)
  • 修订号:Bug 修复

开发技巧

  1. 使用 --plugin-dir 本地开发,避免反复安装
  2. /reload-plugins 实时加载修改
  3. 命名空间防止插件间冲突
  4. Skills 支持辅助文件(reference.md、scripts/)
  5. 安全考虑:插件 Agent 不支持 hooks、mcpServers 和 permissionMode

原文来源:Claude Code Plugins 文档 | 来源:Claude Code 官方文档

相关文章推荐

教程Claude Code Plugins 开发完整指南:从创建 Manifest 到发布到官方市场Claude Code Plugin 开发完整指南:从创建 plugin.json 清单、添加 Skills/Subagent/Hooks/MCP/LSP 服务器,到本地测试、团队分发和提交到 Anthropic 官方市场。附安全审查 Plugin 完整示例和现有配置迁移步骤。2026/2/28教程Claude Code Skills 自定义命令:打造你的团队专属 AI 工作流Claude Code Skills 自定义命令完整教程:Skills vs CLAUDE.md 使用场景对比、内置 Skills 速览(/batch/simplify/loop)、SKILL.md 文件格式与 Frontmatter 配置、四大实用 Skills 示例(代码审查/部署检查/功能开发/团队 OnBoarding)、传参方式、子代理执行与 Git 团队共享。2026/3/14教程Claude Code Subagents 完整创建指南:内置 Agent、Frontmatter 字段、持久记忆与 Hooks 配置Claude Code Subagents 完整创建指南:内置 4 类 Subagent(Explore Haiku 只读/Plan 只读/General-purpose 全工具/Bash-statusline-Guide helper)、/agents 交互界面 7 步创建流程、四种存储位置(CLI --agents 当前会话/项目级/用户级/插件级)及优先级、Subagent 文件 Markdown+Frontmatter 格式、9 个 Frontmatter 字段(name/description 最重要/model/tools/disallowedTools/permissionMode/skills/hooks/maxTurns/memory/allowedAgents/color)、工具白黑名单配置、allowedAgents 限制可 spawn、持久记忆(memory: true/自定义路径/前 200 行加载)、两种 Hooks 配置方式(Frontmatter 内联/settings.json SubagentStart/SubagentStop)、前台后台运行(Ctrl+B/tasks),以及 4 个直接可用示例(code-reviewer/debugger/data-scientist/db-validator)。2026/3/9教程Claude Code 插件开发指南:plugin.json 结构、Skills/Hooks/MCP 集成与官方市场提交Claude Code 插件开发完整指南:独立配置 vs 插件对比(命名空间/适用场景)、5 步快速创建(目录/plugin.json 清单字段/Skill/本地 --plugin-dir 测试/分享)、完整插件目录结构(.claude-plugin/commands/skills/agents/hooks/mcp/.lsp.json/settings.json)、各组件配置示例(Skills SKILL.md/LSP 服务器.lsp.json/默认 settings.json agent 键)、从独立配置迁移步骤对比表、三步调试方法,以及通过 claude.ai 和 Console 提交官方市场的方式。2026/3/8教程Claude Code Skills 完全指南:创建自定义技能、Bundled Skills 与高级模式Claude Code Skills 完全指南:5 个内置 Bundled Skills(/simplify 并行 3 Agent/\batch Git Worktree 并行/\debug 会话日志/\loop 定时执行/\claude-api 自动激活)、3 步创建自定义 Skill(目录/SKILL.md/测试)、存储位置与优先级(Enterprise/Personal/Project/Plugin 命名空间)、Frontmatter 完整配置(name/description/disable-model-invocation/tools)、两种内容类型(参考型内联/任务型手动)、高级模式($ARGUMENTS 字符串替换/支持文件目录/动态注入上下文/子 Agent 执行),以及三种共享方式和故障排查。2026/3/8教程Claude Code VS Code 插件完整指南:@-mentions、多会话、Checkpoint 回滚与 CLI 对比Claude Code VS Code 插件完整指南:安装方法(直接链接/Extensions 搜索/Cursor 支持)、四种打开面板方式(编辑器工具栏/Activity Bar/命令面板/状态栏)、@-mentions 文件引用(模糊匹配/目录/PDF 指定页/拖拽附件)、三种权限模式(Ask/Plan 自动 Markdown 文档/Auto-accept)、提示框命令菜单(/usage/MCP/扩展思考)、多会话管理(标签页/侧边栏)、远程会话续接(Local/Remote 两标签)、Checkpoint 回滚、Chrome 浏览器自动化、VS Code 插件 vs CLI 功能对比表,以及四大常见问题解决。2026/3/8