# doctor - the check registry

<!-- toc -->
- [What the exit code means](#what-the-exit-code-means)
- [What BLOCK means, exactly](#what-block-means-exactly)
- [Who calls it, and what they do with the code](#who-calls-it-and-what-they-do-with-the-code)
- [The four severities](#the-four-severities)
- [The line shape](#the-line-shape)
- [The JSON report](#the-json-report)
- [It recommends, it never fixes](#it-recommends-it-never-fixes)
- [Checks](#checks)
- [The server profile (`--profile=server`)](#the-server-profile---profileserver)
<!-- /toc -->

Every check `/multi-agent:doctor` can report has a `### <id>` heading here, and
`doctor.mjs --list-checks` prints exactly the same set. The equality is checked
in both directions by `smoke-doctor.sh`: a check that ships without an entry
cannot be released, and an entry whose check was deleted cannot linger as orphan
prose. That is the mechanism that keeps this file from rotting into a list of
things the tool used to do.

## What the exit code means

| Code | Meaning |
| ---- | ---------------------------------------------------------------------------------- |
| 0 | healthy - nothing above INFO |
| 1 | degraded - at least one WARN, no BLOCK |
| 2 | blocked - at least one BLOCK |
| 3 | usage error |
| 4 | indeterminate - the installed layout could not be resolved, so nothing was checked |

4 exists so that "I could not look" never borrows the exit code of "I looked and
it is fine". A consumer that treats 0 as healthy would otherwise read a broken
resolver as a clean bill.

## What BLOCK means, exactly

**A state in which a run will fail or leak. Not a state in which it will merely
be worse.** Without a closed definition "blocked" grows until nobody respects
exit 2, so only six checks can produce it: `host-platform`, `install-present`,
`script-surface`, `state-writable`, `prefs-valid` and `embedded-credentials`.
Every other check tops out at WARN however bad it looks.

## Who calls it, and what they do with the code

| Caller | When | On exit 2 |
| --------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `/multi-agent:setup` | before the first question, and again at the end | the closing run is the evidence for or against "setup complete" |
| `/multi-agent:update` | after the install | report that the update left a state a run will fail from, rather than "updated" |
| `/multi-agent:sync` | step 0 | **stop.** Syncing a blocked install copies one fault onto five surfaces, and the copies are what people then debug |

`/multi-agent:sync` stops on exit 4 as well: the layout did not resolve, so
nothing was checked, and syncing from an unknown state is worse than not syncing
at all. Exit 1 never stops anything - a degraded install still syncs correctly,
and a gate that blocked on every warning would be routed around within a week.

## The four severities

| Severity | Meaning |
| -------- | ---------------------------------------------------------------------------------------- |
| BLOCK | a run will fail or leak |
| WARN | a run will work and be worse: a degraded capability, a stale copy, a rejected credential |
| INFO | a capability the user chose not to enable; nothing to fix |
| SKIP | not checked, and why |

`SKIP` is printed in the same list, in the same position, and the summary always
carries its count (`... 2 not checked, 15 checks`). Absence is a finding: a run
without `--probe` exits 0 **and** prints `SKIP credential-liveness`, so "healthy"
and "not looked at" are never the same output.

The INFO / WARN boundary is already decided in `lib/credential-inventory.sh` and
this tool only renders it: an unmapped key is INFO because it is a capability the
user chose not to enable, while `auth-rejected`, `malformed` and
`tier-1-no-grant` are WARN because the configuration made a claim the service
refused. **A missing optional capability is information; a mapped credential the
service rejected is a warning. The difference is whether the configuration
asserted anything.**

## The line shape

```
<SEV> <id>  -  <what is wrong>  -  <single imperative step>
```

The third field is one step, and its first word comes from a closed list:
`run`, `set`, `map`, `revoke`, `install`, `remove`, `free`, `export`, `merge`,
`record`, `re-run`. `consider`, `may want` and `should probably` are refused by
the gate. One problem, one step: a reader with five suggestions does nothing.

## The JSON report

`--json` prints one document whose shape `schemas/doctor-report.schema.json`
fixes and `test/doctor-json-contract.test.mjs` holds against real output and a
golden file:

```json
{
  "schemaVersion": 1,
  "exit": 1,
  "selection": null,
  "checks": [
    { "id": "identity", "severity": "WARN", "problem": "...", "step": "set ...", "detail": null }
  ]
}
```

- `schemaVersion` changes only when an existing field changes meaning or
  shape. A new check id, or a new optional field, does not change it, so a
  reader keys on `id` and ignores ids it does not know.
- `exit` equals the process exit code (0, 1, 2 or 4).
- `selection` is the `--only` list in the order given, or null for a full run,
  so a filtered report is never mistaken for a complete one.
- `checks` holds one entry per check that ran, in registry order. `problem` and
  `step` are null for OK; `step` is null for SKIP.

`--only <id,...>` (or `--only=<id,...>`) runs and reports only the named
checks; the layout checks still run first, since nothing resolves without
them, and a run whose layout does not resolve is still exit 4. An unknown id
is exit 3 with the nearest known id named.

## It recommends, it never fixes

Nothing here rewrites a remote URL, edits `settings.json` or touches a token.
A remote whose URL carries a token may be the only credential that repo has, the
remote may be a mirror a script depends on verbatim, and doctor can run inside a
checkout the user does not own. Silent repair breaks all three.

For an embedded credential the honest single step is **not** "hide it". A token
that reached `.git/config` is already burned: it is in the shell history and
readable by anything that can read the working tree. The step is to revoke it at
its host; everything after that is behind `--explain`.

---

## Checks

### host-platform

The host is macOS. BLOCK otherwise: every credential read shells `security`,
every iOS build shells `xcodebuild`, every piece of visual evidence shells
`simctl`, so a run on another platform does not degrade, it fails partway
through with a worktree and a branch already created (ADR-0012).

It runs **first**, before `install-present`, so an unsupported host reads one
line naming the cause instead of a cascade of consequences. The step names the
`MULTI_AGENT_ALLOW_NON_DARWIN=1` escape, which the entry points honour and
nothing tests.

### install-present

The installed tree this doctor is part of exists and carries the subtrees a run
reads on that host, as `schemas/hosts.json` lists them: `multi-agent-refs/`,
`scripts/`, `lib/` and `schemas/` on all three, plus `commands/` on Claude Code
and `skills/` on Copilot CLI and Codex CLI. The tree is the one the script was
installed into (`~/.claude`, `~/.copilot` or `~/.codex`), so a Copilot-only or
Codex-only machine is checked against its own install; run from a checkout, the
checks answer for the first host in the registry. BLOCK when any subtree is
missing - a run cannot start without them.

### install-version

The installed `.pipeline-version` matches the package version resolved from the
checkout or the published package. WARN on a mismatch: the run works, it just
is not the version the user thinks they have.

### update-policy

Whether a run updates itself before it starts, read the way the run reads it:
`updateCheck.enabled`, `.ttlHours` and `.autoUpdate`. The schema defaults all
three, so a preferences file that omits them behaves exactly like one that sets
them - which is why they are worth reporting. INFO when a value comes from the
schema rather than from the file, so the policy is legible in the place somebody
would change it. Reported, never written: a preferences file is the user's.

### script-surface

Every script a shipped command names by path exists in the installed tree. BLOCK:
the failure lands mid-run, at the call, with the phase already half done.

### skill-siblings

Every command has its copies in the host trees this machine installs. WARN, never
BLOCK: an unsynced host is a fact about the machine, and `skill-siblings.mjs`
itself reports the installed layout as "authored side not checked" rather than
claiming a repo verdict it cannot reach.

### state-writable

`$HOME/.claude/logs/multi-agent` exists or can be created, and a file can be
written there. BLOCK: a run that cannot record its state cannot be resumed,
reported or priced, and it discovers this at Phase 0 after the pickers.

### prefs-valid

`multi-agent-preferences.json` parses and satisfies `schemas/prefs.schema.json`.
BLOCK: Phase 0 reads it before anything else, and a malformed file fails the run
after the user has already answered the pickers.

### identity

A git identity resolves for the account the run would commit as. WARN: the run
reaches Phase 4 and stops there.

### hook-reachability

What Claude Code will actually run, read the way the autopilot runner reads the
agent-guard registration (`lib/hook-registration.mjs`): every template hook has
an entry of the same event whose matcher covers the template's tool names, runs
the same command, and finds its script under `~/.claude/scripts`; no
`disableAllHooks`; and no preference is set to act through a hook that is not
registered (`editSyntaxGate.enabled`, `bulkRead.mode`, `attendedCommitGate.mode`,
`readOnlyRepos`, `guardRules`). WARN, with each gap in `--explain`. SKIP when the template is
not installed.

### guard-rules

`prefs.global.guardRules`, read by `_user_guard_rules.py --report`, the same
code and file lookup agent-guard uses, so the two cannot disagree on which rule
is valid. WARN when the preferences file does not parse or `guardRules` is not
a list (no rule applies; attended each call a rule could govern carries a
note, and unattended it is refused when the file names `guardRules`), when a
rule is invalid (the guard ignores it, and an invalid `block` rule refuses its
tool unattended; a repeated id names both positions), or when a host tool a
rule governs has no `agent-guard.sh` registration (a `Read` rule under the
default hooks, or the `NotebookEdit` half of an `Edit` rule). INFO when the
only finding is a valid rule with a slow shape: it runs under the matching
budget, and the check names it so its pattern can be tightened. Each rule is
named by id with its problem or shape in `--explain`; a pattern is never
printed. OK with no rules. SKIP when python3 or the script is missing.

### hook-coverage

The blocking `PreToolUse` gates from `templates/claude-hooks.json` are present in
`settings.json`, and none of them is registered twice on the same matcher
(Claude Code runs a duplicate on every matching call). WARN. SKIP when the template is not installed - which was the
permanent state until the installer began copying `templates/`, and is exactly
the case this severity exists to make visible.

### credential-mapping

Which logical keys are mapped, and whether each mapped value is well formed.
Unmapped is INFO. Malformed is WARN.

### credential-liveness

One cheap authenticated request per mapped credential. WARN on `auth-rejected`,
`tier-1-no-grant` or `unreachable` - but with **different steps**, because a
refused credential and a host that never answered need different actions.
`credential-inventory.sh` already draws that line ("unreachable - no response at
all - on a corporate host, almost always the VPN"), and telling someone to
re-onboard a token that was never the problem is the exact failure the keychain
rules warn about one layer up. **SKIP unless `--probe` is passed**, and the
skip is printed, because a network check is the user's decision to spend.

### store-reference

Whether the toolkit's store reference file (`~/.config/multi-agent-mcp/store.json`,
or `MCP_TOOLKIT_STORE_CONFIG`) names the Keychain items that `keychainMapping`
holds for App Store Connect (`appstore_connect_key_id`, `appstore_connect_issuer_id`,
`appstore_connect_private_key`) and Google Play (`google_play`). The `store_*`
tools and `ios_testflight_validate` read the keys only through that file, so a
key that is in the Keychain but not in the file is invisible to them.

Asked through `write-store-config.mjs --check`, which checks each item's presence
with `credential-store.sh probe` and never reads a value. OK when none of the
four keys is mapped: nothing was claimed. WARN when the file is missing or stale,
with the single step `run node "$HOME/.claude/scripts/write-store-config.mjs"`.
INFO when a store is only partly onboarded (for example the key id and issuer id
mapped without the `.p8`), with setup as the step. SKIP when the writer is not
installed or the credential store does not answer.

### embedded-credentials

A token in a git remote URL or a tracked config file. BLOCK: this one leaks
rather than fails.

The report carries the repo path, the config key, the **host**, a shape label and
a length bucket. Never the value, and not the prefix either: `ghp_` plus a length
is already a fingerprint, and this line is printed to a terminal that is often
shared, which is the whole reason the check exists. The URL is parsed inside a
`python3` heredoc reading stdin, so no shell variable ever holds it.

### task-tools

Whether this session's model carries `TaskCreate` / `TaskUpdate`. Claude Code
provides them by default only on Claude 3.x, Opus 4 through 4.7, Sonnet 4 through
4.6 and Haiku 4.5; on any newer model they are absent unless the user opts in.
INFO, with the opt-in as the step.

A script cannot answer this - only the agent knows its own tool list - so the
caller passes `--task-tools=yes|no` and the default is SKIP. Reporting "absent"
from a script that never looked would be the same defect this check is about.

### mcp-registration

Whether `multi-agent` is registered as an MCP server. INFO when it is
not: the tools it provides are optional and a run without them is smaller, not
wrong.

**Registered is not the same as working.** With `--probe` the server is started
and its tools counted; serving none is WARN. Without `--probe` this reports what
is configured, and says so. The distinction is not theoretical: a half-extracted
package in the npx cache left the server dying on `Cannot find module` at
startup, which the client surfaces only as `CONNECTION_CLOSED`, and a check that
read the registration and stopped would have called that healthy. A probed
server whose version differs from the `toolkitVersion` of the vendored
`schemas/toolkit-path-params.json` is also WARN: the unattended guard confines
the parameters that file declares, so another toolkit release can carry a path
parameter the guard only judges by its shape. Without `--probe` the served
version is not known without the network, so the comparison is not made.

### mcp-surface

How many MCP servers are charged in the project the caller is standing in,
counted across three places that all cost the same: the global blocks in
`~/.claude.json` and `~/.claude/settings.json`, the per-project block inside
`~/.claude.json`, and a `.mcp.json` committed to the repo. INFO once the count
exceeds `prefs.global.mcpSurface.infoAbove` (default 8); `--explain` lists the
names with the scope each came from.

Servers registered by a marketplace plugin are NOT counted: nothing in the
config names them, and inventing a number is worse than reporting the one that
is countable.

The reason it exists: every registered server sends its tool list on every turn,
the user adds them one at a time, and nobody ever sees the running total - our
own toolkit contributes 118 tools by itself. This is the same argument that made
the pre-run context budget a measured number rather than an intention.

It only reports. It never disables a server, never blocks and never warns: how
many servers are worth their context is the user's call, not a health failure.
The threshold is judgement, which is why it is a pref instead of a constant in
the script - a number nobody can see is a number nobody can argue with.

### mcp-schema-load

How much of every turn the toolkit's tool list takes, per tool family, and
what each `MCP_TOOLKIT_CAPS` family would save. With `--probe` it is measured
from the `tools/list` the registration probe served; without it, a
`families` field in the `tool-manifest.json` beside a toolkit registered by
path is read; otherwise SKIP. Tokens are bytes / 4 of the JSON each entry is
sent as: an estimate, and the problem line says so. INFO once the total
reaches `prefs.global.mcpSurface.schemaInfoAboveTokens` (default 8000), naming
the three largest families; `--explain` lists every family. Like
`mcp-surface` it only reports: which families a repo needs is the user's call.

### mcp-failures

A server whose MCP tool calls keep failing, read from the local log
`note-mcp-failure.sh` writes on PostToolUseFailure (`mcp__.*`): one row per
failed call with the server, the tool, the time and a closed error class, never
the arguments, the output or the error text. INFO when one server failed five
times or more in the last 24 hours; `--explain` lists each such server with its
failures per tool and per class. Invalid input, a denied call and an
interrupted one are the caller's or the user's, so they never count toward the
light. A single `disk-full` failure (ENOSPC, no space left on device) in the
window lights INFO on its own, with `/multi-agent:clean-disk` as the step. SKIP
when `mcpFailures.enabled` is false or `usageLog.optOut` is true.

Nothing is probed: the light only reflects calls the sessions already made.
INFO and never WARN, because a flaky third-party server makes a session worse
without making this install unhealthy.

### disk-space

Free space on the volume holding `$HOME`, from one statfs call in
`lib/low-disk.mjs`. WARN under `diskCleaner.lowDiskGb` (default 10 GB) or
`diskCleaner.lowDiskPercent` (default 5%) free: a worktree plus a build is the
largest thing a run writes, and ENOSPC mid-run corrupts the state file it was
writing at the time. The step names `/multi-agent:clean-disk`, which measures
before it deletes anything; doctor itself deletes nothing.

What could be freed comes from the newest disk-cleaner dry run under
`~/.claude/logs/disk-cleaner/`: its reclaimable total, its three largest
categories and how long ago it ran. Doctor never measures on its own, since a
full measurement walks every cache. A run older than 24 hours, or none, is
named as such, with `/multi-agent:clean-disk` to measure. With `--probe` it
runs `disk-cleaner.mjs --dry-run --json` under a 60-second cap; a timeout is
reported in the detail and never changes the severity. Enough free space but
at least `diskCleaner.reclaimableGb` (default 10) to reclaim, from a fresh
run, is INFO with the same step:
"run /multi-agent:clean-disk: N GB can be freed". An OK result still carries the free space and the reclaimable line in
`detail.summary`, which the text output prints after the id. The JSON detail
holds `freeBytes`, `totalBytes`, `freePercent`, the thresholds,
`reclaimable` (`source`, `file`, `measuredAt`, `ageHours`, `stale`,
`totalBytes`, `top`) and `probe`.

### worktree-residue

Worktrees left under `<repo>/.worktrees/` in the repository the caller is
standing in. WARN at five or more, or at 2 GB. A finished task removes its own
worktree at PR time, but a run that stops before Phase 4 never reaches that
step and nothing else collects it: the finalizer only runs on success, and
`gc-worktrees` only sweeps entries git has already forgotten. Each survivor is
a full second checkout, so the total is measured in gigabytes rather than
megabytes. SKIP outside a git repository - a project name in prefs is a name,
not a path, and guessing checkout locations to produce a number is how a
diagnostic starts lying.

## The server profile (`--profile=server`)

Four checks that only run under `--profile=server`. They are ADDITIVE: a
default run is byte-for-byte what it was, and `--list-checks` reports whichever
set the invocation would actually perform, because a list that disagrees with
the run is worse than no list.

None of them may BLOCK. The blocking set is closed at six and these are
readiness, not correctness: a machine that fails all four still runs the
pipeline perfectly well with someone watching it. What they catch is the
failure mode of an unwatched run - stopping without saying so.

### usage-report

The outcome `usage-report.mjs` recorded for its last send attempt, read from
`logs/multi-agent/usage-last-send.json`. SKIP when `usageLog.enabled` is off or
nothing has been sent yet; OK when the last send was accepted; WARN for every
other outcome (`redirected`, `rejected`, `not-accepted`, `failed`, `skipped`),
with the status code or reason and the step that fixes it. The emitter runs
detached from phase-tracker with its output discarded, so this record is the
only surface on which a reporting path that stopped working shows up.

It reads the last registration record too and states the reporting state in
one line with the last send time (`usage-register.mjs` `reportingState`): OK
carries "registered, last send accepted" as its summary; WARN names a
rejected token with the self-heal result; INFO names a deferred registration
or one waiting for the owner's approval; WARN says `registration waiting:
enter your GitHub username with /multi-agent:setup` in outputLanguage for a
machine that proves no account. The last three are reported even while
`usageLog.enabled` is still off.

### usage-register

The outcome `usage-register.mjs` recorded for its last attempt, read from
`logs/multi-agent/usage-last-register.json`, and whether the failure report
that attempt may have sent reached the site (`usage-register-beacon.json`).
SKIP when `usageLog.optOut` is set or nothing was attempted yet; OK after a
registration or when a token is already onboarded; INFO for `pending-approval`
and for `deferred` (the accounts were not visible to that run); WARN for every other
outcome, naming the status, its detail and either "the failure report
(<reason>) reached the site", "could not be delivered" or "no failure report
was sent" (no login, a dry run, or a refusal the person chose). Registration
runs quietly from setup, update and Phase 0, so this is where a machine that
never registers shows why.

### access

The last answer of the run-time access check (`usage-access.mjs`), read from
`logs/multi-agent/access-state.json`; doctor sends nothing itself. One line in
outputLanguage: OK "access: open" (`erişim: açık`); WARN "access: closed
(<date>)" (`erişim: kapalı (<tarih>)`), with the reason and the link for an
organization invitation that waits or missing access; SKIP "access: could not
be checked" (`erişim: kontrol edilemedi`) when no check reached the site yet.

### free-models

Can `route-on --free` actually leave Claude. SKIP while routing or its free
chain is off. Otherwise it runs the toolkit's `multi-agent-mcp-llm
providers` through `lib/toolkit-llm.sh`: WARN when the CLI cannot run, or when
no provider is both configured and allowed by the data policy
(`modelRouting.free.allowTraining`), because every free task then escalates to
Claude while the user believes it does not. `--probe` also sends each
configured provider one tiny request and WARNs when every usable one fails it
(a revoked key, an exhausted quota). `--explain` lists each provider with its
key source, never a value.

### local-model

Only on the local-model host; SKIP elsewhere, naming the host, because no other
host runs a model served from this machine. BLOCK when `global.localModel` is
absent or unusable, with the reason naming the field and what it has to be: a
model id of a narrow character set, a base URL that is loopback unless
`allowRemote` is set, and a context window of at least 8192 tokens. `--probe`
also asks the server for its model list and BLOCKs when nothing answers, since a
run that reaches a phase and then cannot ask a model has already spent the
setup. The step is to set `global.localModel` in the preferences file, which the
message names by path.

### xcode-skills

Is Apple's `xcode-integration` plugin, which Xcode 27.1 and later materialize
(`xcrun agent plugin path`), linked into Claude Code at the installed Xcode
build. SKIP on Copilot CLI and Codex CLI, which receive Apple's skills as copied
directories rather than a linked plugin, so the linkage this check reads does
not describe them. SKIP when this Mac has no such plugin, because the pipeline's
own iOS skills then apply; INFO when it is available but not linked; WARN when
the link was copied from an older Xcode build than the one installed; OK
otherwise. The
step is `/multi-agent:update`, which re-runs the installer's link. Apple's skills
are the reference for iPhone Duo and window resizing, SwiftUI, App Intents and
the accessibility audits, so a stale copy is a worse answer, never a failed run.

### routine-commands

Does a saved routine still name a removed command: the plain autopilot command,
the rung command that `fable-on`, `fable-off` and `fable-status` replaced, or a
sharing action typed as a `routines` argument in any host's spelling, which `routines-share`,
`routines-browse`, `routines-import`, `routines-update` and `routines-delete`
replaced.
Saved routines are the `local-only: true` commands under
`~/.claude/commands/multi-agent` (`/multi-agent:save`), which the installer
carries across updates exactly as written, so a body that named a command keeps
typing it. SKIP when no routine is saved, OK when none names one, WARN listing
each routine with the removed commands it names, the replacement for each
(`/multi-agent "<task>" autopilot`; `/multi-agent:fable-on`,
`/multi-agent:fable-off` or `/multi-agent:fable-status`;
`/multi-agent:routines-<action>`) and the file to edit.

### mcp-legacy-names

Does the current project still name the MCP server by its pre-4.0 id. The
installer moves the user's own settings to `multi-agent`, but a project's
`.claude/settings.json`, `.claude/settings.local.json` and `.mcp.json` belong
to the repository and are not rewritten. They are read at the root of the
repository the current directory is in. A `.claude` that is the user's own
`~/.claude` is skipped: the installer keeps old entries there on purpose
until the old registration is gone. OK when none of them names the old
id, WARN listing each file and its entries, with the replacement to make:
`mcp__multi-agent__` for permission rules and hook matchers, `multi-agent` as
a server id or `.mcp.json` key.

### unattended-contract

Is `multi-agent-refs/unattended-contract.md` installed. It is the only place
that says which entry points honour `MULTI_AGENT_UNATTENDED=1` and what each
one resolves to. Without it an operator setting up a server has to read the
scripts to find out, which is how the wrong assumption gets made.

### unattended-permissions

Does `multi-agent-unattended.settings.json`, the file the runner passes with
`claude --settings`, carry the unattended profile (`schemas/unattended-profile.json`):
`defaultMode: "dontAsk"`, `Edit` and `Write` allowed, at least one narrow
`Bash(...)` rule, and every deny rule; and is there no whole-`Bash` allow in it
or in `settings.json`, whose permission lists merge into the run's. autopilot spawns its child with `--permission-prompts none`, but the
tools that child then calls still have to be allowed, and on a fresh machine
they are not - the run stops at the first prompt with nobody there to answer
it, printing nothing. This is the single most likely reason a server sits idle
and looks healthy.

### scheduler

Is a multi-agent launchd agent loaded. Something has to start the work; a
server with no agent and an empty queue looks exactly like a server that has
finished everything.

### keychain-unlock

Is a default keychain reachable from this session. Every credential the
pipeline reads lives there, and a LaunchDaemon started before login sees a
LOCKED keychain: each fetch fails, and the failures surface much later as 401s
that blame the token rather than the lock. The check is a proxy - reading a
real credential would be a network call and a side effect - so it asks whether
a login keychain is reachable at all, which is the condition a boot-time
daemon fails.
