Files
Luong NGUYEN 5609e68a6c docs: sync to Claude Code v2.1.325 (#277)
Type: docs

Syncs the tutorial, its translations and the root README from Claude Code v2.1.323 to v2.1.325 (P1 3, P3 10, P4 1; 37 files: 7 English, 30 translations). npm published 2.1.324 and 2.1.325 on 2026-11-13. The upstream CHANGELOG has no 2.1.324 section; everything is listed under 2.1.325.

## Changes by priority

### P1
- **Sandboxed commands no longer skip prompts by default** (09-advanced-features).
  - `sandbox.autoAllowBashIfSandboxed` now defaults to `false`, so sandboxed Bash commands go through your allow rules and permission mode.
  - The new note shows how to get auto-allow back and what still prompts with `true`, including commands such as `FOO=bar npm test`, `make CC=clang` or `eval "ls"`, and that plan mode doesn't widen approvals.
  - The settings table gains the key, and the `/sandbox` line names the Mode tab.
  - Dated "since v2.1.324 per the settings reference; the changelog lists it in v2.1.325".
  - `config-examples.json` is unchanged: its `autonomous` preset relies on auto mode's classifier and promises no prompt-free sandboxing.
  - Sources: https://code.claude.com/docs/en/settings-reference#sandbox-autoallowbashifsandboxed, https://code.claude.com/docs/en/sandboxing#auto-allow-mode
- **`/stickers`** is now "Check Claude Code sticker availability" (01-slash-commands, CATALOG). This was a standing docs-vs-changelog item; the docs now agree with the changelog. https://code.claude.com/docs/en/commands
- **Prompt-suggestion keys** (09): `Tab` or `Right arrow` places the suggestion, then `Enter` submits. The guide used to say `Enter` accepts and submits at once. https://code.claude.com/docs/en/interactive-mode#prompt-suggestions

### P3
All in-range. Each changelog-only item says that the docs don't list it yet.

**09-advanced-features**
- `sandbox.failIfUnavailable` doesn't stop cloud sessions from starting.
- The sandbox refuses `.claude` writes in added directories too.
- VS Code prompt suggestions, and `promptSuggestionEnabled`, which `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` takes precedence over (https://code.claude.com/docs/en/vs-code#use-or-turn-off-suggested-prompts, https://code.claude.com/docs/en/settings-reference#promptsuggestionenabled).
- Scheduled tasks and `/loop` ask before running a skill that declares `allowed-tools` or hooks (`Skill(name)` in `permissions.allow`), plus the "Always allow" change.
- `claude remote-control` exit status 4 and 69.
- `/resume` and `/teleport` disconnect when the session has a share link (https://code.claude.com/docs/en/remote-control#what-connected-devices-see).
- `WorktreeCreate` refuses a path through a symlink, and since v2.1.325 `EnterWorktree` does too (https://code.claude.com/docs/en/hooks).
- Worktree-isolation refusals: `git bisect run`, `git maintenance register|start`, `scalar`.
- The existing v2.1.157 "left unlocked" sentence now adds that non-interactive `-p` runs keep the lock on their worktrees until a later session's stale-lock sweep (https://code.claude.com/docs/en/worktrees#clean-up-worktrees).

**10-cli**
- A "Permission hardening (v2.1.325)" note:
  - read-only git commands ask first outside the project or a trusted repo (use `--add-dir`);
  - relative deny and ask rules keep covering the project after `cd`, and now apply in added directories;
  - the Bash allow-rule and compound-command fixes;
  - the `plansDirectory` fallback.
- A `CLAUDE_CODE_MAX_CONTEXT_TOKENS` row (https://code.claude.com/docs/en/model-config#which-ids-claude_code_max_context_tokens-applies-to).

**07-plugins**
- Marketplace-source `ref` accepts a full commit SHA (https://code.claude.com/docs/en/plugins/marketplace-reference#marketplace-sources).
- Plugin loading skips, and `claude plugin validate` reports, unsafe paths and links.
- `prependPlugins`/`appendPlugins` plugins count as the organization's (v2.1.324 per the mods admin docs), and `pluginDigests` is deprecated (changelog-only).
- Nested `.claude/skills` in `--plugin-dir` plugins no longer load from a session started above them.
- `.mcpb`/`.dxt` bundles unpack into `mcpb/` under the plugins root (https://code.claude.com/docs/en/plugins/loading#find-plugins-on-disk).

**04-subagents**
- tmux and iTerm2 teammates start in the session's folder.
- An unrecognized `teammateMode` value is now listed as skipped.

### P4
- Root README: the badge, line 105 and line 204 now say v2.1.325, and the footer is refreshed.

## Translation coverage

Locales are vi, zh, uk, ja, ko and fa. For each fix I grepped the key token across `*/<file>` in every locale.

| Fix | Done | Not done, and why |
|---|---|---|
| Sandbox default, prompt keys, cloud `failIfUnavailable`, added-dir writes, VS Code suggestions, scheduled-task skills, Remote Control (09) | vi, uk, ja, ko, fa | zh: its 09 sandbox and prompt-suggestion sections are condensed, with no table and no prompt claim |
| Worktree row (09) | vi, uk, ja, ko, fa | zh: condensed |
| Worktree-isolation note (09) | vi, uk, ja, ko, fa | zh: condensed |
| Auto-allow note: other regular-flow commands and the plan-mode limit (09) | vi, uk, ja, ko, fa | zh: no auto-allow note |
| `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` precedence sentence, worded as env-vars gives it (09) | vi, uk, ja, ko, fa | zh: no `promptSuggestionEnabled` paragraph |
| `-p` worktree-lock qualifier on the v2.1.157 sentence (09) | vi, ko, fa | uk, ja, zh: no v2.1.157 "left unlocked" sentence |
| `/stickers` | 01: vi, uk, ja, ko, fa; CATALOG: all six | zh 01 has no row |
| 10-cli hardening note, `CLAUDE_CODE_MAX_CONTEXT_TOKENS` row | vi, ko, fa | zh: no hardening notes and no matching env rows; uk, ja: no `CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT` anchor row; 10 not synced to 2.1.325 in uk/ja |
| 07: marketplace `ref` paragraph, `pluginDigests` note with v2.1.324 dating, mods admin Sources entry | all six | — |
| 07: validate sentence, loading-changes note | vi, ko, fa | zh, uk, ja: no validate paragraph, and no `--plugin-url` local-plugin block |
| 04 teammate note | vi, uk, ja, ko, fa | zh: no split-pane text |

**Footers**
- Bumped to 2.1.325 only where the page was at the previous English level:
  - 09: en, vi, uk, ja, ko, fa
  - 07, 10: en, vi, ko, fa
  - 04: en, vi, uk, ja, ko, fa
  - 01, CATALOG: en, ko, fa
- Pages that lag English stay as they were, even where this PR edits them:
  - 01 vi/uk/ja at 2.1.316
  - CATALOG vi/zh/uk at 2.1.302, ja at 2.1.316
  - 07 zh/uk/ja at 2.1.302
- Locale READMEs are untouched.

## Learner skills

- I audited both skills against 2.1.325: sandbox, permissions, `/loop` and scheduled tasks, plugins, worktrees, Remote Control and prompt suggestions.
- No question, option, `Correct` letter or `- **Review**:` pointer changed.
- No file changed, and no version was bumped: lesson-quiz stays at 1.6.6 and self-assessment at 2.5.8.

## Needs maintainer decision

**New docs-vs-changelog conflicts:** none needing a guide edit.

**Version dating.** The docs date six 2.1.325 changelog items to v2.1.324. The guide names both sources, per the brief:
- the `sandbox.autoAllowBashIfSandboxed` default: https://code.claude.com/docs/en/settings-reference#sandbox-autoallowbashifsandboxed
- `CLAUDE_CODE_MAX_CONTEXT_TOKENS` for `claude-` IDs: https://code.claude.com/docs/en/model-config#which-ids-claude_code_max_context_tokens-applies-to
- the Remote Control share-link check: https://code.claude.com/docs/en/remote-control#what-connected-devices-see
- the marketplace `ref` SHA and the `mcpb/` folder: https://code.claude.com/docs/en/plugins/marketplace-reference#marketplace-sources, https://code.claude.com/docs/en/plugins/loading#find-plugins-on-disk
- plugins of a remote marketplace counting as the organization's: https://code.claude.com/docs/en/plugins/mods/admin#install-your-organizations-mods

**Read-only git commands.** Not a conflict: permissions.md's 'in every mode' is about permission modes and already has location exceptions (`blockReadsOutsideWorkingDirectories`; `cd` + `git` prompts). The changelog adds one more location exception; the guide attributes it to the changelog.

**Ten standing items, rechecked 2026-11-14 against freshly fetched pages.**

The docs now agree with the changelog on four:
- `/stickers`: resolved to the docs in this PR.
- `CLAUDE_CODE_PLUGIN_DIR_WATCH`: env-vars now says skills-directory mods reload in non-interactive sessions and `0` turns reloading off. The guide has no sentence on it, so nothing changed.
- Mods' own tool calls: the mods admin page now says `$.mcp.call` runs "with no permission prompt". The guide has no sentence on it, so nothing changed.
- `CLAUDE_CODE_OVERLOADED_RETRY_MAX_DELAY_MS`: env-vars now allows 32000 to 300000, with values above 64000 needing v2.1.323. The guide has no row, so nothing changed.

Six still disagree. Repo / docs / changelog for each:
1. **Self-paced `/loop` ending.**
   - Repo: no sentence.
   - Docs: a fallback wakeup after about 20 minutes.
   - Changelog 2.1.319: the loop ends.
   - https://code.claude.com/docs/en/scheduled-tasks#stop-a-loop
2. **Auto mode with telemetry or flags off.**
   - Repo: no sentence.
   - Docs: "falls back to its own classifier requests".
   - Changelog 2.1.319: no fallback.
   - https://code.claude.com/docs/en/permission-modes#server-side-classifier-review
3. **MCP tasks.**
   - Repo, 05-mcp: they need feature-flag fetching.
   - Docs: the same.
   - Changelog 2.1.319: they work without flag fetching.
   - https://code.claude.com/docs/en/mcp#mcp-tasks-that-run-on-the-server
4. **`deniedMcpServers` `serverUrl` vs connectors.**
   - Repo: no sentence.
   - Docs: a connector's own URL doesn't match.
   - Changelog 2.1.318: it blocks those connectors.
   - https://code.claude.com/docs/en/mcp#how-connectors-reach-claude-code
5. **Context window for an unrecognized model ID.**
   - Repo: no sentence. The new `CLAUDE_CODE_MAX_CONTEXT_TOKENS` row states no assumed window.
   - Docs: assumes 200K.
   - Changelog 2.1.323: assumes 1M.
   - https://code.claude.com/docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id
6. **`MCP_SDK_GENERATION=v1`.**
   - Repo: no sentence.
   - Docs: picks the v1 runtime.
   - Changelog 2.1.323: the v1 client is removed, and `v1` runs v2 in compatibility mode.
   - https://code.claude.com/docs/en/env-vars

## Follow-ups

- **Changelog items not added**, because the guide doesn't teach the surface:
  - `claude -p` waiting for account data;
  - `/login` privacy permission;
  - `/cost` and `--max-budget-usd` counting mods' model calls;
  - plugin downloads using a CONNECT tunnel with `ALL_PROXY` only;
  - `user_prompt` `delivery.mode: "mid_turn"`;
  - MCP tool descriptions of 16,384 characters in cloud sessions;
  - subagents re-asked at the output limit;
  - Esc on an MCP task question.
- **Locales behind English.** zh, uk and ja 07/09/10 still need a catch-up sync beyond this release.
- uk/ja 10-cli env tables could take the `CLAUDE_CODE_MAX_CONTEXT_TOKENS` row (catch-up sync).
- **Possible merge conflicts with open PRs:**
  - #173 edits the root README near line 105.
  - #189 edits the README footer Sources.
  - #225 edits `CATALOG.md` (different hunks).

## Validation

- `SKIP=mermaid,vietnamese-mermaid,japanese-mermaid,korean-mermaid,persian-mermaid pre-commit run --all-files` exited 0, before and after the edits. Link-check reached 247 URLs on a clean tree.
- `python scripts/check_mermaid.py --strict`: Pele 1.6.0 rendered 416 blocks.
- `python scripts/check_cross_references.py`: 674 files valid on a clean tree.
- The EPUB build was not run.

## Sources

- https://code.claude.com/docs/en/changelog#2-1-325
- https://raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md
- https://code.claude.com/docs/en/settings-reference#sandbox-autoallowbashifsandboxed
- https://code.claude.com/docs/en/sandboxing#auto-allow-mode
- https://code.claude.com/docs/en/commands
- https://code.claude.com/docs/en/interactive-mode#prompt-suggestions
- https://code.claude.com/docs/en/vs-code#use-or-turn-off-suggested-prompts
- https://code.claude.com/docs/en/settings-reference#promptsuggestionenabled
- https://code.claude.com/docs/en/remote-control#what-connected-devices-see
- https://code.claude.com/docs/en/hooks
- https://code.claude.com/docs/en/model-config#which-ids-claude_code_max_context_tokens-applies-to
- https://code.claude.com/docs/en/plugins/marketplace-reference#marketplace-sources
- https://code.claude.com/docs/en/plugins/loading#find-plugins-on-disk
- https://code.claude.com/docs/en/permissions#read-only-commands
- https://code.claude.com/docs/en/plugins/mods/admin#install-your-organizations-mods
- https://code.claude.com/docs/en/worktrees#clean-up-worktrees
2026-11-14 15:16:12 +01:00
..

Claude How To

Claude Code 插件

这个目录包含一组完整的插件示例,它们把多个 Claude Code 功能打包成可安装的一体化方案。

介绍

Claude Code 插件是把 slash commands、subagents、MCP servers 和 hooks 组合在一起的功能集合,可以通过一条命令安装。它们代表了 Claude Code 最高级别的扩展方式,把多个功能整合成可共享、可复用的完整方案。

概览

一个插件通常会把以下能力打包在一起:

  • slash commands
  • subagents
  • MCP servers
  • hooks

这样做的好处是:

  • 一次安装即可使用完整工作流
  • 团队共享更容易
  • 配置更统一
  • 便于版本控制和分发

插件架构

graph TB
    A["插件"]
    B["Slash Commands"]
    C["Subagents"]
    D["MCP Servers"]
    E["Hooks"]
    F["Configuration"]

    A -->|打包| B
    A -->|打包| C
    A -->|打包| D
    A -->|打包| E
    A -->|打包| F

插件类型与分发

类型 范围 共享对象 维护者 示例
官方 全局 所有用户 Anthropic PR 审查、安全指导
社区 公开 所有用户 社区 DevOps、数据科学
组织 内部 团队成员 公司 内部规范、工具
个人 个人 单个用户 开发者 自定义工作流

插件定义结构

插件清单使用 .claude-plugin/plugin.json 中的 JSON 格式:

{
  "name": "my-first-plugin",
  "description": "一个问候插件",
  "version": "1.0.0",
  "author": {
    "name": "Your Name"
  },
  "homepage": "https://example.com",
  "repository": "https://github.com/user/repo",
  "license": "MIT"
}

插件结构示例

my-plugin/
├── .claude-plugin/
│   └── plugin.json       # 清单(名称、描述、版本、作者)
├── commands/             # 以 Markdown 文件形式存放的命令
│   ├── task-1.md
│   ├── task-2.md
│   └── workflows/
├── agents/               # 自定义 agent 定义
│   ├── specialist-1.md
│   ├── specialist-2.md
│   └── configs/
├── skills/               # 带有 SKILL.md 文件的技能
│   ├── skill-1/
│   │   └── SKILL.md
│   └── skill-2/
│       └── SKILL.md
├── hooks/                # hooks.json 中的事件处理器
│   └── hooks.json
├── .mcp.json             # MCP server 配置
├── .lsp.json             # LSP server 配置
├── settings.json         # 默认设置
├── templates/
│   └── issue-template.md
├── scripts/
│   ├── helper-1.sh
│   └── helper-2.py
├── docs/
│   ├── README.md
│   └── USAGE.md
└── tests/
    └── plugin.test.js

LSP server 配置

插件可以包含 Language Server Protocol(LSP)支持,以获得实时代码智能。LSP server 会在你编写代码时提供诊断、代码导航和符号信息。

配置位置:

  • 插件根目录中的 .lsp.json 文件
  • plugin.json 中的内联 lsp 键

字段参考

字段 必填 说明
command 是 LSP server 可执行文件(必须在 PATH 中)
extensionToLanguage 是 将文件扩展名映射到语言 ID
args 否 server 的命令行参数
transport 否 通信方式:stdio(默认)或 socket
env 否 server 进程的环境变量
initializationOptions 否 LSP 初始化期间发送的选项
settings 否 传递给 server 的工作区配置
workspaceFolder 否 覆盖工作区文件夹路径
startupTimeout 否 等待 server 启动的最长时间(毫秒)
shutdownTimeout 否 优雅关闭的最长时间(毫秒)
restartOnCrash 否 server 崩溃时自动重启
maxRestarts 否 放弃前的最大重启次数

示例配置

Go(gopls):

{
  "go": {
    "command": "gopls",
    "args": ["serve"],
    "extensionToLanguage": {
      ".go": "go"
    }
  }
}

Python(pyright):

{
  "python": {
    "command": "pyright-langserver",
    "args": ["--stdio"],
    "extensionToLanguage": {
      ".py": "python",
      ".pyi": "python"
    }
  }
}

TypeScript:

{
  "typescript": {
    "command": "typescript-language-server",
    "args": ["--stdio"],
    "extensionToLanguage": {
      ".ts": "typescript",
      ".tsx": "typescriptreact",
      ".js": "javascript",
      ".jsx": "javascriptreact"
    }
  }
}

可用的 LSP 插件

官方市场包含了预配置好的 LSP 插件:

插件 语言 Server Binary 安装命令
pyright-lsp Python pyright-langserver pip install pyright
typescript-lsp TypeScript/JavaScript typescript-language-server npm install -g typescript-language-server typescript
rust-analyzer-lsp Rust rust-analyzer 使用 rustup component add rust-analyzer 安装

LSP 能力

配置完成后,LSP server 会提供:

  • 即时诊断 - 编辑后立即显示错误和警告
  • 代码导航 - 跳转到定义、查找引用和实现
  • 悬浮信息 - 在悬停时查看类型签名和文档
  • 符号列表 - 浏览当前文件或工作区中的符号

如果插件的 language server 无法启动,/plugin 的 Errors 标签页会显示失败及其原因;自 v2.1.323 起,Claude Code 还会显示一条警告,指明该 server 以及需要检查的内容。

插件选项(v2.1.83+)

插件可以在清单中通过 userConfig 声明用户可配置选项。标记为 sensitive: true 的值会存储在系统钥匙串中,而不是明文设置文件里:

{
  "name": "my-plugin",
  "version": "1.0.0",
  "userConfig": {
    "apiKey": {
      "type": "string",
      "title": "API key",
      "description": "服务的 API key",
      "sensitive": true
    },
    "region": {
      "type": "string",
      "title": "Region",
      "description": "部署区域",
      "default": "us-east-1"
    }
  }
}

持久化插件数据(${CLAUDE_PLUGIN_DATA})(v2.1.78+)

插件可以通过 ${CLAUDE_PLUGIN_DATA} 环境变量访问一个持久化状态目录。这个目录对每个插件都是唯一的,并且会跨会话保留,适合缓存、数据库和其他持久化状态:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "node \"${CLAUDE_PLUGIN_ROOT}\"/scripts/track-usage.js \"${CLAUDE_PLUGIN_DATA}\"/usage.json"
          }
        ]
      }
    ]
  }
}

该目录(~/.claude/plugins/data/<id>/)在首次被引用时创建,并在插件更新后保留。当你从插件安装的最后一个位置卸载插件时,该目录会被删除(除非传入 --keep-data)。

通过设置文件内联定义插件(source: 'settings')(v2.1.80+)

插件可以在设置文件中以内联市场条目的方式定义,使用 source: 'settings' 字段即可。这允许你直接嵌入插件定义,而不必单独准备仓库或市场。请在 extraKnownMarketplaces.<name>.source 下声明,name 必须与市场键名一致,其中的插件必须引用 GitHub 或 npm 等外部源(相对路径会被拒绝):

{
  "extraKnownMarketplaces": {
    "inline-tools": {
      "source": {
        "source": "settings",
        "name": "inline-tools",
        "plugins": [
          {
            "name": "quick-lint",
            "source": {
              "source": "github",
              "repo": "my-org/quick-lint"
            }
          }
        ]
      }
    }
  }
}

插件设置

插件可以提供一个 settings.json 文件来定义默认配置。只有 agent 键生效,其他键都会被丢弃。v2.1.323 移除了 subagentStatusLine 设置,因此 subagent 行始终使用默认外观,仍包含该键的设置文件照常加载。agent 填写插件中某个 agent 的名称,并将其作为主线程运行。自 v2.1.323 起该键已弃用:它仍然生效,但 Claude Code 会在启动时、在 claude plugin list 和 claude plugin validate 中对其发出警告:

{
  "agent": "specialist-1"
}

当插件包含 settings.json 时,这些默认值会在安装时自动应用。用户也可以在自己的项目或用户级配置中覆盖它们。

独立命令 vs 插件方式

方式 命令名称 配置方式 最适合
独立命令 /hello 在 CLAUDE.md 中手动设置 个人、项目专用
插件 /plugin-name:hello 通过 plugin.json 自动配置 共享、分发、团队使用

对于快速的个人工作流,使用 独立 slash commands。当你想打包多个功能、与团队共享或者发布分发时,使用 插件。

实际示例

示例 1:PR 审查插件

文件: .claude-plugin/plugin.json

{
  "name": "pr-review",
  "version": "1.0.0",
  "description": "包含安全、测试和文档检查的完整 PR 审查工作流",
  "author": {
    "name": "Anthropic"
  },
  "repository": "https://github.com/your-org/pr-review",
  "license": "MIT"
}

文件: commands/review-pr.md

这个文件会成为 /pr-review:review-pr:插件的 name 加上文件名。

---
description: 启动包含安全和测试检查的完整 PR 审查
---

# PR Review

这个命令会启动一次完整的 Pull Request 审查,包括:

1. 安全分析
2. 测试覆盖率验证
3. 文档更新
4. 代码质量检查
5. 性能影响评估

文件: agents/security-reviewer.md

---
name: security-reviewer
description: 面向安全的代码审查
tools: Read, Grep, Bash
---

# Security Reviewer

专注于发现安全漏洞:
- 身份验证/授权问题
- 数据暴露
- 注入攻击
- 安全配置

文件: hooks/hooks.json

当用户输入插件的某个命令时运行 hooks/pre-review.js。如果当前不在 git 仓库中,该脚本会阻止命令执行(退出码 2)。matcher 匹配的是 command_name,在 Claude Code 2.1.322 上,插件命令的 command_name 是 pr-review:review-pr;matcher 也接受不带前缀的 review-pr。args(exec 形式)把脚本路径作为单个参数传入,因此无需加引号:

{
  "hooks": {
    "UserPromptExpansion": [
      {
        "matcher": "^(pr-review:)?(review-pr|check-security|check-tests)$",
        "hooks": [
          {
            "type": "command",
            "command": "node",
            "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/pre-review.js"],
            "timeout": 30
          }
        ]
      }
    ]
  }
}

