← 提示词库 Anthropic/claude-code/skills/doctor/SKILL.md 原文 md
🌐 中英双语对照

name: doctor
description: "Health-check the user's Claude Code setup and fix issues: diagnose installation health — what the claude doctor terminal diagnostics cover — from local data (duplicate or leftover installs, PATH, unparseable settings files, broken or colliding agent definitions, skills whose frontmatter fails to parse); find unused skills, MCP servers, and plugins versus their context cost and disable dead weight; deduplicate local CLAUDE.md files against checked-in ones; trim checked-in CLAUDE.md files by cutting content a session could derive from the codebase (directory layouts, tech-stack lists, architecture overviews) while keeping gotchas, rationale, and non-standard conventions; migrate always-loaded CLAUDE.md guidance into lazy skills and nested CLAUDE.md files; flag slow hooks and context-heavy extensions; check the installed version is current; make auto mode the default permission mode; and pre-approve frequently denied read-only commands. Use when the user asks for a doctor run, checkup, audit, tune-up, or cleanup of their Claude Code setup or configuration."
disable-model-invocation: true

Claude Code Doctor / Claude Code 体检

Health-check my Claude Code setup and fix what's wrong: diagnose installation health (what the claude doctor terminal diagnostics cover), find extensions that cost context but never get used, deduplicate my LOCAL memory files against checked-in ones, trim checked-in CLAUDE.md files down to what a session can't derive on its own, migrate the always-loaded guidance that survives to lazy loading, flag slow hooks, verify my installed version is current, make auto mode my default permission mode, and pre-approve the read-only commands I keep getting denied on.

为我的 Claude Code 环境做健康检查并修复问题:诊断安装健康状况(即 claude doctor 终端诊断所覆盖的内容),找出消耗上下文却从未被使用的扩展,将我的 LOCAL 记忆文件与已签入文件去重,把已签入的 CLAUDE.md 文件精简到会话无法自行推导的内容为止,把精简后仍需保留的常驻加载指引迁移为懒加载,标记缓慢的钩子,验证已安装版本是否为最新,把 auto 模式设为我的默认权限模式,并预批准我反复被拒的只读命令。

Ground rules / 基本规则

