How a hook call is decided
What happens between Claude Code calling a hook and the agent reading its answer, and why a hook never lets a call through by accident.
What happens between Claude Code calling a hook and the agent reading its answer? harness-kit picks the Policies that apply to the call, runs them together, and merges their Decisions into one answer. A failure never lets a call through by accident.
Claude Code calls the hook
It runs
harness-kit hook <event>with the call as JSON on standard input.The configuration loads
harness.config.tsat the repository root. A broken one is not ignored: calls are refused with the error and its fix.The Policies that apply decide
Those whose event, tool and agent type match, all at once, each under its own timeout. One that fails follows its fail mode: closed refuses, open lets through.
Their Decisions merge into one answer
The first deny in the configuration's order wins, questions are joined into one, and context is added up.
Claude Code calls a hook at fixed points of a session and reads its answer from the exit code and output.
The hook events
| Event | When Claude Code calls it | What a Policy usually does there |
|---|---|---|
SessionStart | a session starts, resumes or is cleared | checks the checkout and toolchain, adds context for the agent |
UserPromptSubmit | the person sends a prompt | refuses prompts while the toolchain is wrong, keeps the machine awake |
PreToolUse | before every tool call the hook entry matches | refuses or asks about the call: commands, writes, git, paths |
PostToolUse | after a tool call | records what changed, formats an edited file, objects to a result |
Stop | the agent wants to end its turn | keeps it going until lint passes or the work is committed |
SubagentStop | a subagent wants to finish | the same, for subagents |
How Decisions are merged
Every Policy answers with one Decision: allow deny ask context or block-stop. The hook merges them:
- The first deny wins, counted by the configuration's order, not by which Policy finished first. A refusal always carries a reason and a fix; the agent reads both.
- Questions are joined. When several Policies ask about one call, the person sees one question.
- Block-stop reasons are joined. When lint fails and the work is not committed, the agent reads both objections in one message.
- Context is concatenated and added to what the agent reads.
What the agent sees
Claude Code reads each event differently, and the kit writes each Decision where that event shows it:
| Event | A refusal | Everything else |
|---|---|---|
PreToolUse | the call is blocked; the agent reads the reason and fix | a question becomes Claude Code's permission prompt; context is added |
UserPromptSubmit | the prompt is refused, with the reason and fix | context is added to the prompt; nothing at all when every Policy allows |
PostToolUse | — (the call has run) | an objection is shown to the agent as a block, beside any context |
Stop, SubagentStop | — | an objection keeps the agent working, with the reason and fix |
SessionStart | — (a session start is never blocked) | every message becomes text in the agent's context |
A refusal reads as the reason, then a line starting with Fix::
Blocked: this commit would land on main, a shared branch.
Fix: Move the work onto a branch of its own first: git switch -c <task type>/<issue key>-<slug>, then commit.When a hook fails, the call is refused
Claude Code lets a tool call run when its hook exits with any code other than 0 (allow) or 2 (block), and when the hook outlasts its timeout. harness-kit makes sure neither happens by accident. Each case below ends in a refusal or a logged exception, never a silent pass.
If the configuration is broken
A configuration that is missing, cannot be loaded, is invalid or loosens one it extends is not ignored. Until it is fixed:
- tool calls are refused with the error and its fix, except reading tools, read-only shell commands (a plain pipeline of reading programs),
harness-kit config check, edits of the configuration's own files, and the dependency install and the kit's build typed alone (npm ci,npm run build -w @microeinhundert/harness-kit, or your package manager's), so the agent can repair it, or replace a stale build of the kit that cannot load a configuration written for a newer one; - a session start and a prompt get the error as context;
- a stop and a finished tool call are never blocked.
The harness configuration harness.config.ts is invalid: the options of kubectl do not decode (Expected no excess property
at ["bogus"]).
Fix: Correct harness.config.ts, then run `harness-kit config check` until it passes. Until it loads, harness-kit lets through only reading, `harness-kit config check`, edits of harness.config.ts, and the install and the build that repair the kit, each typed alone: `npm ci` or `npm run build -w @microeinhundert/harness-kit`.Related
- Policies and Decisions: what a Policy is made of.
- Debugging a configuration: see each Policy's Decision for a call.