文件: .mcp.json

声明 GitHub 官方 MCP 服务器,以只读模式运行,token 取自 GITHUB_TOKEN。镜像固定在 v2.1.0 版本 的 tag 上,因此只有在你修改 tag 或发布者重新推送该 tag 时才会变化。按 digest 固定更严格:把 :v2.1.0 换成 @sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a,即 2026-11-12 时 v2.1.0 的 digest。该文件固定的是 tag:

{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
        "-e", "GITHUB_READ_ONLY",
        "ghcr.io/github/github-mcp-server:v2.1.0"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}",
        "GITHUB_READ_ONLY": "1"
      }
    }
  }
}

安装:

claude plugin validate ./07-plugins/pr-review
claude --plugin-dir ./07-plugins/pr-review

# Loads:
# ✅ 3 slash commands: /pr-review:review-pr, /pr-review:check-security, /pr-review:check-tests
# ✅ 3 subagents
# ✅ 1 MCP server: plugin:pr-review:github
# ✅ 1 hook: UserPromptExpansion → pre-review.js

示例 2:DevOps 插件

组件:

devops-automation/
├── commands/
│   ├── deploy.md
│   ├── rollback.md
│   ├── status.md
│   └── incident.md
├── agents/
│   ├── deployment-specialist.md
│   ├── incident-commander.md
│   └── alert-analyzer.md
├── hooks/
│   ├── hooks.json        # PreToolUse/PostToolUse on Bash
│   ├── pre-deploy.js
│   └── post-deploy.js
└── scripts/
    ├── deploy.sh
    ├── rollback.sh
    └── health-check.sh

