Skip to Content
harness-kit

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.

  1. Claude Code calls the hook

    It runs harness-kit hook <event> with the call as JSON on standard input.

  2. The configuration loads

    harness.config.ts at the repository root. A broken one is not ignored: calls are refused with the error and its fix.

  3. 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.

  4. 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.

denyExit 2: the call is blocked, and the agent reads the reason and a Fix: line.
askClaude Code's permission prompt: the person decides.
allowThe call runs as the agent asked.
contextText added to what the agent reads, beside any other answer.
How harness-kit decides one hook call

Claude Code calls a hook at fixed points of a session and reads its answer from the exit code and output.

The hook events

EventWhen Claude Code calls itWhat a Policy usually does there
SessionStarta session starts, resumes or is clearedchecks the checkout and toolchain, adds context for the agent
UserPromptSubmitthe person sends a promptrefuses prompts while the toolchain is wrong, keeps the machine awake
PreToolUsebefore every tool call the hook entry matchesrefuses or asks about the call: commands, writes, git, paths
PostToolUseafter a tool callrecords what changed, formats an edited file, objects to a result
Stopthe agent wants to end its turnkeeps it going until lint passes or the work is committed
SubagentStopa subagent wants to finishthe 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:

EventA refusalEverything else
PreToolUsethe call is blocked; the agent reads the reason and fixa question becomes Claude Code's permission prompt; context is added
UserPromptSubmitthe prompt is refused, with the reason and fixcontext 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::

What the agent reads
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.
What the agent reads
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`.

On this page