{
  "_readme": "Recommended Claude Code hooks for multi-agent-pipeline. `install` registers the pre-commit and agent-guard gates, the run-scoped run-stop-guard / run-scope-guard hooks, the task-mirror hook, the file-context hook, the skill-usage hook and the MCP failure hook itself (install/claude.mjs configureSettings, RUN_HOOKS); /multi-agent:setup offers to merge the rest of this block. Merge the `hooks` object into your ~/.claude/settings.json to make these deterministic PreToolUse gates real (exit 2 blocks the tool call). A PreToolUse matcher is a regex over the TOOL NAME, so each gate registers on a tool name and reads the command from its stdin payload. Three PreToolUse gates ship here: (1) pre-commit-check.sh on Bash, which acts only on a `git commit` and blocks a secret in the staged diff; (2) agent-guard.sh on Bash, on Edit|Write|NotebookEdit, and on WebFetch plus every multi-agent MCP tool (WebFetch|mcp__multi-agent__.*). Always, it blocks AI/assistant attribution in a commit message and a force-push, delete or mirror push to a protected branch (main/master/develop), including one inside a subshell or a `bash -c` / `eval` line. With MULTI_AGENT_UNATTENDED=1 in the hook's environment it also applies the unattended policy: no push, PR or tracker write, no Keychain read, no fetch outside the host allowlist (curl, WebFetch, the toolkit's web tools, agent_run_steps and open_url), no package install, and no write into a protected path (features/unattended-security.md); (3) check-read-size.sh on Read|Bash, which inspects Read plus the shell commands that read a file whole (cat/head/tail/sed), returns immediately for everything else, and routes an oversized read to a cheap worker instead of the caller's own rung; it is inert until `prefs.global.bulkRead.mode` is set to observe or enforce. Failure behaviour: pre-commit-check.sh and check-read-size.sh fail open on an internal error. agent-guard.sh fails open when attended, so a guard bug cannot break a legitimate tool call, and fails closed under MULTI_AGENT_UNATTENDED=1, where nobody is there to notice a gap. None of the three executes the inspected command, and none needs run-specific arguments. The other deterministic gates (evidence, consensus, intent, learnings) take run-specific arguments and are phase-enforced by the pipeline instead. Three capture hooks ship alongside them and block nothing: (4) SessionEnd runs capture-flush.sh --if-stale, which writes a run's triage findings and durable learnings into the per-repo stores when the run ended before Phase 5, where those writes otherwise happen; the same hook runs note-session.sh, which records the mechanical shape of a session outside the pipeline (tools used, commands that failed, calls the user refused). (4b) SubagentStop and PostToolUseFailure run note-agent-event.sh, which appends one row to the same session notes as the event happens: a subagent's type, id, the bound run's task id and its last message cut to 200 characters (secret-scanned; a hit stores the row without the message), or a failed tool's name and its command's first program word, never an argument or error text. (5) PreCompact runs capture-flush.sh without --if-stale: a compaction summarizes the conversation mid-phase, so it is the moment unflushed findings are at risk, and both writes are idempotent, so a finished run costs two no-op writes. The staleness test exists only so a session exit does not re-flush a run that already finished. (6) SessionStart runs capture-resume.sh, which prints at most two lines: an unfinished run and how to resume it, and a stale pipeline-observation queue. (6b) session-brief.sh runs on the same event and is opt-in: it prints nothing until prefs.global.sessionBrief.enabled is true. Enabled, it prints, from a cache that a detached process rebuilds, a block of at most prefs.global.sessionBrief.maxChars characters (default 2400, about 350 tokens): the repository's learnings ledger as an index of pointers (inside an <untrusted-data> block, after the secret scan) and one line about its code graph, plus the skill indexes of the enabled toolkits; the working notes are a separate setting, discipline, also off. A repository with no ledger entries and no code graph gets nothing. It starts no node process on a warm cache, is silent in unattended and pipeline contexts and outside a git repository, writes its cache 0600 under ~/.claude/memory/multi-agent/_session-brief/, and exits 0 on every path. No capture hook calls a model or reads a payload - note-session.sh keeps a command's first word and an exit code, never an argument or any output - and all exit 0 on every path, because a hook that fails a session over bookkeeping costs more than the bookkeeping. A GitHub write gate ships too: (2a) pr-write-guard.sh on Bash answers `ask`, naming the PR and the operation, when the command runs `pr-threads.mjs apply` (directly, through a variable, inside `bash -c`, after `env` or as `node <path>`), so /multi-agent:address-review cannot reply, resolve or push without the person approving that one write at the host; with MULTI_AGENT_UNATTENDED=1 it answers `deny`. Every other Bash call gets no output, and it exits 0 on every path. A run-scoped PreToolUse gate ships too: (2b) run-scope-guard.sh on every Figma MCP tool (mcp__.*[Ff]igma.*) denies a Figma call above phases.json thresholds.mcpAllowedThroughPhase for the run bound to the session, unless the run is in analysis mode, and records each allowed call into telemetry.mcpCalls[]; on Edit|Write|NotebookEdit the same script warns, attended only, when the target is outside the bound run's worktree (additionalContext for the model, systemMessage for the user; the call proceeds). On Agent|Task, with prefs.global.costBudget.enabled true, it asks before a subagent starts while the bound run's estimated spend is over the ceiling (denies with onExceed halt) and adds a note for the model from the warn threshold. On Bash|WebFetch|AskUserQuestion it denies a question from a bound autopilot run, a Figma read over HTTP (figma.com or api.figma.com) under the same phase rule, and, in any session, a direct write to agent-state.json or tracker-state.json (Edit/Write, a shell redirect or tee), since write-state.mjs is their only writer; the shell wrapper starts node only when the payload mentions Figma or a state file. Outside a run it is silent, and it fails open. One PostToolUse hook ships as well and blocks nothing: (7) edit-syntax-gate.sh on Edit|Write|MultiEdit parses the file the edit just wrote (swiftc -parse, node --check, py_compile into a temp dir, JSON.parse, bash -n; Kotlin skipped) under a 2 s deadline and, when it no longer parses, hands the model the error as PostToolUse additionalContext; it exits 0 on every path, stays silent when a parser is missing or slow, and is inert until `prefs.global.editSyntaxGate.enabled` is true. A second PostToolUse hook blocks nothing either: (7b) task-mirror.sh on TaskCreate|TaskUpdate mirrors the native task list into the tracker of the run bound to the session (phase-tracker.sh task, tracker-contract.md, \"Mirroring the host's task list\"), skipping phase tiles, so the office panel shows the same list; silent outside a run, exit 0 on every path. A third blocks nothing: (7c) file-context.sh on Read (PostToolUse, and PreToolUse on Read|Grep|Glob) hands the model, once per file per session, what the repo's memory says about the file it reads or searches (ledger facts whose scope covers it, its latest review findings, its open known limits from debt-ledger.mjs) as additionalContext inside an <untrusted-data> block, after the secret scan and fitted to the host's 10,000-character hook output limit; a Grep with a path, or a Glob whose literal directory is inside the repo, is mapped to at most five files the stores know, and a whole-repo search gets nothing; inside a run bound to the session by default, everywhere with prefs.global.fileContext.enabled true, never with it false; exit 0 on every path. A fourth blocks nothing: (7d) answer-check.sh on AskUserQuestion names, as PostToolUse additionalContext, every question the user submitted without a choice, so an empty answer is asked again instead of resolved to the Recommended option; it runs in every session, since it only adds context, and exits 0 on every path. A fifth blocks nothing: (7e) graph-hint.sh on Grep|Glob (PreToolUse) adds, once per session, one line pointing at `/multi-agent:graph ask` and mcp__multi-agent__graph_query when the call searches the whole repo for a bare identifier and a current code graph (graphFreshness: build commit is HEAD, no indexed file changed) exists for the repo; silent with prefs.global.codeGraph.enabled false; exit 0 on every path. A sixth blocks nothing: (7f) note-skill-use.sh on Skill (PostToolUse and PostToolUseFailure) appends one row to the local <log root>/skill-usage.jsonl: the skill name (kept only when it matches a strict charset and length and carries no credential pattern, else the call is dropped), ok or error, the time, the host and the repo folder name (null outside a git repository and for a repository in prefs.global.memory.excludeProjects), never the arguments, the prompt or any output; past 1 MiB the log moves to skill-usage.jsonl.1; off with prefs.global.skillUsage.enabled false or prefs.global.usageLog.optOut true; it reads stdin for at most 1.5 s and exits 0 on every path. skill-usage.mjs summary and prune-candidates read it. A seventh blocks nothing: (7g) note-mcp-failure.sh on mcp__.* (PostToolUseFailure) appends one row to the local <log root>/mcp-failures.jsonl: the server and tool from the tool name (dropped unless both match a strict charset and length and carry no credential pattern), the time and a closed error class (the host's interrupt flag first, then a refusal by the user or the permission layer, then a JSON-RPC code in the error text, then a message opening with invalid or validation, then an HTTP status, then fixed patterns), never the arguments, the output or the error text itself; it probes nothing, is written by the same code as the skill-usage log, so it has the same 1 MiB cap and .1 generation, rotates under its own mcp-failures.jsonl.lock, never follows a symlink at the log path, is off with prefs.global.mcpFailures.enabled false or prefs.global.usageLog.optOut true, and exits 0 on every path; doctor's mcp-failures check reads it. note-mcp-call.sh is registered on PostToolUse for mcp__.* with \"async\": true (the host's hook schema defines `async`: if true, the hook runs in the background without blocking) and counts the calls that succeeded for the usage record: it starts no node process, reads the first 8 KiB of the payload, and does nothing unless the marker file <log root>/mcp-counting-on exists and is newer than the preferences file (the marker is written by the usage report and the failure hook, with a real parser, only while prefs.global.usageLog.enabled is true and neither usageLog.optOut nor mcpFailures.enabled false is set); it appends one line, the session id and the tool name, to <log root>/mcp-calls.log, which the next usage report folds into <log root>/mcp-calls.json (counts per host session, owner-only, at most 200 names per session and 20 sessions), under the same two off switches. note-command-use.sh is registered on UserPromptSubmit with \"async\": true and counts which /multi-agent commands are typed: it starts no node process, reads the first 8 KiB of the payload, looks only at a prompt whose first token is /multi-agent:<name> (or /multi-agent <name> for a shipped command), appends the shipped command name or the constant other to <log root>/cmd-calls.log, and stores no argument, text or length; it does nothing unless the marker file <log root>/cmd-counting-on exists and is newer than the preferences file (written only while prefs.global.usageLog.enabled is true and usageLog.optOut is not). One Stop hook ships as well: (8) run-stop-guard.sh answers {\"decision\":\"block\"} when the session driving an active pipeline run (bound through agent-state.json sessionId or hostSessionId, never by a worktree match) tries to stop while the run is in_progress below its mode's last phase with no haltReason or waitingFor; the reason says to finish the current phase, record the wait, or record a halt. A turn that ends on a question to the user, a session with background tasks or crons, and prefs.global.stopGuard.enabled false are never held, and run-stop-guard.sh is not registered on SubagentStop: a subagent's stop is the dispatching session's business. After three consecutive blocks it records the halt itself (status paused, haltReason <phase>:stop-guard), which write-state clears when the run advances a phase. It never blocks outside a run and fails open, with a line in <log root>/hook-failures.log, on any error. These registrations are Claude Code's; README \"Hooks per host\" lists which have no equivalent elsewhere. On Codex only the syntax gate is offered, from codex-hooks.json through host-hooks.mjs; Copilot CLI gets none, since as of 1.0.45 it discards postToolUse output; the other gates are Claude Code only. multi-agent:setup offers to merge this block.",
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/pre-commit-check.sh\"",
            "timeout": 15,
            "statusMessage": "Scanning staged changes for secrets..."
          },
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/agent-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking commit/push safety (attribution + force-push)..."
          }
        ]
      },
      {
        "matcher": "Edit|Write|NotebookEdit",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/agent-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the edit target..."
          },
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/run-scope-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the edit is inside the run's worktree..."
          }
        ]
      },
      {
        "matcher": "WebFetch|mcp__multi-agent__.*",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/agent-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the fetch host..."
          }
        ]
      },
      {
        "matcher": "Bash|WebFetch|AskUserQuestion",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/run-scope-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the call against the run's phase and state file..."
          }
        ]
      },
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/pr-write-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking for a GitHub write that needs your approval..."
          }
        ]
      },
      {
        "matcher": "Read|Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/check-read-size.sh\"",
            "timeout": 10,
            "statusMessage": "Checking read size..."
          }
        ]
      },
      {
        "matcher": "mcp__.*[Ff]igma.*",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/run-scope-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the Figma call against the run's phase..."
          }
        ]
      },
      {
        "matcher": "Agent|Task",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/run-scope-guard.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the run's cost budget before a new subagent..."
          }
        ]
      },
      {
        "matcher": "Read|Grep|Glob",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/file-context.sh\"",
            "timeout": 10,
            "statusMessage": "Looking up what the repo's memory says about these files..."
          }
        ]
      },
      {
        "matcher": "Grep|Glob",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/graph-hint.sh\"",
            "timeout": 10,
            "statusMessage": "Checking whether the code graph answers this search..."
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/edit-syntax-gate.sh\"",
            "timeout": 10,
            "statusMessage": "Checking the edited file parses..."
          }
        ]
      },
      {
        "matcher": "TaskCreate|TaskUpdate",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/task-mirror.sh\"",
            "timeout": 10,
            "statusMessage": "Mirroring the task list into the run tracker..."
          }
        ]
      },
      {
        "matcher": "AskUserQuestion",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/answer-check.sh\"",
            "timeout": 10,
            "statusMessage": "Checking every question got an answer..."
          }
        ]
      },
      {
        "matcher": "Read",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/file-context.sh\"",
            "timeout": 10,
            "statusMessage": "Looking up what the repo's memory says about this file..."
          }
        ]
      },
      {
        "matcher": "Skill",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-skill-use.sh\"",
            "timeout": 5,
            "statusMessage": "Counting the skill call..."
          }
        ]
      },
      {
        "matcher": "mcp__.*",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-mcp-call.sh\"",
            "async": true,
            "timeout": 5,
            "statusMessage": "Counting the MCP call..."
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-command-use.sh\"",
            "async": true,
            "timeout": 5,
            "statusMessage": "Counting the command..."
          }
        ]
      }
    ],
    "PostToolUseFailure": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-agent-event.sh\"",
            "timeout": 20,
            "statusMessage": "Noting the failed tool call..."
          }
        ]
      },
      {
        "matcher": "Skill",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-skill-use.sh\"",
            "timeout": 5,
            "statusMessage": "Counting the skill call..."
          }
        ]
      },
      {
        "matcher": "mcp__.*",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-mcp-failure.sh\"",
            "timeout": 5,
            "statusMessage": "Counting the failed MCP call..."
          }
        ]
      }
    ],
    "PreCompact": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/capture-flush.sh\" --quiet",
            "timeout": 20,
            "statusMessage": "Persisting what this run learned before compaction..."
          }
        ]
      }
    ],
    "SessionEnd": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/capture-flush.sh\" --if-stale --quiet",
            "timeout": 20,
            "statusMessage": "Persisting what this run learned..."
          },
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-session.sh\"",
            "timeout": 20,
            "statusMessage": "Noting this session..."
          }
        ]
      }
    ],
    "SessionStart": [
      {
        "matcher": "startup|resume|clear|compact",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/capture-resume.sh\"",
            "timeout": 10,
            "statusMessage": "Checking for unfinished runs..."
          },
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/session-brief.sh\"",
            "timeout": 5,
            "statusMessage": "Loading the session brief..."
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/run-stop-guard.sh\"",
            "timeout": 15,
            "statusMessage": "Checking the pipeline run is not left mid-phase..."
          }
        ]
      }
    ],
    "SubagentStop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"$HOME/.claude/scripts/note-agent-event.sh\"",
            "timeout": 20,
            "statusMessage": "Noting the subagent's outcome..."
          }
        ]
      }
    ]
  }
}