hooks/hooks.json 会在每次 Bash 调用之前运行 pre-deploy.js,之后运行 post-deploy.js。这两个脚本从 hook 的 JSON 输入中读取命令,只对 kubectl apply 或 deploy.sh 这类部署命令生效。当 kubectl 无法连接到集群时,pre-deploy.js 以退出码 2 退出,阻止部署。该插件没有 MCP 服务器:hooks 和脚本直接调用 kubectl。

示例 3:文档插件

打包组件:

documentation/
├── commands/
│   ├── generate-api-docs.md
│   ├── generate-readme.md
│   ├── sync-docs.md
│   └── validate-docs.md
├── agents/
│   ├── api-documenter.md
│   ├── code-commentator.md
│   └── example-generator.md
├── templates/
│   ├── api-endpoint.md
│   ├── function-docs.md
│   └── adr-template.md
└── .mcp.json             # GitHub MCP server

插件市场

Anthropic 官方维护的插件目录是 anthropics/claude-plugins-official。企业管理员也可以创建私有插件市场用于内部分发。

graph TB
    A["插件市场"]
    B["官方<br/>anthropics/claude-plugins-official"]
    C["社区<br/>市场"]
    D["企业<br/>私有仓库"]

    A --> B
    A --> C
    A --> D

    B -->|分类| B1["开发"]
    B -->|分类| B2["DevOps"]
    B -->|分类| B3["文档"]

    C -->|搜索| C1["DevOps 自动化"]
    C -->|搜索| C2["移动开发"]
    C -->|搜索| C3["数据科学"]

    D -->|内部| D1["公司规范"]
    D -->|内部| D2["遗留系统"]
    D -->|内部| D3["合规"]

    style A fill:#e1f5fe,stroke:#333,color:#333
    style B fill:#e8f5e9,stroke:#333,color:#333
    style C fill:#f3e5f5,stroke:#333,color:#333
    style D fill:#fff3e0,stroke:#333,color:#333

