插件(Plugin)是打包和分发 Claude Code 扩展的标准方式——将 Skills、Agents、Hooks、MCP 服务器打包为可版本化、可分享、可市场发布的单元。
独立配置 vs 插件:如何选择?
| 方式 | Skill 命名 | 适合场景 |
|---|---|---|
独立配置(.claude/ 目录) | /hello | 单项目自定义、个人工作流、快速实验 |
插件(含 .claude-plugin/plugin.json) | /my-plugin:hello | 团队共享、社区分发、版本化发布、跨项目复用 |
插件 Skill 使用命名空间(
插件名:技能名),防止插件间冲突;独立 Skill 直接用/技能名。
快速上手:创建第一个插件(5 步)
前提:Claude Code 1.0.33+(claude --version 验证)
第一步:创建插件目录
mkdir -p my-first-plugin/.claude-plugin
mkdir -p my-first-plugin/skills/hello第二步:创建插件清单 plugin.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"
}
}| 字段 | 说明 |
|---|---|
name | 唯一标识符,也是 Skill 的命名空间前缀 |
description | 在插件管理器中显示 |
version | 语义化版本(SemVer) |
author | 可选,用于归因 |
其他可选字段:homepage、repository、license。
第三步:创建 Skill
# my-first-plugin/skills/hello/SKILL.md
---
name: hello
description: Greets the user by name
disable-model-invocation: true
---
Greet the user with: "Hello, $ARGUMENTS! Welcome to Claude Code."调用方式:/my-first-plugin:hello World → Claude 回复「Hello, World!」
第四步:本地测试
claude --plugin-dir ./my-first-plugin测试各组件:
- Skill:
/my-first-plugin:hello World - Agent:
/agents - Hook:触发相关操作验证
第五步:分享
- 添加
README.md(安装和使用说明) - 在
plugin.json设置版本号 - 创建或使用插件市场分发
插件完整目录结构
my-plugin/
├── .claude-plugin/
│ └── plugin.json # 插件清单(必须)
├── commands/ # 以 Markdown 文件形式的 Skill(旧版兼容)
├── skills/ # Agent Skills(推荐)
│ └── skill-name/
│ └── SKILL.md
├── agents/ # 自定义 Agent 定义
├── hooks/
│ └── hooks.json # Hook 事件处理器
├── .mcp.json # MCP 服务器配置
├── .lsp.json # LSP 服务器配置(代码智能)
└── settings.json # 插件默认设置
各组件配置示例
Skills
# skills/code-review/SKILL.md
---
name: code-review
description: Reviews code for best practices. Use when reviewing code, checking PRs.
---
When reviewing code, check for:
1. Code organization and structure
2. Error handling
3. Security concerns
4. Test coverage安装插件后重启 Claude Code 加载 Skills。
LSP 服务器(代码智能)
// .lsp.json
{
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go"
}
}
}用户安装插件后需要在本机安装对应的语言服务器二进制(如 gopls)。
默认 Settings
// settings.json
{
"agent": "security-reviewer"
}激活插件的 agents/security-reviewer Agent 作为主线程,修改 Claude Code 的默认行为。目前仅支持 agent 键。
迁移现有配置到插件
独立配置(.claude/) | 插件 |
|---|---|
.claude/commands/ | plugin-name/commands/ |
settings.json 中的 Hooks | hooks/hooks.json |
| 仅限单个项目 | 通过市场可分享 |
| 手动复制共享 | /plugin install 安装 |
调试插件问题
- 检查目录结构:所有目录(
skills/、agents/等)在插件根目录,不在.claude-plugin/内 - 逐个测试组件:分别验证 Skill、Agent、Hook
- 用 validation 工具:参见 Plugins reference 中的调试工具文档
提交到官方市场
插件完成后,通过以下方式提交到 Anthropic 官方插件市场:
- claude.ai:claude.ai/settings/plugins/submit
- Console:platform.claude.com/plugins/submit
原文:Create plugins - Claude Code Docs | 来源:Anthropic 官方文档