命令字典
Slash 命令、CLI 子命令、Hook 事件、启动参数的字典与演进史。
Slash 命令、CLI 子命令、Hook 事件、启动参数的字典与演进史。
管理 Claude Code 插件
claude plugin <subcommand>claude plugin install code-review@claude-plugins-officialclaude plugin(别名 claude plugins)是 Claude Code CLI 中管理 plugin 的子命令组。官方 CLI 参考表中的描述是 "Manage Claude Code plugins",示例为 claude plugin install code-review@claude-plugins-official。
按官方 plugins-reference 文档,该命令组包含以下子命令:
| 子命令 | 作用 |
|---|---|
install | 从 marketplace 安装 plugin |
uninstall | 移除已安装的 plugin |
enable / disable | 启用 / 停用 plugin,不卸载 |
update | 更新一个或全部 plugin |
list | 显示已安装 plugin 及状态 |
validate | 校验 plugin 的 manifest 与配置 |
init(别名 new) | 脚手架生成新 plugin |
marketplace ... | 管理 marketplace(官方文档中出现 add / list / update,见下) |
details | 查看 plugin 提供的组件清单(discover-plugins 页面提到,该页未给出语法) |
claude plugin install <plugin>[@<marketplace>] [options]
claude plugin uninstall <plugin> [options]
claude plugin enable <plugin> [options]
claude plugin disable <plugin> [options]
claude plugin update [plugin] [options]
claude plugin list
claude plugin validate <plugin-path> [--strict]
claude plugin init <name> [options]
<plugin> 可写作 plugin-name 或 plugin-name@marketplace-name。
install 选项| 选项 | 说明 |
|---|---|
-s, --scope <scope> | 安装范围:user(默认)/ project / local |
--config <key=value> | 设置 plugin manifest 中声明的 userConfig 选项,可重复 |
-y, --yes | 无确认地接受 marketplace 声明的 command;stdin/stdout 不是 TTY 时必需(除非使用 --accept-command) |
--accept-command <sha256> | 按 SHA256 摘要接受 marketplace 声明的 command(摘要来自之前的 --json 运行);不能与 -y 同用;需 v2.1.271+ |
--json | 在 stdout 最后一行输出 JSON 结果;需 v2.1.268+ |
| 子命令 | 选项 |
|---|---|
uninstall | --keep-data(保留 plugin 的持久数据目录)、--json |
enable / disable / update | --json |
validate | --strict(把警告视为错误,如拼错字段、来自其他工具 manifest 的字段) |
init | --description、--author、--author-email、--with <components...>(skills agents hooks mcp lsp output-style channel)、-f, --force |
官方文档中出现的 shell 形式:
claude plugin marketplace list
claude plugin marketplace update <marketplace-name>
claude plugin marketplace add --claudeai claudeai-organization-library # 需 v2.1.273+
marketplace add 的 source 可以是 GitHub owner/repo、Git URL、本地路径或远程 marketplace.json URL。文档中的 add / remove 示例主要以会话内 /plugin marketplace ... 形式给出;remove 的 shell 形式在已抓取的官方页面中没有直接示例。
claude --plugin-dir ./my-plugin # 仅本次会话加载目录或 .zip
claude --plugin-url https://example.com/plugin.zip
--plugin-dir 传入 plugin 文件夹(而非单个 plugin)需要 v2.1.265+。
退出码:已抓取的官方文档没有给出 claude plugin 的退出码表,此处不作断言。
--json 输出:结果为最后一行 stdout 的 JSON 对象。
| 字段 | 出现条件 |
|---|---|
command、outcome(ok 或 failed)、message | 始终 |
pluginId、scope、failureCode、shownCommand | 视情况;shownCommand 在 marketplace 声明了 command 时出现 |
list 的文本输出按来源分组(marketplace、synced from claude.ai、skills-directory 等),显示启用/停用状态与版本,并标注 required by your org 的必需 plugin。
官方文档明确说明 claude plugin install 可无交互运行:
# 安装到项目范围(写入 .claude/settings.json,团队共享)
claude plugin install formatter@my-marketplace --scope project
# 非 TTY 环境(provisioning 脚本)接受 marketplace 声明的 command
claude plugin install my-plugin@your-marketplace --yes
# 先 --json 取得 shownCommand 的 sha256,再按摘要接受
claude plugin install <plugin>@<marketplace> --accept-command <sha256>
# 脚本化读取结果
claude plugin install plugin-name --json
容器 / CI 预置(plugin-marketplaces 文档):构建时用 CLAUDE_CODE_PLUGIN_CACHE_DIR 预装,运行时用 CLAUDE_CODE_PLUGIN_SEED_DIR 指向同一目录:
CLAUDE_CODE_PLUGIN_CACHE_DIR=/opt/claude-seed claude plugin marketplace add your-org/plugins
CLAUDE_CODE_PLUGIN_CACHE_DIR=/opt/claude-seed claude plugin install my-tool@your-plugins
# 运行时:CLAUDE_CODE_PLUGIN_SEED_DIR=/opt/claude-seed
seed 目录只读,seed marketplace 不自动更新,对 seed 管理的 marketplace 执行 remove / update 会失败。多个 seed 目录在 Unix 用 : 分隔,Windows 用 ;。
| 维度 | claude plugin ...(shell) | /plugin ...(会话内) |
|---|---|---|
| 界面 | 不打开面板,适合脚本 | /plugin disable/enable/uninstall 会打开 plugin 面板并保持打开,需按 Esc 关闭 |
| 生效时机 | 不在会话中运行;下次启动 Claude Code,或在已开会话里执行 /reload-plugins 后加载 | 面板关闭时自动运行 /reload-plugins;若会使 prompt cache 失效则给出警告并保持待定,可用 /reload-plugins --force |
| 安装范围 | 默认 user,用 --scope 指定 | /plugin install 打开详情页,在其中选择范围 |
| marketplace 刷新 | 写 plugin@marketplace 时会先刷新该 marketplace;只写 plugin 名时读缓存目录、不刷新 | 只写 plugin 名时,仅在查找未命中后刷新会后台更新的 marketplace |
| 约束 | 原因 / 来源 |
|---|---|
非 TTY 下若 marketplace 声明了 command,必须 --yes 或 --accept-command | 官方 install 选项说明 |
--yes 与 --accept-command 不能同用 | 官方 install 选项说明 |
managed 范围的 plugin 由管理员通过 managed settings 安装,不可修改 | 官方文档 |
组织通过 strictKnownMarketplaces / managed settings 限制时,被阻止的 marketplace 会拒绝安装 | discover-plugins、plugin-marketplaces 文档 |
| 从 claude.ai 同步的 plugin 不能在 CLI 中删除,需在 claude.ai 关闭(组织标记为 required 的连启停都不行) | discover-plugins 文档 |
未设 --scope 时 install 装到 user 范围 | 官方文档 |
claude plugin install 不在会话内运行。已开着的会话要执行 /reload-plugins,否则等下次启动。name 一致:文档指出标识符里的 plugin-name 是 marketplace entry 的 name,可能与 plugin 自己 plugin.json 里的 name 不同。claude plugin install plugin-name 读取缓存的 catalog,不刷新。要装刚发布的 plugin,先 claude plugin marketplace update <name> 再重试,或写全 plugin@marketplace。--scope:官方示例为 claude plugin uninstall formatter@your-org --scope project。需注意 plugins-reference 中 uninstall 的选项表没有列出 --scope,而 discover-plugins 的示例使用了它,不确定时以本机 claude plugin uninstall --help 为准。github.com / gitlab.com / Azure DevOps 外,https 地址需带 .git 后缀,否则会被当作托管的 marketplace.json 直链;主机名前需带 https://(v2.1.196 起缺少前缀直接报错)。