市场配置

企业和高级用户可以通过设置来控制市场行为:

设置 说明
extraKnownMarketplaces 在默认列表之外添加额外的市场源
strictKnownMarketplaces 控制允许用户添加哪些市场
enabledPlugins(设为 false) 阻止特定插件:在 managed settings 中设置 "enabledPlugins": { "<plugin>@<marketplace>": false },即可在所有作用域阻止安装,并在市场中隐藏该插件

更友好的别名(v2.1.232):additionalMarketplaces 被接受为 extraKnownMarketplaces 的别名,allowedMarketplaces 为 strictKnownMarketplaces 的别名。官方 settings 参考页面已在 Marketplace key aliases 中列出这两个别名。旧版本会忽略别名,因此继续使用规范键名是安全的。

owner 通配符(v2.1.223+):"owner/*" 条目可允许或阻止某个 GitHub owner 名下的所有市场仓库。仅在 strictKnownMarketplaces 和 blockedMarketplaces 中被接受。 在其他出现 github 源的地方 —— 包括 extraKnownMarketplaces 和 /plugin marketplace add —— repo 的值必须指向单个仓库。

额外的市场特性

  • 默认 git 超时:对大型插件仓库从 30 秒增加到 120 秒
  • 自定义 npm registry:插件可以指定自定义 npm registry URL 用于依赖解析
  • 版本锁定:将插件锁定到特定版本,以获得可复现的环境

