claude-code-doctor
A health checkup for Claude Code. The core idea: diagnosis (read-only) and treatment
(after approval) are strictly separated.
Write the report, dashboard and all conversation output in the user's language.
Iron rules (override everything else)
- Be honest about what "read-only" is: a prompt-level contract, not an OS
sandbox. Tell the user so if asked, and recommend pairing with Claude Code
permission deny rules for hard guarantees.
- The diagnosis phase is strictly read-only. Never use Write / Edit / mkdir / mv /
rm / any git-mutating command. Allowed: ls / find / du / wc / head / grep / cat /
stat / plutil -p / git status / git log / git ls-files, plus Linux read-only
probes such as
crontab -l, systemctl --user list-timers --all --no-pager,
systemctl --user list-unit-files --type=timer --no-pager, and ss -ltnp;
plus the Read / Grep / Glob tools.
On Linux, never run rm, mv, mkdir, touch, chmod, chown, sed -i,
package-manager commands, systemctl start / stop / enable / disable,
or crontab -e.
On Windows, use read-only PowerShell probes such as Get-ChildItem,
Get-Content -TotalCount, Get-ScheduledTask, schtasks /Query, and
git status; never run Set-Item, Remove-Item, New-Item, Move-Item,
Copy-Item, registry writes, or schtasks /Change / /Delete.
- The user decides. Findings are "evidence + proposal". Fixes wait for an explicit GO.
"Probably fine" or "might be OK" is not approval.
- Confirm no-go paths first. User-designated excluded paths (personal, patient,
secret areas) must not be read at all. Every find command carries the exclusion.
- Never quote secrets. If something looks like an API key or token, report the
path and existence only, never the value.
Step 0: Scope confirmation
Before scanning, confirm with the user (use AskUserQuestion if available):
- Scan root: entire
~/, or only ~/.claude + development directories?
- No-go paths: directories that must not be touched (suggest defaults: personal
documents, keys, patient data)
- Report destination: get write permission for exactly one output location
(everything else stays read-only)
Step 1: Recon (main loop, 1-2 minutes)
Grasp the size of the estate before fanning out:
ls -la ~/.claude/ && ls ~/.claude/skills | wc -l && ls ~/.claude/agents | wc -l
wc -c ~/.claude/settings.json ~/.claude/CLAUDE.md 2>/dev/null
ls ~/Library/LaunchAgents/ 2>/dev/null | head -30 # macOS only
crontab -l 2>/dev/null | head -10
Windows coverage is beta. If the scan is on Windows, generate a reviewable
PowerShell probe plan first:
python3 scripts/build_windows_probe_plan.py windows-probe-plan.md
Then ask the user to approve the no-go paths and output location before running
any PowerShell command from that plan.
Linux coverage is beta. If the scan is on Linux or WSL, generate a reviewable
shell probe plan first:
python3 scripts/build_linux_probe_plan.py linux-probe-plan.md
Then ask the user to approve the no-go paths and output location before running
any shell command from that plan.
Embed the counts and sizes you find into each domain prompt (agents wander less
when given concrete targets).
Step 2: Parallel fan-out (10 domains)
Use the domain definitions in references/domains.md and launch read-only subagents
in parallel. Use the Workflow tool's parallel() if available; otherwise launch
multiple Agent tool calls in a single message.
- Prepend the common prohibition block (top of domains.md) to every agent
- Force structured output (the findings schema in
references/report-format.md)
- Model routing: pin scanners to cheaper models (e.g. haiku/sonnet) explicitly.
Synthesis and judgment stay on the main loop's stronger model. Do not let every
subagent inherit the top-tier default — that cost leak is itself one of the most
common findings this audit produces.
Step 3: Synthesis (main loop)
With all agent results in hand:
- Verify the load-bearing claims: re-check 2-3 pivotal findings yourself
(ones confirmable with a single command)
- Impact x Effort matrix: A = high impact x low effort (do now) / B = high x mid /
C = high x high / D = low x low (while passing by) / E = not worth it (say so explicitly)
- Top 10 findings by effect on daily efficiency, safety and cost
- Extract decisions: 3-5 choices only the user can make, presented as OPTION A/B
- Phased plan: Phase 0 (backup, non-destructive) → 1 (stop the bleeding) →
2 (context diet) → 3 (grooming) → 4 (heavy lifting). For destructive steps, always
spell out the order: backup → quarantine → verify → delete later
Step 4: Outputs
- Markdown report written to the single approved location
(state map → matrix → ideal layout → phased plan)
- Prescriptions (action plan): for every matrix-A/B item, write an
actions[]
entry whose prompt is a ready-to-paste Claude Code instruction that executes
that one fix safely (backup → quarantine → verify baked in, ends with a report
step). A diagnosis without an executable action plan is not a deliverable.
- HTML dashboard: assemble the findings JSON and run
python3 scripts/build_dashboard.py findings.json out.html
(set meta.lang to en or ja), then open it in the browser
- Share cards (only on request): assemble a sanitized summary JSON and run
python3 scripts/build_share_cards.py cards.json outdir/ for four 16:9 PNGs
Always verify rendering with a headless browser screenshot before calling any
generated HTML finished.
Sanitization rules for share cards (mandatory)
Public-facing cards may contain aggregates and generalized lessons only:
- Allowed: finding counts / always-on token totals / permission-list sizes /
MCP tool counts / lessons learned
- Never: real paths (generic ones like
~/.claude are fine) / personal or patient
folder names / actual spend figures / exact locations of security gaps /
whereabouts of account IDs or keys
Step 5: Treatment (after approval only)
After an explicit GO ("do it", "run phase 1"), execute matrix-A items one at a time:
- Back up before touching anything (settings.json / crontab / target files)
- Execute → verify on the spot (counts, JSON validity, launchctl list, etc.) →
report in one line
- Never delete. Move to a quarantine folder with a MANIFEST.tsv
(original path, reason, date) and delete weeks later
If a permission guard blocks you mid-treatment, stop and report to the user.
Do not route around it — the guard firing is evidence the setup is healthy.
Fallback without subagents
Walk the 10 domains sequentially in the main loop (finalize each domain's findings
before moving on). Slower, but converges to the same schema and outputs.
1---2name: claude-code-doctor3description: Use when the user asks to audit, diagnose, or health-check their Claude Code setup, wonders where their context/tokens go, or invokes /doctor. Runs a read-only audit across 10 domains (directory structure, dev repos, CLAUDE.md hierarchy, settings & permissions, skills, commands, subagents, MCP & plugins, automations & git, usage & disk) with parallel subagents, triages findings on an impact-x-effort matrix, and renders an HTML dashboard with A-E grades, red flags and a paste-ready action plan. Zero changes until the user approves each fix. Triggers: '/doctor', 'audit my claude code setup', 'setup audit', 'health check my setup', 'claude code doctor', '環境監査', 'セットアップ監査', 'Claude Code健康診断', '設定を診断して'4---56# claude-code-doctor78A health checkup for Claude Code. The core idea: **diagnosis (read-only) and treatment9(after approval) are strictly separated.**1011Write the report, dashboard and all conversation output in the user's language.1213## Iron rules (override everything else)14150. **Be honest about what "read-only" is**: a prompt-level contract, not an OS16 sandbox. Tell the user so if asked, and recommend pairing with Claude Code17 permission deny rules for hard guarantees.181. **The diagnosis phase is strictly read-only.** Never use Write / Edit / mkdir / mv /19 rm / any git-mutating command. Allowed: ls / find / du / wc / head / grep / cat /20 stat / plutil -p / git status / git log / git ls-files, plus Linux read-only21 probes such as `crontab -l`, `systemctl --user list-timers --all --no-pager`,22 `systemctl --user list-unit-files --type=timer --no-pager`, and `ss -ltnp`;23 plus the Read / Grep / Glob tools.24 On Linux, never run `rm`, `mv`, `mkdir`, `touch`, `chmod`, `chown`, `sed -i`,25 package-manager commands, `systemctl start` / `stop` / `enable` / `disable`,26 or `crontab -e`.27 On Windows, use read-only PowerShell probes such as `Get-ChildItem`,28 `Get-Content -TotalCount`, `Get-ScheduledTask`, `schtasks /Query`, and29 `git status`; never run `Set-Item`, `Remove-Item`, `New-Item`, `Move-Item`,30 `Copy-Item`, registry writes, or `schtasks /Change` / `/Delete`.312. **The user decides.** Findings are "evidence + proposal". Fixes wait for an explicit GO.32 "Probably fine" or "might be OK" is not approval.333. **Confirm no-go paths first.** User-designated excluded paths (personal, patient,34 secret areas) must not be read at all. Every find command carries the exclusion.354. **Never quote secrets.** If something looks like an API key or token, report the36 path and existence only, never the value.3738## Step 0: Scope confirmation3940Before scanning, confirm with the user (use AskUserQuestion if available):4142- Scan root: entire `~/`, or only `~/.claude` + development directories?43- No-go paths: directories that must not be touched (suggest defaults: personal44 documents, keys, patient data)45- Report destination: get write permission for exactly one output location46 (everything else stays read-only)4748## Step 1: Recon (main loop, 1-2 minutes)4950Grasp the size of the estate before fanning out:5152```bash53ls -la ~/.claude/ && ls ~/.claude/skills | wc -l && ls ~/.claude/agents | wc -l54wc -c ~/.claude/settings.json ~/.claude/CLAUDE.md 2>/dev/null55ls ~/Library/LaunchAgents/ 2>/dev/null | head -30 # macOS only56crontab -l 2>/dev/null | head -1057```5859Windows coverage is beta. If the scan is on Windows, generate a reviewable60PowerShell probe plan first:6162```bash63python3 scripts/build_windows_probe_plan.py windows-probe-plan.md64```6566Then ask the user to approve the no-go paths and output location before running67any PowerShell command from that plan.6869Linux coverage is beta. If the scan is on Linux or WSL, generate a reviewable70shell probe plan first:7172```bash73python3 scripts/build_linux_probe_plan.py linux-probe-plan.md74```7576Then ask the user to approve the no-go paths and output location before running77any shell command from that plan.7879Embed the counts and sizes you find into each domain prompt (agents wander less80when given concrete targets).8182## Step 2: Parallel fan-out (10 domains)8384Use the domain definitions in `references/domains.md` and launch read-only subagents85in parallel. Use the Workflow tool's `parallel()` if available; otherwise launch86multiple Agent tool calls in a single message.8788- Prepend the **common prohibition block** (top of domains.md) to every agent89- Force structured output (the findings schema in `references/report-format.md`)90- Model routing: pin scanners to cheaper models (e.g. haiku/sonnet) explicitly.91 Synthesis and judgment stay on the main loop's stronger model. Do not let every92 subagent inherit the top-tier default — that cost leak is itself one of the most93 common findings this audit produces.9495## Step 3: Synthesis (main loop)9697With all agent results in hand:98991. **Verify the load-bearing claims**: re-check 2-3 pivotal findings yourself100 (ones confirmable with a single command)1012. **Impact x Effort matrix**: A = high impact x low effort (do now) / B = high x mid /102 C = high x high / D = low x low (while passing by) / E = not worth it (say so explicitly)1033. **Top 10** findings by effect on daily efficiency, safety and cost1044. **Extract decisions**: 3-5 choices only the user can make, presented as OPTION A/B1055. **Phased plan**: Phase 0 (backup, non-destructive) → 1 (stop the bleeding) →106 2 (context diet) → 3 (grooming) → 4 (heavy lifting). For destructive steps, always107 spell out the order: backup → quarantine → verify → delete later108109## Step 4: Outputs1101111. **Markdown report** written to the single approved location112 (state map → matrix → ideal layout → phased plan)1132. **Prescriptions (action plan)**: for every matrix-A/B item, write an `actions[]`114 entry whose `prompt` is a ready-to-paste Claude Code instruction that executes115 that one fix safely (backup → quarantine → verify baked in, ends with a report116 step). A diagnosis without an executable action plan is not a deliverable.1173. **HTML dashboard**: assemble the findings JSON and run118 `python3 scripts/build_dashboard.py findings.json out.html`119 (set `meta.lang` to `en` or `ja`), then open it in the browser1204. **Share cards (only on request)**: assemble a sanitized summary JSON and run121 `python3 scripts/build_share_cards.py cards.json outdir/` for four 16:9 PNGs122123Always **verify rendering with a headless browser screenshot** before calling any124generated HTML finished.125126### Sanitization rules for share cards (mandatory)127128Public-facing cards may contain aggregates and generalized lessons only:129130- Allowed: finding counts / always-on token totals / permission-list sizes /131 MCP tool counts / lessons learned132- Never: real paths (generic ones like `~/.claude` are fine) / personal or patient133 folder names / actual spend figures / exact locations of security gaps /134 whereabouts of account IDs or keys135136## Step 5: Treatment (after approval only)137138After an explicit GO ("do it", "run phase 1"), execute matrix-A items **one at a time**:1391401. Back up before touching anything (settings.json / crontab / target files)1412. Execute → verify on the spot (counts, JSON validity, launchctl list, etc.) →142 report in one line1433. Never delete. Move to a quarantine folder with a MANIFEST.tsv144 (original path, reason, date) and delete weeks later145146If a permission guard blocks you mid-treatment, stop and report to the user.147Do not route around it — the guard firing is evidence the setup is healthy.148149## Fallback without subagents150151Walk the 10 domains sequentially in the main loop (finalize each domain's findings152before moving on). Slower, but converges to the same schema and outputs.