C Claude Code Internals
| EN | ES

Plugins

Plugins 通过模块化包扩展 Claude Code,这些包捆绑了命令、技能、代理、输出样式、hooks、MCP 服务器、LSP 服务器、通道和设置。它们可以从 marketplace 安装、通过 CLI 标志加载或作为内置包捆绑。

9 能力类型 6 marketplace 来源格式 3 plugin 来源 11 /plugin 子命令
i 一个包,多种能力
单个 plugin 可以提供斜杠命令、技能、代理、输出样式、hooks、MCP 服务器、LSP 服务器、消息通道和设置覆盖的任意组合。 唯一必需的文件是 .claude-plugin/plugin.json。 其他所有内容都是可选的,并通过目录约定自动检测。

Plugin 来源和存储

来源 ID 格式 描述
Marketplace plugin@marketplace 从 marketplace 仓库安装
会话 (基于路径) 通过 --plugin-dir CLI 标志加载
内置 plugin@builtin 与 Claude Code 捆绑(当前无注册)

存储位置

# 缓存的 plugin 文件
~/.claude/plugins/cache/{marketplace}/{plugin}/{version}/

# 启用的 plugins 列表
~/.claude/settings.json → enabledPlugins: [...]

# 每个 plugin 的选项
~/.claude/settings.json → pluginConfigs: {...}

Plugin 目录结构

my-plugin/
├── .claude-plugin/
│   ├── plugin.json        # Manifest(必需)
│   └── marketplace.json   # 供发布者使用
├── commands/              # 斜杠命令(自动检测)
│   ├── build.md
│   └── deploy.md
├── agents/                # 自定义代理(自动检测)
│   └── test-runner.md
├── skills/                # 技能(自动检测)
│   └── my-skill/
│       └── SKILL.md
├── output-styles/         # 输出样式(自动检测)
│   └── concise.md
├── hooks/
│   └── hooks.json         # Hook 配置
└── .mcp.json              # MCP 服务器(可选)

.claude-plugin/plugin.json 的 manifest 是唯一必需的文件。Claude Code 从标准目录自动检测能力,无需 manifest 声明。

自动检测的目录

commands/ 任何 .md 文件 → 斜杠命令
agents/ 任何 .md 文件 → 自定义代理类型
skills/ 包含 SKILL.md 的目录 → 技能
output-styles/ 任何 .md 文件 → 输出样式
hooks/hooks.json Hook 配置
.mcp.json MCP 服务器配置

Plugin Manifest(plugin.json)

完整 schema

{
  "name": "my-plugin",
  "version": "1.0.0",
  "description": "What this plugin does",
  "author": {
    "name": "Author Name",
    "email": "author@example.com",
    "url": "https://example.com"
  },
  "homepage": "https://example.com/plugin",
  "repository": "https://github.com/org/plugin",
  "license": "MIT",
  "keywords": ["testing", "deployment"],
  "dependencies": [
    "other-plugin",
    "dep-plugin@other-marketplace"
  ],

  "commands": { ... },
  "agents": [ ... ],
  "skills": [ ... ],
  "outputStyles": [ ... ],
  "hooks": { ... },
  "mcpServers": { ... },
  "lspServers": { ... },
  "channels": [ ... ],
  "userConfig": { ... },
  "settings": { ... }
}

元数据字段

字段 必需 描述
name kebab-case,无空格
version Semver(如 "1.2.3")
description 简短描述
author 如存在对象则 name 必需
license SPDX 标识符
keywords 搜索关键词
dependencies "name" 或 "name@marketplace"

Plugin 能力(9 种类型)

命令

斜杠命令,如 /build/deploy

"commands": {
  "build": {
    "source": "./commands/build.md",
    "description": "Build the project",
    "argumentHint": "[target]",
    "model": "claude-sonnet-4-6",
    "allowedTools": ["Bash", "Read"]
  },
  "about": {
    "content": "# About\nInline content.",
    "description": "Show plugin info"
  }
}