市场定义 schema

插件市场定义在 .claude-plugin/marketplace.json 中:

{
  "name": "my-team-plugins",
  "owner": { "name": "my-org" },
  "plugins": [
    {
      "name": "code-standards",
      "source": "./plugins/code-standards",
      "description": "强制执行团队编码规范",
      "version": "1.2.0",
      "author": { "name": "platform-team" }
    },
    {
      "name": "deploy-helper",
      "source": {
        "source": "github",
        "repo": "my-org/deploy-helper",
        "ref": "v2.0.0"
      },
      "description": "部署自动化工作流"
    }
  ]
}
字段 必填 说明
name 是 使用 kebab-case 的市场名称
owner 是 维护该市场的组织或用户:包含必填 name 的对象(email、url 可选)
plugins 是 插件条目数组
plugins[].name 是 插件名称(kebab-case)
plugins[].source 是 插件来源(路径字符串或来源对象)
plugins[].description 否 插件的简要描述
plugins[].version 否 语义化版本字符串
plugins[].author 否 插件作者:包含必填 name 的对象(email、url 可选)

插件来源类型

插件可以来自多个位置:

来源 语法 示例
相对路径 字符串路径 "./plugins/my-plugin"
GitHub { "source": "github", "repo": "owner/repo" } { "source": "github", "repo": "acme/lint-plugin", "ref": "v1.0" }
Git URL { "source": "url", "url": "..." } { "source": "url", "url": "https://git.internal/plugin.git" }
Git 子目录 { "source": "git-subdir", "url": "...", "path": "..." } { "source": "git-subdir", "url": "https://github.com/org/monorepo.git", "path": "packages/plugin" }
npm { "source": "npm", "package": "..." } { "source": "npm", "package": "@acme/claude-plugin", "version": "^2.0" }

