在前面的章节中,我们学习了 Hooks(事件驱动的自动化)和 Skills(可复用的提示模板)。但当你的团队积累了大量相关联的 Hooks、Skills 甚至 MCP 服务器配置后,逐个管理和分发它们变得困难。Plugins 就是解决这个问题的方案——它们将相关的能力打包成一个可安装、可分发的整体。
你可以把 Plugin 想象成一个”能力包”:它可以同时包含多个 Skills、多个 Hooks 和 MCP 服务器配置,围绕某个特定领域(如测试、部署、代码质量)提供完整的增强体验。
一个 Plugin 遵循约定的目录结构:
PLUGIN.md 是 Plugin 的清单文件,描述了 Plugin 的名称、用途和包含的能力:
# Testing Plugin
A comprehensive testing plugin for Claude Code.
## Skills
- /test-unit — Run unit tests for specified files or modules
- /test-e2e — Run end-to-end test suites
- /test-coverage — Generate and analyze test coverage reports
## Hooks
- PostToolUse: Auto-lint after file writes
- PreToolUse: Block commits without passing tests
## MCP Servers
- coverage-server: Provides real-time coverage data一个 Plugin 可以包含以下三种能力的任意组合:
Skills(提示模板)
Plugin 中的 Skills 与独立的 Skills 完全相同——它们是 Markdown 文件,通过斜杠命令调用。唯一的区别是它们被组织在 Plugin 的 skills/ 目录下。
# skills/test-unit.md
Run unit tests for the specified file or module.
Steps:
1. Identify the test framework (Jest, Vitest, Mocha, etc.)
2. Find corresponding test files for the target
3. Execute tests with verbose output
4. If tests fail, analyze failures and suggest fixes
5. Report coverage for the tested filesHooks(自动化触发器)
Plugin 的 Hooks 配置在 hooks/settings.json 中,安装时会合并到用户的 Hook 配置中:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write",
"command": "npx eslint --fix $CLAUDE_FILE_PATH 2>/dev/null || true"
}
],
"PreToolUse": [
{
"matcher": "Bash",
"command": "echo $CLAUDE_TOOL_INPUT | grep -q 'git push' && npm test || true"
}
]
}
}MCP 服务器配置
Plugin 可以配置 MCP 服务器,扩展 Claude Code 可以访问的外部数据源和工具:
{
"mcpServers": {
"coverage-server": {
"command": "npx",
"args": ["coverage-mcp-server", "--root", "."],
"env": {
"COVERAGE_DIR": "./coverage"
}
}
}
}为什么需要 Plugin 而不是单独管理 Skills 和 Hooks?
Plugins 可以通过多种渠道分发:
Git 仓库
最常见的分发方式。团队或社区将 Plugin 发布为 Git 仓库:
# 安装 Plugin
claude plugin add https://github.com/team/testing-plugin
# 从特定分支安装
claude plugin add https://github.com/team/testing-plugin --branch v2npm 包
对于 Node.js 生态,Plugin 可以作为 npm 包分发:
# 作为 npm 包安装
claude plugin add @team/claude-testing-plugin本地路径
开发阶段可以从本地路径安装:
# 从本地路径安装
claude plugin add ./my-local-pluginPlugins 的安装信息记录在配置文件中:
{
"plugins": [
{
"name": "testing-plugin",
"source": "https://github.com/team/testing-plugin",
"version": "1.2.0",
"enabled": true
},
{
"name": "deploy-plugin",
"source": "@team/claude-deploy-plugin",
"version": "3.0.1",
"enabled": true
}
]
}每个 Plugin 可以单独启用或禁用,不需要卸载就能暂时关闭某些功能。
让我们看一个完整的 Testing Plugin,它围绕”测试”这个领域提供全方位的增强:
这个 Plugin 安装后:
/test 命令让 Claude 智能地找到并运行相关测试这就是 Plugin 的威力——它不是单一功能,而是一个围绕特定领域的完整工作流增强方案。
Plugins 是 Claude Code 扩展生态的最高层抽象:
从底层的工具调用,到中层的 MCP 协议,再到 Hooks 的自动化和 Skills 的流程封装,最终由 Plugins 将一切打包在一起。这构成了 Claude Code 完整的能力扩展体系。
In the previous chapters, we learned about Hooks (event-driven automation) and Skills (reusable prompt templates). But when your team accumulates many related Hooks, Skills, and even MCP server configurations, managing and distributing them individually becomes difficult. Plugins solve this problem — they package related capabilities into an installable, distributable unit.
Think of a Plugin as a “capability package”: it can simultaneously contain multiple Skills, multiple Hooks, and MCP server configurations, providing a complete enhanced experience around a specific domain (such as testing, deployment, or code quality).
A Plugin follows a conventional directory structure:
PLUGIN.md is the Plugin’s manifest file, describing the Plugin’s name, purpose, and included capabilities:
# Testing Plugin
A comprehensive testing plugin for Claude Code.
## Skills
- /test-unit — Run unit tests for specified files or modules
- /test-e2e — Run end-to-end test suites
- /test-coverage — Generate and analyze test coverage reports
## Hooks
- PostToolUse: Auto-lint after file writes
- PreToolUse: Block commits without passing tests
## MCP Servers
- coverage-server: Provides real-time coverage dataA Plugin can contain any combination of these three capability types:
Skills (Prompt Templates)
Skills within a Plugin are identical to standalone Skills — they are Markdown files invoked via slash commands. The only difference is they are organized under the Plugin’s skills/ directory.
# skills/test-unit.md
Run unit tests for the specified file or module.
Steps:
1. Identify the test framework (Jest, Vitest, Mocha, etc.)
2. Find corresponding test files for the target
3. Execute tests with verbose output
4. If tests fail, analyze failures and suggest fixes
5. Report coverage for the tested filesHooks (Automated Triggers)
Plugin Hooks are configured in hooks/settings.json and merged into the user’s Hook configuration upon installation:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write",
"command": "npx eslint --fix $CLAUDE_FILE_PATH 2>/dev/null || true"
}
],
"PreToolUse": [
{
"matcher": "Bash",
"command": "echo $CLAUDE_TOOL_INPUT | grep -q 'git push' && npm test || true"
}
]
}
}MCP Server Configuration
Plugins can configure MCP servers, extending the external data sources and tools that Claude Code can access:
{
"mcpServers": {
"coverage-server": {
"command": "npx",
"args": ["coverage-mcp-server", "--root", "."],
"env": {
"COVERAGE_DIR": "./coverage"
}
}
}
}Why use Plugins instead of managing Skills and Hooks independently?
Plugins can be distributed through multiple channels:
Git Repositories
The most common distribution method. Teams and communities publish Plugins as Git repositories:
# Install a Plugin
claude plugin add https://github.com/team/testing-plugin
# Install from a specific branch
claude plugin add https://github.com/team/testing-plugin --branch v2npm Packages
For the Node.js ecosystem, Plugins can be distributed as npm packages:
# Install as an npm package
claude plugin add @team/claude-testing-pluginLocal Paths
During development, install from a local path:
# Install from a local path
claude plugin add ./my-local-pluginPlugin installation information is recorded in the configuration file:
{
"plugins": [
{
"name": "testing-plugin",
"source": "https://github.com/team/testing-plugin",
"version": "1.2.0",
"enabled": true
},
{
"name": "deploy-plugin",
"source": "@team/claude-deploy-plugin",
"version": "3.0.1",
"enabled": true
}
]
}Each Plugin can be individually enabled or disabled — you can temporarily turn off certain features without uninstalling.
Let’s look at a complete Testing Plugin that provides comprehensive enhancement around the “testing” domain:
Once installed, this Plugin provides:
/test to have Claude intelligently find and run relevant testsThis is the power of Plugins — not a single feature, but a complete workflow enhancement around a specific domain.
Plugins are the highest-level abstraction in Claude Code’s extension ecosystem:
From low-level tool calls, to the MCP protocol at the middle layer, to Hook automation and Skill workflow encapsulation, and finally Plugins packaging everything together — this forms Claude Code’s complete capability extension system.