Also accepts: single path string or array of paths.

Agents

Custom AI agent types with their own tools and model.

"agents": [
  "./agents/test-runner.md",
  "./agents/reviewer.md"
]

Agent .md files use the same frontmatter format as user-defined agents (tools, model, disallowedTools).

Skills

Skill directories containing SKILL.md.

"skills": [
  "./skills/my-skill",
  "./skills/another-skill"
]

Auto-detected: any directory in skills/ containing SKILL.md.

Output Styles

Custom response formatting.

---
name: Concise
description: Short, direct responses
keepCodingInstructions: true
forceForPlugin: false
---

Respond in 1-2 sentences. No preamble.

forceForPlugin: true overrides user settings when the plugin is active.

Hooks

Supports all 27 hook events. Three declaration formats:

// Inline object
"hooks": { "PostToolUse": [...] }

// File reference
"hooks": "./hooks/extra.json"

// Array mixing both
"hooks": [
  "./hooks/formatting.json",
  { "Stop": [...] }
]

MCP Servers

External tool integrations. Special variables available:

"mcpServers": {
  "my-server": {
    "type": "stdio",
    "command": "node",
    "args": ["`${plugin_root}`/server.js"],
    "env": {
      "API_KEY": "`${user_config.API_KEY}`"
    }
  }
}

Also accepts: ./file.json, ./server.mcpb, or remote URL.

LSP Servers

Language server protocol for code intelligence.

command — start command (required)
extensionToLanguage — file ext → lang ID (required)
transport — stdio / socket
restartOnCrash / maxRestarts
startupTimeout / shutdownTimeout (ms)

Channels

Messaging channels for KAIROS assistant mode.

"channels": [{
  "server": "my-chat-server",
  "displayName": "Team Chat",
  "userConfig": {
    "CHANNEL_ID": {
      "type": "string",
      "title": "Channel ID"
    }
  }
}]

server must match a key in mcpServers. MCP server must declare claude/channel capability.

Settings

Configuration overrides when the plugin is enabled.

"settings": {
  "agent": {
    "my-agent": {
      "tools": ["Read", "Grep"],
      "model": "haiku"
    }
  }
}

Currently only the "agent" key is supported. Merged into the settings cascade when enabled.

User Configuration (userConfig)

Plugins can define options prompted at enable time. Values are injected as $`${user_config.KEY}` in MCP/LSP configs, hooks, and skill content — and as CLAUDE_PLUGIN_OPTION_KEY env vars in hook commands.

Schema example

"userConfig": {
  "API_KEY": {
    "type": "string",
    "title": "API Key",
    "description": "Your API key",
    "required": true,
    "sensitive": true      // stored in Keychain
  },
  "MAX_RESULTS": {
    "type": "number",
    "title": "Max Results",
    "default": 10,
    "min": 1,
    "max": 100
  },
  "VERBOSE": {
    "type": "boolean",
    "default": false
  },
  "PROJECT_DIR": { "type": "directory" },
  "CONFIG_FILE": { "type": "file" }
}

Config option types

Type Input Extra fields
string 文本输入 multiple(数组)
number 数字 minmax
boolean 开关
directory 路径选择器
file 文件选择器

Storage

Non-sensitive: settings.json → pluginConfigs[pluginId].options
Sensitive: macOS Keychain or .credentials.json

Marketplace System

Plugin source formats

Type Format
相对路径 "./plugins/my-plugin"
NPM { "source": "npm", "package": "@org/plugin", "version": "^1.0" }
Pip { "source": "pip", "package": "my-plugin" }
Git URL { "source": "url", "url": "https://...", "ref": "main" }
GitHub { "source": "github", "repo": "owner/repo", "ref": "v1.0" }
Git 子目录 { "source": "git-subdir", "url": "...", "path": "plugins/my" }

Anti-impersonation