GitHub 和 git 来源支持可选的 ref(分支/标签)和 sha(提交哈希)字段用于版本锁定。

市场来源(github 或 git,写在 extraKnownMarketplaces 中,或在添加市场时写成 owner/repo@ref)同样接受 ref:一个分支、一个标签,或某个分支或标签上一次提交的完整小写 SHA。根据市场参考文档,SHA 锁定需要 v2.1.324 或更高版本(changelog 将其列在 v2.1.325),并且对 claude-plugins-official 这类保留市场名称会被拒绝。早于该版本的客户端无法克隆这种锁定,因此以这种方式锁定的市场在这些客户端上会停止加载。

分发方式

GitHub(推荐):

# 用户添加你的市场
/plugin marketplace add owner/repo-name

其他 git 服务(需要完整 URL):

/plugin marketplace add https://gitlab.com/org/marketplace-repo.git

私有仓库:可以通过 git credential helper 或环境令牌支持。用户必须有该仓库的读取权限。

提交到 Anthropic 目录:通过开发者门户 claude.ai/directory/manage 将插件提交到 Anthropic 的目录,以便更广泛分发。Anthropic 官方市场 claude-plugins-official 不通过目录门户接受提交。

严格模式

控制市场定义与本地 plugin.json 文件的交互方式:

设置 行为
strict: true(默认) 本地 plugin.json 为权威来源;市场条目会对其进行补充
strict: false 市场条目就是完整的插件定义

配合 strictKnownMarketplaces 的组织限制:

值 效果
未设置 无限制,用户可以添加任意市场
空数组 [] 锁定模式,不允许任何市场
源对象数组 白名单模式,只允许匹配的市场被添加
{
  "strictKnownMarketplaces": [
    { "source": "github", "repo": "my-org/*" },
    { "source": "github", "repo": "trusted-vendor/*" }
  ]
}

警告:在带有 strictKnownMarketplaces 的严格模式下,用户只能从白名单市场安装插件。这适用于需要受控插件分发的企业环境。

插件安装与生命周期

graph LR
    A["发现"] -->|浏览| B["市场"]
    B -->|选择| C["插件页"]
    C -->|查看| D["组件"]
    D -->|安装| E["/plugin install"]
    E -->|解包| F["配置"]
    F -->|激活| G["使用"]
    G -->|检查| H["更新"]
    H -->|可用| G
    G -->|完成| I["禁用"]
    I -->|稍后| J["启用"]
    J -->|返回| G

插件能力对比

功能 Slash Command Skill Subagent Plugin
安装 手动复制 手动复制 手动配置 一条命令
设置时间 5 分钟 10 分钟 15 分钟 2 分钟
打包 单文件 单文件 单文件 多文件
版本管理 手动 手动 手动 自动
团队共享 复制文件 复制文件 复制文件 安装 ID
更新 手动 手动 手动 自动可用
依赖 无 无 无 可能包含
市场 否 否 否 是
分发 仓库 仓库 仓库 市场

插件 CLI 命令

所有插件操作都可以通过 CLI 命令完成:

claude plugin install <name>@<marketplace>   # 从市场安装
claude plugin uninstall <name>               # 删除插件
claude plugin list                           # 列出已安装插件
claude plugin enable <name>                  # 启用已禁用的插件
claude plugin disable <name>                 # 禁用插件
claude plugin validate <path>                # 验证 <path> 处的插件结构

安装方式