Data sources (all local — the ONLY permitted network access is check 7's read-only latest-version lookup, and even that is skipped in essential-traffic mode) / 数据来源(全部为本地 —— 唯一允许的网络访问是检查 7 的只读最新版本查询,且在必要流量模式下连它也会被跳过)

Check 0 — setup health (installation, settings, agent and skill definitions) / 检查 0 —— 环境健康状况(安装、设置、代理与技能定义)

Diagnose the installation itself, from local data only. The claude doctor terminal command prints the same read-only install/settings diagnostics; replicate its checks here rather than shelling out to it, because this check must also turn each finding into a concrete fix proposal:

只依据本地数据诊断安装本身。claude doctor 终端命令打印的是同样的只读安装/设置诊断;在这里复刻它的检查而不是直接调用它,因为本检查还必须把每项发现转化为具体的修复提议:

Check 1 — unused skills, MCP servers, and plugins / 检查 1 —— 未使用的技能、MCP 服务器与插件

For each user-installed skill, MCP server, and plugin, collect its lifetime usage total (the counters above are cumulative since install — never windowed) and whether it was used in the scan window (lastUsedAt inside the window, plus transcript hits: <command-name> entries, Skill tool_use entries with the skill in input.skill, and MCP tool calls — transcripts are the ONLY window signal for MCP servers, which have no counter), plus estimated always-in-context cost.

对每个用户安装的技能、MCP 服务器和插件,收集其终身使用总量(上述计数器是自安装以来的累计值 —— 从不按窗口截取)、它在扫描窗口内是否被使用(lastUsedAt 落在窗口内,加上转录命中:<command-name> 条目、input.skill 含该技能的 Skill tool_use 条目、以及 MCP 工具调用 —— 转录是 MCP 服务器唯一的窗口信号,它们没有计数器),以及估算的常驻上下文成本。

Context-cost rules — be deferral-aware:

上下文成本规则 —— 要考虑延迟加载(deferral):

Signal quality — know what a zero means before judging:

信号质量 —— 下判断前先弄清零值意味着什么:

Verdicts: zero invocations in the window → recommend disabling. Rarely used but expensive, or any other keep-vs-remove judgment call → still take a position: verdict "remove" or "keep" with a one-line reason ("2 uses in 300 sessions for 1.1k est. resident tokens — remove; re-enabling is one command" / "keep — used weekly and costs almost nothing"). Never park a borderline case as "up to you" with no verdict; the user can always override at the confirmation gate. "Not touching" is reserved for exactly two cases: bundled/built-in skills and anything enabled by managed policy (never propose disabling those — user-installed extensions only), and items with real observed usage in the window. Everything else unused gets a removal recommendation, with the signal quality stated honestly per item. Note honestly when the window is too thin to judge (few sessions, recent install) — thin data is the one case where withholding a verdict beats guessing; never stretch that to the no-signal component types above, where more sessions will never produce data — ask the user instead.

判定:窗口内零调用 → 建议禁用。很少使用但成本高,或其他任何保留/移除的两难 → 仍要表态:给出"移除"或"保留"的判定并附一行理由("300 个会话中用了 2 次、估算常驻 1.1k token —— 移除;重新启用只需一条命令"/"保留 —— 每周使用且几乎不占成本")。绝不把边缘情形搁置为"由你决定"而不给判定;用户随时可以在确认关口推翻你。"不予触碰"只保留给两种情形:内置/自带技能与任何由受管策略启用的项(绝不提议禁用它们 —— 仅限用户自装扩展),以及窗口内有真实观测使用记录的条目。其余一切未使用项都给出移除建议,并逐项如实说明信号质量。窗口太薄难以判断(会话少、安装时间短)时要如实说明 —— 数据稀薄是"不给判定胜过猜测"的唯一情形;绝不要把它套用到上述无信号组件类型上,那里再多的会话也产生不出数据 —— 应改为询问用户。

Disable mechanics (after confirmation — every name/key written below is harvested, so the never-inline ground rule applies to these edits):

禁用机制(确认之后 —— 下面写出的每个名称/键都是采集来的,因此这些编辑同样适用"绝不内联"基本规则):

Check 2 — LOCAL CLAUDE.md dedup and contradictions / 检查 2 —— LOCAL CLAUDE.md 去重与矛盾

LOCAL files: ~/.claude/CLAUDE.md and CLAUDE.local.md (project root and ancestor dirs). Checked-in files: CLAUDE.md, .claude/CLAUDE.md, .claude/rules/*.md in the project, including nested directories.

LOCAL 文件:~/.claude/CLAUDE.md 与 CLAUDE.local.md(项目根目录及祖先目录)。已签入文件:项目中的 CLAUDE.md、.claude/CLAUDE.md、.claude/rules/*.md,含嵌套目录。

Check 3 — trim derivable content from checked-in CLAUDE.md files / 检查 3 —— 裁剪已签入 CLAUDE.md 中可推导的内容

A line of a checked-in CLAUDE.md that a fresh session could reconstruct with a few tool calls (ls, cat, reading the manifest, --help) is dead weight every session it loads into pays for. Scan each checked-in CLAUDE.md file — the root file and .claude/CLAUDE.md (always loaded), nested-directory CLAUDE.md files (loaded when working under that directory), and .claude/rules/*.md — for content that is derivable from the codebase and propose deleting it outright. Always-loaded files matter most; nested files still get scanned. LOCAL files (~/.claude/CLAUDE.md, CLAUDE.local.md) are check 2's domain; leave them alone here.

已签入 CLAUDE.md 中,一个全新会话用几次工具调用(ls、cat、读清单、--help)就能重建的行,是每次加载它的会话都要支付的死重。扫描每个已签入 CLAUDE.md 文件 —— 根文件与 .claude/CLAUDE.md(始终加载)、嵌套目录的 CLAUDE.md 文件(在该目录下工作时加载)、以及 .claude/rules/*.md —— 找出可从代码库推导的内容并提议直接删除。始终加载的文件最重要;嵌套文件也要扫描。LOCAL 文件(~/.claude/CLAUDE.md、CLAUDE.local.md)归检查 2 管;此处不要碰。

The derivability test, per section: could a session working in this repo reconstruct this by reading the code? If yes, cut it. If no, keep it.

可推导性测试,逐节进行:在这个仓库里工作的会话能否通过阅读代码重建这段内容?能,就删。不能,就留。

Prioritize files at or near the large-CLAUDE.md warning threshold — Claude Code warns when a single loaded memory file exceeds roughly 5% of the model's context window in characters, with a floor of ~40,000 chars (getMaxMemoryCharacterCount in src/utils/claudemd.ts in the Claude Code repo) — and state in the report which files trip it before vs after the proposed cuts. Files under the threshold with substantial derivable content still get a trim proposal; files that are already lean get one line ("already lean — nothing to cut") and no proposal.

优先处理处于或接近超大 CLAUDE.md 警告阈值的文件 —— 当单个被加载的记忆文件字符数超过模型上下文窗口的约 5%(下限约 40,000 字符)时,Claude Code 会发出警告(getMaxMemoryCharacterCount,位于 Claude Code 仓库的 src/utils/claudemd.ts)—— 并在报告中说明哪些文件在提议裁剪的前/后会触及该阈值。阈值以下但含大量可推导内容的文件仍给出裁剪提议;本已精瘦的文件给一行("already lean — nothing to cut",已经很精简 —— 无可删项)且不做提议。

Propose per file: the categories being cut with approximate line counts ("directory layout — 31 lines", "tech stack — 8 lines"), the est. resident tokens saved, and what remains. Quote each removed block verbatim in the proposal so the user can judge and so the edit is reversible from the report. This check runs BEFORE check 4's migration so that migration operates on the kept content only — don't propose migrating anything this check proposes to delete.

逐文件提议:被删类别及近似行数("目录布局 —— 31 行"、"技术栈 —— 8 行")、节省的估算常驻 token,以及保留的内容。在提议中逐字引用每个将被删除的块,让用户可以判断、也让编辑可从报告还原。本检查在检查 4 的迁移之前运行,使迁移只作用于保留内容 —— 本检查提议删除的内容绝不要提议迁移。

Check 4 — migrate always-loaded CLAUDE.md content to lazy loading / 检查 4 —— 将常驻加载的 CLAUDE.md 内容迁移为懒加载

Of the checked-in CLAUDE.md content that survives check 3's cuts, every line of a root file is still in context in every session. Scan the remaining content for guidance that doesn't need to be always-loaded:

在挺过检查 3 裁剪的已签入 CLAUDE.md 内容中,根文件的每一行仍会在每个会话中进入上下文。扫描剩余内容,找出无需常驻加载的指引:

Propose the full migration set (source lines → destination file) and apply only after confirmation. Estimate the resident-token savings.

提出完整的迁移集合(源行 → 目标文件),仅在确认后执行。估算可节省的常驻 token。

Check 5 — slow hooks / 检查 5 —— 缓慢的钩子

Aggregate durationMs per hookName/hookEvent from the transcript attachment entries above (typical and worst-case). Treat hook_cancelled entries with timedOut: true as slow-hook evidence — the hook ran until its timeout fired, so durationMs (≈ timeoutMs) is a duration floor, and a repeatedly-timing-out hook is the worst blocking-hook case even though it never logs a success. Key on timedOut/timeoutMs to separate these from user-Esc cancellations, which lack both fields and say nothing about hook speed. Warn on hooks that run often and slowly — as a rule of thumb: >2s typical for per-tool-call/per-prompt events (PreToolUse, PostToolUse, UserPromptSubmit — these block the loop every time they fire), >10s for SessionStart or Stop. For configured hooks with no recorded runs in the window, inspect the command strings in settings and flag obviously heavy patterns (network calls, package-manager invocations, cold interpreter startups), clearly labeled "no timing data — config inspection only". Note: successful runs with empty output are never persisted to transcripts, so config inspection is the EXPECTED path for silent hooks — zero recorded runs does not mean the hook rarely fires. Only execute a hook command yourself to measure it if it is plainly read-only AND the user explicitly agrees; run it with a timeout. Fixes to suggest: make the hook async, cache its output, narrow its matcher, or remove it — but slow-hook findings are warnings; don't edit hook config unless asked.

根据上文的转录 attachment 条目按 hookName/hookEvent 聚合 durationMs(典型值与最差值)。把带 timedOut: true 的 hook_cancelled 条目视为慢钩子证据 —— 钩子一直运行到超时触发,因此 durationMs(≈ timeoutMs)是时长的下限,反复超时的钩子是最糟的阻塞型钩子,尽管它从未记录过一次成功。以 timedOut/timeoutMs 为键把它们与用户按 Esc 的取消区分开,后者两个栏目都没有,也说明不了钩子速度。对运行频繁且缓慢的钩子发出警告 —— 经验法则:每工具调用/每提示事件(PreToolUse、PostToolUse、UserPromptSubmit —— 每次触发都会阻塞主循环)典型耗时 >2s,SessionStart 或 Stop 则 >10s。对窗口内无运行记录的已配置钩子,检查设置中的 command 字符串并标记明显沉重的模式(网络调用、包管理器调用、解释器冷启动),并明确标注"无计时数据 —— 仅基于配置检查"。注意:输出为空的成功运行从不持久化到转录,因此配置检查是静默钩子的预期路径 —— 零运行记录不等于钩子很少触发。仅当钩子命令明显只读且用户明确同意时,才亲自执行它来测量;执行时加超时。可建议的修复:把钩子改为异步、缓存其输出、收窄其匹配器,或移除它 —— 但慢钩子发现属于警告;除非被要求,否则不编辑钩子配置。

Check 6 — context-heavy extensions / 检查 6 —— 上下文开销大的扩展

Summarize estimated always-resident context by component: each CLAUDE.md file, the skill/command listing total (vs its ~1% budget), non-deferred MCP tool schemas, and plugins' resident contributions. Deferral rules from check 1 apply — deferred MCP tools are ~0. Call out the largest few. Recommend /context for the exact live measurement; your figures are disk-based estimates.

按组件汇总估算的常驻上下文:每个 CLAUDE.md 文件、技能/命令列表总量(对比其约 1% 预算)、未延迟的 MCP 工具模式,以及插件的常驻贡献。检查 1 的延迟规则同样适用 —— 被延迟的 MCP 工具约为 0。点名最大的几项。精确的实时测量请推荐 /context;你的数字只是基于磁盘的估算。

Check 7 — Claude Code version / 检查 7 —— Claude Code 版本

Check whether the installed Claude Code is the latest for its release channel. Everything here is read-only.

检查已安装的 Claude Code 是否是其发布通道的最新版本。本检查全部只读。

Check 8 — auto mode as the default permission mode / 检查 8 —— 将 auto 模式设为默认权限模式

Auto mode ("auto") delegates per-action permission decisions to a safety classifier instead of prompting the user for each one. Check whether it is the user's default permission mode; if not, propose making it so.

auto 模式("auto")把逐操作的权限决定交给安全分类器,而不是每个操作都询问用户。检查它是否已是用户的默认权限模式;若不是,提议设为默认。

Check 9 — pre-approve frequently denied read-only commands / 检查 9 —— 预批准频繁被拒的只读命令

Find tool calls that keep getting denied even though they only read state, and propose permission allow rules for the top ones so they stop costing a prompt (or a classifier block) every time.

找出反复被拒、但实际只读取状态的工具调用,并为其中最高频者提议权限 allow 规则,使其不再每次都消耗一次询问(或一次分类器拦截)。

Report format / 报告格式

  1. Plain-language summary first, and keep it SHORT — 2-3 sentences: what you found, what it costs, that cleanup is reversible (see the beginner-friendly ground rule). Anything that doesn't change the user's decision belongs in the detail table, not the lead. Then the detail table: | Component | Type | Scope | Uses (total since install) | Used in window? | Est. resident tokens | Verdict |. One row per skill/MCP server/plugin/CLAUDE.md file; MCP servers have no counter — put "n/a (no counter)" in the total column and answer the window column from transcript hits; use "deferred" in the tokens column for deferred MCP servers, and "no signal (passive)" across both usage columns for components with no usage counter. State the scan window under the table.
    1. 先给通俗摘要,并保持简短 —— 2-3 句:发现了什么、代价是什么、清理可逆(见"面向新手"基本规则)。任何不改变用户决定的信息都放进详细表格,不要放在开头。然后是详细表格:| Component | Type | Scope | Uses (total since install) | Used in window? | Est. resident tokens | Verdict |。每个技能/MCP 服务器/插件/CLAUDE.md 文件一行;MCP 服务器没有计数器 —— 总量列填 "n/a (no counter)",窗口列依据转录命中回答;被延迟的 MCP 服务器在 token 列填 "deferred",没有使用计数器的组件在两个使用列都填 "no signal (passive)"。在表格下方注明扫描窗口。
  2. Proposed actions grouped by check (0, 1, 2, 3, 4, 7, 8, 9), each item with exact file + exact edit (or exact command, for checks 0 and 7).
    1. 按检查分组的提议动作(0、1、2、3、4、7、8、9),每项给出确切文件 + 确切编辑(检查 0 和 7 则为确切命令)。
  3. Warnings (checks 5 and 6) — no actions, just findings.
    1. 警告(检查 5 和 6)—— 不带动作,仅列发现。
  4. Confirmation gates: at most TWO AskUserQuestions (mechanics in the propose-then-confirm ground rule) — the consolidated cleanup question for checks 0-4 and 7, then the separate permission question for checks 8 and 9. Each RECOMMENDS rather than neutrally offers, in 2-3 sentences: plain-language counts, the concrete benefit ("saves about 1.5k tokens of context every session"), and honest reversibility — "You can ask me to undo it later" wherever that's true (the disable mechanics above all are; for deletions, the report quotes what was removed so it can be restored). Don't restate the report's per-item detail — except in the permission question, which must name every change it grants. Models to follow:
    1. 确认关口:至多两个 AskUserQuestion(机制见"先提议再确认"基本规则)—— 先是涵盖检查 0-4 和 7 的合并清理问题,然后是检查 8 和 9 的单独权限问题。每个问题都给出推荐而非中立罗列,用 2-3 句话:通俗的计数、具体收益("每次会话节省约 1.5k token 上下文"),以及如实的可逆性说明 —— 凡属实在,都说"你之后可以让我撤销"(上述禁用机制都可逆;删除操作则由报告引用被删内容以便还原)。不要复述报告的逐项细节 —— 权限问题除外,它必须点明其授予的每项改动。示范模板:

Everything above is unused and safe to remove: 4 skills, 2 plugins, and 1 MCP server (a connection to an external tool). Cleaning up saves about 1.5k tokens of context every session, and you can ask me to undo it later. Clean up everything?
以上内容均未使用且可安全移除:4 个技能、2 个插件和 1 个 MCP 服务器(与外部工具的连接)。清理后每次会话可节省约 1.5k token 上下文,之后你可以让我撤销。要清理全部吗?

  1. Clean up everything (recommended)
  2. 清理全部(推荐)
  3. Let me pick
  4. 让我挑选
  5. No, keep everything
  6. 不,全部保留

If the user picks "Let me pick", ask ONE follow-up multiSelect question — an option per group, its label a short name plus the benefit ("37 unused skills — saves ~2.2k est. tokens/session") — then apply only the selected groups.

如果用户选择"Let me pick",追加一个 multiSelect 问题 —— 每组一个选项,标签为简短名称加收益("37 个未使用技能 —— 每会话节省约 2.2k 估算 token")—— 然后只执行被选中的组。

Then, only if check 8 or 9 proposed anything, the permission question — explicit because these widen what runs without asking:

然后,仅当检查 8 或 9 有提议时,提权限问题 —— 必须显式,因为它们会扩大无需询问即可运行的范围:

Separately from the cleanup: I recommend two permission changes. (1) Make auto mode your default — a safety classifier approves routine actions instead of prompting you each time. (2) Pre-approve 2 read-only commands you denied 14 times: Bash(git log --oneline -20), Bash(gh pr view). Apply both?
在清理之外:我建议两项权限改动。 (1) 把 auto 模式设为默认 —— 由安全分类器批准常规操作,而不是每次都询问你。 (2) 预批准 2 条你被拒了 14 次的只读命令:Bash(git log --oneline -20)、Bash(gh pr view)。两项都应用吗?

  1. Apply both (recommended)
  2. 两项都应用(推荐)
  3. Let me pick
  4. 让我挑选
  5. No, keep prompting me
  6. 不,继续询问我

"Let me pick" here follows the same follow-up multiSelect pattern, one option per proposed permission change.

这里的"Let me pick"遵循同样的后续 multiSelect 模式,每个提议的权限改动一个选项。

  1. After applying, list exactly what changed, file by file, and how to undo it.
    1. 应用完成后,逐文件列出确切改动,以及如何撤销。

If a check has no findings, say so in one line and move on. Keep the report tight — no padding, no restating these instructions.

某项检查没有发现时,用一行说明然后继续。保持报告紧凑 —— 不注水,不复述本指令。