Marketplace names are validated against known registries. A marketplace cannot impersonate another marketplace's plugins. Cross-marketplace dependencies require explicit allowCrossMarketplaceDependenciesOn.

extraKnownMarketplaces in settings.json

{
  "extraKnownMarketplaces": [
    {
      "type": "github",
      "repo": "org/plugins",
      "ref": "main"
    },
    {
      "type": "url",
      "url": "https://plugins.example.com/marketplace.json"
    },
    {
      "type": "npm",
      "package": "@org/marketplace"
    },
    {
      "type": "directory",
      "path": "/local/marketplace"
    },
    {
      "type": "settings",
      "name": "inline-marketplace",
      "plugins": [
        { "name": "my-plugin", "source": "./path" }
      ]
    }
  ]
}

Installation & Loading Flow

Installation (10 steps)

1. User runs /plugin install or enables via menu
2. Resolve marketplace source (extraKnownMarketplaces → defaults)
3. Find plugin entry in marketplace.json, resolve source type
4. Download: npm pack, GitHub sparse checkout, git clone, or pip install
5. Cache at ~/.claude/plugins/cache/{marketplace}/{plugin}/{version}/
6. Validate manifest + auto-detect commands/, agents/, skills/…
7. Check dependencies — detect and error on circular deps
8. Prompt for userConfig values if defined
9. Add to enabledPlugins in settings.json
10. Load plugin capabilities into session

Loading on startup (5 steps)

1. assemblePluginLoadResult() — parallel loading from marketplace, session (--plugin-dir), and built-in sources
2. mergePluginSources() — session plugins override marketplace by name; policy wins over all
3. verifyAndDemote() — unsatisfied deps demote plugin to disabled
4. createPluginFromPath() per plugin — reads manifest, auto-detects dirs, loads hooks and .mcp.json
5. Register capabilities: commands, skills, agents, output styles, hooks, MCP servers, LSP servers

Caching & auto-update

Plugins are version-checked on startup. Cache supports ZIP mode. If forceRemoveDeletedPlugins: true in the marketplace, removed plugins are auto-disabled.

/plugin Command

Aliases: /plugins, /marketplace

Command Description
/plugin 打开交互式插件管理菜单
/plugin install [name@marketplace] 从 marketplace 安装插件
/plugin manage 管理已安装的插件(启用/禁用/配置)
/plugin uninstall <name> 移除插件
/plugin enable <name> 启用已禁用的插件
/plugin disable <name> 禁用插件
/plugin validate [path] 验证插件 manifest
/plugin marketplace add <source> 添加 marketplace 源
/plugin marketplace remove <name> 移除 marketplace 源
/plugin marketplace update [name] 更新 marketplace 索引
/plugin marketplace list 列出已配置的 marketplace

Permissions & Enterprise Policies

Policy controls

Setting Description
allowedPlugins 允许的插件白名单(namename@marketplace
deniedPlugins 拒绝列表 — 始终优先于允许列表(失败关闭)
strictPluginOnlyCustomization 将表面(如 mcp)锁定为仅插件 — 用户配置的 MCP 服务器被阻止

Plugin MCP server naming

plugin:<pluginName>:<serverName>

Deduplicated against manually-configured servers — manual wins. Plugin MCP servers follow the same permission system as regular MCP tools.

Plugin ID format

// String
"my-plugin@my-marketplace"

// Object with options
{
  "id": "my-plugin@my-marketplace",
  "version": "^1.0.0",
  "required": true,
  "config": { "API_KEY": "value" }
}

Both parts validated: [a-z0-9][-a-z0-9._]*

! No built-in plugins are registered yet
The plugin system scaffolding is complete — manifests, marketplace, installation, loading, and policy controls are all implemented. However, src/plugins/bundled/index.ts currently registers zero built-in plugins. The infrastructure exists for migrating bundled skills to user-toggleable plugin form, but as of the current source the built-in registry is empty.