从市场安装

/plugin install plugin-name
# 或通过 CLI:
claude plugin install plugin-name@marketplace-name

是否立即生效? 自 v2.1.221 起通常会立即生效 —— 请查看安装摘要的最后一行:

安装摘要显示 含义
Plugin is now active. Claude Code 已在安装过程中激活该插件,无需其他操作。
Run /reload-plugins to activate. 插件已安装但尚未生效 —— 要么激活会使 prompt cache 失效,要么激活尝试失败。

在 v2.1.221 之前,任何安装都要等到你运行 /reload-plugins 或重启后才会在当前会话中生效。

启用 / 禁用(自动检测作用域)

/plugin enable plugin-name
/plugin disable plugin-name

本地插件(用于开发)

# 本地测试的 CLI 参数(可重复指定多个插件)
claude --plugin-dir ./path/to/plugin
claude --plugin-dir ./plugin-a --plugin-dir ./plugin-b

从 Git 仓库安装

/plugin marketplace add username/repo                    # 将 GitHub 仓库添加为市场
/plugin install plugin-name@marketplace-name             # 然后从该市场安装插件
/plugin install plugin-name --marketplace username/repo  # 或一步完成两者(v2.1.275+)

何时创建插件

graph TD
    A["我该创建插件吗?"]
    A -->|需要多个组件| B{"多个命令<br/>或 subagents<br/>或 MCPs?"}
    B -->|是| C["✅ 创建插件"]
    B -->|否| D["使用单独功能"]
    A -->|团队工作流| E{"要和<br/>团队共享吗?"}
    E -->|是| C
    E -->|否| F["保持本地配置"]
    A -->|复杂设置| G{"需要自动<br/>配置吗?"}
    G -->|是| C
    G -->|否| D

插件适用场景

场景 建议 原因
团队入职 ✅ 使用插件 即时安装,包含所有配置
框架初始化 ✅ 使用插件 打包框架专属命令
企业规范 ✅ 使用插件 集中分发,版本控制
快速任务自动化 ❌ 使用命令 太重
单一领域能力 ❌ 使用 Skill 太重,直接用 skill 更合适
专门化分析 ❌ 使用 Subagent 可手动创建,或用 skill
实时数据访问 ❌ 使用 MCP 独立使用,不要打包

测试插件

在发布前,使用 --plugin-dir CLI 参数在本地测试插件(可以重复指定多个插件):

claude --plugin-dir ./my-plugin
claude --plugin-dir ./my-plugin --plugin-dir ./another-plugin

这会用已加载插件启动 Claude Code,让你可以:

  • 验证所有 slash commands 是否可用
  • 测试 subagents 和 agents 是否正常工作
  • 确认 MCP servers 能正确连接
  • 验证 hooks 的执行
  • 检查 LSP server 配置
  • 检查是否有配置错误

热重载

插件支持开发期间的热重载。当你修改插件文件时,Claude Code 可以自动检测变化。你也可以手动触发重载:

/reload-plugins

这会重新读取所有插件清单、commands、agents、skills、hooks 以及 MCP/LSP 配置,而无需重启会话。

插件托管设置

管理员可以使用托管设置在组织范围内控制插件行为:

设置 说明
enabledPlugins 默认启用的插件白名单
enabledPlugins(设为 false) 阻止特定插件:在 managed settings 中设置 "enabledPlugins": { "<plugin>@<marketplace>": false },即可在所有作用域阻止安装,并在市场中隐藏该插件
extraKnownMarketplaces 在默认列表之外添加额外市场源
strictKnownMarketplaces 限制用户允许添加的市场
allowedChannelPlugins 允许向会话推送消息的 channel 插件白名单(每个条目包含 marketplace 和 plugin)

更友好的别名(v2.1.232):additionalMarketplaces 被接受为 extraKnownMarketplaces 的别名,allowedMarketplaces 为 strictKnownMarketplaces 的别名。官方 settings 参考页面已在 Marketplace key aliases 中列出这两个别名。旧版本会忽略别名,因此继续使用规范键名是安全的。

owner 通配符(v2.1.223+):"owner/*" 条目可允许或阻止某个 GitHub owner 名下的所有市场仓库。仅在 strictKnownMarketplaces 和 blockedMarketplaces 中被接受。 在其他出现 github 源的地方 —— 包括 extraKnownMarketplaces 和 /plugin marketplace add —— repo 的值必须指向单个仓库。

组织插件与 pluginDigests:托管设置所声明、启用并列在 prependPlugins 或 appendPlugins 中的远程市场插件,现在算作组织的插件。mods 管理文档将此标注为 v2.1.324 起;changelog 将其列在 v2.1.325。自 v2.1.325 起 pluginDigests 已弃用并被忽略;这由 changelog 新增,文档尚未列出。

这些设置可以通过托管配置文件应用到组织级别,并且优先于用户级设置。

插件安全

插件 subagents 会忽略以下 frontmatter 键(agent 仍会加载,但这些键不起作用):

  • hooks - subagents 不能注册事件处理器
  • mcpServers - subagents 不能配置 MCP servers
  • permissionMode - subagents 不能覆盖权限模型
  • initialPrompt - 插件 agents 不能自动提交第一条提示

agent 文件本身无法添加 hooks 或 MCP servers;请改为以插件级 hooks 和 MCP servers 的形式提供。

发布插件

发布步骤:

  1. 使用所有组件创建插件结构
  2. 编写 .claude-plugin/plugin.json 清单
  3. 创建带文档的 README.md
  4. 使用 claude --plugin-dir ./my-plugin 在本地测试
  5. 提交到插件市场
  6. 经过审查和批准
  7. 发布到市场
  8. 用户即可一条命令安装

示例提交:

# PR 审查插件

## 描述
包含安全、测试和文档检查的完整 PR 审查工作流。

## 包含内容
- 3 个用于不同审查类型的 slash commands
- 3 个专门化 subagents
- GitHub MCP 集成
- 一个检查 git 仓库的 pre-review hook

## 安装
```bash
claude --plugin-dir ./07-plugins/pr-review
```

## 功能
✅ 安全分析
✅ 测试覆盖率检查
✅ 文档校验
✅ 代码质量评估
✅ 性能影响分析

## 使用
```text
/pr-review:review-pr
/pr-review:check-security
/pr-review:check-tests
```

## 要求
- Claude Code 2.1+
- Node.js 和 Docker
- 在 `GITHUB_TOKEN` 中设置 GitHub personal access token

插件 vs 手动配置

手动设置(2+ 小时):

  • 逐个安装 slash commands
  • 单独创建 subagents
  • 分别配置 MCP
  • 手动设置 hooks
  • 记录所有内容
  • 和团队共享(希望他们能配对)

使用插件(2 分钟):

claude --plugin-dir ./07-plugins/pr-review
# ✅ 一切都已安装并配置
# ✅ 可以立即使用
# ✅ 团队可以复现完全相同的设置

最佳实践

应该做的 ✅

  • 使用清晰、描述性的插件名
  • 提供完整 README
  • 正确使用语义化版本(semver)
  • 一起测试所有组件
  • 清楚记录依赖和要求
  • 提供使用示例
  • 包含错误处理
  • 为发现性添加合适标签
  • 保持向后兼容
  • 保持插件聚焦且一致
  • 包含完整测试
  • 记录所有依赖

不要做的 ❌

  • 不要打包无关功能
  • 不要硬编码凭据
  • 不要跳过测试
  • 不要忘记文档
  • 不要创建冗余插件
  • 不要忽略版本管理
  • 不要把组件依赖搞得过于复杂
  • 不要忘记优雅处理错误

安装说明

从市场安装

  1. 浏览可用插件(Discover 标签页列出你的市场中的插件;/plugin list 只显示已安装的插件):

    /plugin
    
  2. 查看插件详情: 在 Discover 标签页中选择插件即可打开详情。(claude plugin details plugin-name 仅在插件已加载时可用:已安装,或通过 --plugin-dir 传入。)

  3. 安装插件:

    /plugin install plugin-name
    

从本地路径安装

# /plugin install 需要 name@marketplace;传入路径会报 "marketplace not found"
claude --plugin-dir ./path/to/plugin-directory

从 GitHub 安装

/plugin marketplace add username/repo                    # 将 GitHub 仓库添加为市场
/plugin install plugin-name@marketplace-name             # 然后从该市场安装插件
/plugin install plugin-name --marketplace username/repo  # 或一步完成两者(v2.1.275+)

列出已安装插件

/plugin list             # 所有已安装插件
/plugin list --enabled   # 仅已启用插件
/plugin list --disabled  # 仅已禁用插件

更新插件

使用 CLI 形式 —— 这是 plugin update 中记录的形式,也是有可用更新时 Claude Code 自身提示你使用的形式:

claude plugin update plugin-name

禁用 / 启用插件

# 临时禁用
/plugin disable plugin-name

# 重新启用
/plugin enable plugin-name

卸载插件

/plugin uninstall plugin-name

相关概念

以下 Claude Code 功能会和插件一起协作:

  • Slash Commands - 插件中打包的单独命令
  • Memory - 插件的持久上下文
  • Skills - 可以包装进插件的领域能力
  • Subagents - 作为插件组件包含的专门化 agent
  • MCP Servers - 打包在插件中的 Model Context Protocol 集成
  • Hooks - 触发插件工作流的事件处理器

完整示例工作流

PR Review 插件完整工作流

1. 用户:/pr-review:review-pr

2. 插件执行:
   ├── pre-review.js hook(UserPromptExpansion)验证 git repo
   ├── GitHub MCP 获取 PR 数据
   ├── security-reviewer subagent 分析安全
   ├── test-checker subagent 验证覆盖率
   └── performance-analyzer subagent 检查性能

3. 汇总并展示结果:
   ✅ 安全:没有发现关键问题
   ⚠️  测试:覆盖率 65%(建议 80%+)
   ✅ 性能:没有明显影响
   📝 提供了 12 条建议

故障排查

插件无法安装

  • 检查 Claude Code 版本兼容性:claude --version
  • 用 JSON 校验器验证 plugin.json 语法
  • 检查网络连接(远程插件)
  • 检查权限:ls -la plugin/

组件没有加载

  • 验证 plugin.json 中的路径与实际目录结构一致
  • 检查文件权限:chmod +x scripts/
  • 检查组件文件语法
  • 查看组件清单:claude plugin details plugin-name

MCP 连接失败

  • 确认环境变量已正确设置
  • 检查 MCP server 的安装和健康状态
  • 使用 /mcp 查看 MCP 服务器状态
  • 查看插件 .mcp.json 中的 MCP 配置

安装后命令不可用

  • 确认插件已成功安装:/plugin list
  • 检查插件是否已启用:/plugin list --enabled
  • 确认是否已生效 —— 参见安装方式中的安装摘要说明:Plugin is now active. 表示无需其他操作,Run /reload-plugins to activate. 表示运行该命令即可(无需重启)
  • 检查是否与现有命令冲突

Hook 执行问题

  • 确认 hook 文件权限正确
  • 检查 hook 语法和事件名
  • 查看 hook 日志中的错误细节
  • 如有可能,手动测试 hooks

更多资源


最后更新: 2026 年 10 月 18 日 Claude Code 版本: 2.1.302 来源: