The most common control in an agent's harness is a sentence. "Search the notes before you write to them." It sits in the system prompt or a rules file, the model reads it on every call, and the team that wrote it counts it as a safeguard. Whether the model acts on it is up to the model. A hook is the other place a control can live, and it is a different kind of thing.

Thesis: A hook is a channel the harness owns: code that runs on an event in the loop, a prompt arriving, a tool about to run, the model saying it is done, and can record, inject, block a call, ask a person, rewrite a call's input or refuse to stop, without asking the model. A rule in the prompt is advisory text the model weighs against everything else in its window and may drop. Use the channel for what only it can do: capture what happened, shape what the model sees, point at a live source, and refuse the one act where not looking is expensive. Fire it on everything and it tends to become background noise the model skips.


What a Hook Is

The harness is the code that calls the model, runs its tools and assembles each request (Anatomy of a Turn). A hook is a place in the harness where your code runs when something happens in the loop: the harness fires it on an event, hands it what it knows, and reads back a decision. The model never sees the hook's code, only its consequences.

Claude Code's hooks reference lists more than thirty events, among them SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact and Stop, and three sentences from it carry the idea. On a PreToolUse hook: "The hook can deny the call, but staying silent doesn't approve it." On a Stop hook returning a blocking code: it "Prevents Claude from stopping, continues the conversation." On text a hook injects: "Claude Code wraps the string in a system reminder and inserts it into the conversation at the point where the hook fired." An event, your code, a decision the model did not make. On a tool call that decision can block the call and send the model back with the reason, ask a person, or rewrite the call's input; it has no documented way to change which tool is called, and a command or HTTP hook that errors or times out does not stop the call, which goes on to the normal permission check, unless the hook is set to block on failure. A stop hook's refusal has a limit too: by default, after eight continuations in a row with no tool call, Claude Code ends the turn anyway, and a stop hook that fails lets it end.

Step 6 of 7

The hook itself fails

This time the hook errors or times out. Unless it is set to block on failure, a command or HTTP hook that fails does not stop the call: it goes on to the permission check.

Read this figure as text

An Example from Supplier Master Data

  1. A tool about to run The model calls the ERP write tool to change a bank field. Before the tool runs, the PreToolUse hook takes the call; it logs every attempted write, allowed or denied, to a ledger the agent cannot edit. The call travels from the model into the hook and stops there. The hook's four answers wait on the right, its ways out drawn faint, and the ledger under it is empty.
  2. Blocked, with the reason The request carries no verification reference the callback tool issued this session, so the hook blocks the call and sends the model back with a reason that names that tool. The line to Block draws, a bar closes the way on, and a line runs from Block back to the model; Block's line now reads that its reason names the callback tool. The ledger shows one mark for this attempt.
  3. Ask a person The hook can ask a person instead, so the decision on this call is one the model did not make. The line to Ask a person draws and that card is outlined; the call stays in the hook. The ledger shows one mark for this attempt.
  4. Rewrite the call's input The hook can rewrite the call's input, but it has no documented way to change which tool is called. The rewritten call still meets the deny and ask rules. The call's input line is marked as rewritten while its tool, the ERP write tool, stays the same; the line to Rewrite draws and the call travels down into the permission check. The ledger shows one mark for this attempt.
  5. Stay silent A hook that stays silent has not approved the call. It goes on to the normal permission check. The line to Stay silent draws and the call travels down into the permission check, where it is outlined. The ledger shows one mark for this attempt.
  6. The hook itself fails This time the hook errors or times out. Unless it is set to block on failure, a command or HTTP hook that fails does not stop the call: it goes on to the permission check. The hook's outline breaks into dashes and its four answers fade: none of them fires. The call travels down into the permission check and is outlined. Whether the failed hook wrote its ledger line is not stated, so the attempt's one mark is a question mark.
  7. Set to block on failure Set to block on failure, the same failure stops the call at the hook. The hard deny still belongs in the permission rules, which are evaluated whatever the hook returns. The hook is still dashed and its answers faded; a bar closes the way on and the call stays in the hook. The permission check gets a heavy outline. The attempt's one mark is again a question mark.

A Rule Is Advisory

An agent's instructions arrive in layers, and every layer is the same kind of thing: text in the model's input. The system prompt is written by the team that built the agent and is in the window on every call. A project file, a CLAUDE.md or an AGENTS.md, carries the project's standing instructions; the AGENTS.md site calls it "a README for agents." Rules are scoped instructions, loaded always or when a matching file is in play; skills are procedures loaded on demand: Claude Code's documentation says a skill's "full content only loads when a skill is used." None of the four executes; the model weighs each against everything else in its window, and Instructions That Outlive the Model calls every behavioural instruction "a bet against the next model." This site's split for Cursor, Rules vs Skills in AI Dev, shows the practice: rules say what to know, skills what to do.

Take one control in two placements. A harness injects a pointer on every prompt: search the project's notes before you act. A signal that fires on every input carries no information about this input, so the model has every reason to treat it as background noise ("chrome") and move on. Fire the same pointer once per session, at the start, and it is still a sentence: read once, then weighed against everything that follows it in the window. Neither placement is a control. Both are sentences.

A rule in the prompt A hook A permission The sandbox
Who enforces it the model, if it chooses your code, on an event the harness, before a tool runs the OS, the network, the identity provider
Can the model ignore it yes no no no
Good for judgement, tone, the goal capture, shape, point, one narrow refusal what runs without a human what can be reached at all

Four Jobs a Hook Does Well

Most of what a hook should do is not refusal.

Capture. Record what happened in a ledger the model does not write. Anatomy of a Turn says the audit record is what the model received, not the chat log; a PostToolUse hook (with PostToolUseFailure for errors) records each tool call that runs and its result, the part of that record the model would otherwise be asked to remember.

Shape. Structure what the model will see next. A PreCompact hook can write the live identifiers to a progress file before the summary replaces the transcript, and a SessionStart hook that fires after compaction can point the next turn at it. Asking the summariser to keep them is not enough: What Compaction Actually Destroys measured the loss (of 101 file paths in one session, 5 survived compaction) and found that a prose instruction lifted decisions to 100% but kept none of the planted citations (0 of 15).

Point. Inject a pointer to a live read, never the content, which goes stale and costs tokens on every call it rides in. Fire it only at the moment it applies, on the tool event where the read matters, not on every prompt: a pointer is still advice, and one that must be obeyed belongs under Refuse.

Refuse. Deny one act where not looking is expensive, and say how to clear the denial. Agents Will Lie to Escape the Loop describes Anthropic's harness primitives for long-running Claude agents, where a PreToolUse hook "denies writing to test-results.json unless the agent has first read a matching evidence file," so the agent "cannot talk its way to done." The same post describes a subagent harness whose stop hook "reads the task ledger when the agent tries to terminate; if the ledger still has open tasks, it refuses to stop." Both bind to an artifact the model does not control.

flowchart TD
    subgraph Rule["A rule in the prompt"]
        direction TB
        R1["Search the notes before<br/>you write to them, in the<br/>input on every call"] --> R2["The model reads it<br/>with everything else"]
        R2 --> R3{"Acts on it?"}
        R3 -->|"this time"| R4["Followed"]
        R3 -->|"treated as noise"| R5["Ignored<br/>background noise"]
    end
    subgraph Hook["A hook on the act"]
        direction TB
        H1["A write to the notes<br/>is about to run"] --> H2{"Has a search happened<br/>this session?"}
        H2 -->|"yes"| H3["The write runs"]
        H2 -->|"no"| H4["Denied, with the call<br/>that clears it"]
    end

    style R5 fill:#9d4444
    style H4 fill:#2d6a4f

Same intent, placed differently: read on every call and acted on or not, the ignored branch shown in red; or fired once, at the write, the denial shown in green carrying the instruction that clears it.

Fire It Rarely, Bind the Signal

Frequency destroys a signal. A hook that cannot be made rare should not be made louder; it should be moved to the act where not looking is expensive, and made to block there.

Bind the signal, never a proxy. A gate that checks for a search by scanning the transcript text for the search tool's name can pass when no search happened, because a harness may write its own tool inventory into the transcript at session start, and the name is then always there. A gate that parses the transcript for an actual tool-use event reads behaviour instead. The first reads strings, and a gate that reads strings can report as enforcement while enforcing nothing. Replay any gate over real session transcripts before you trust it.

Decide the failure mode. A hook that shapes or points fails open: a broken hook must never break a tool call. A hook that refuses an irreversible act fails closed, and says so. A hook that has timed out has denied nothing, unless it is set to block on failure, so the hard deny belongs in the permission rules: Claude Code's hooks reference says deny and ask rules "are still evaluated regardless of what the hook returns". The evidence check stays in the hook. Back both with a check the agent cannot skip, because any client-side gate has a bypass flag somewhere.

Permissions and the Sandbox Beside It

Two coarser, cheaper control layers sit beside hooks.

Permissions decide what runs without asking a human. Claude Code's documentation puts it in one line: "permissions control what Claude can do without asking." Commands That Know When to Merge, written for Cursor, shows the practice: reversible local actions run, destructive or shared-state ones wait for confirmation. Confidence Is Not Consent supplies the rule behind it: the deterministic gates carry the weight, and an irreversible write is never automatic at any confidence.

The sandbox decides what the commands inside it can reach at all. The Agent Sandbox You Already Run reads Anthropic's four precautions for computer use, minimal privileges, no credentials in the model's reach, an allowlist and a human on consequential decisions.

The sandbox bounds what exists for the commands that run inside it. Permissions bound what runs without a person. Hooks bound what happens on an event. A rule in the prompt is not on the list, because it bounds nothing; it asks.

When a Rule in the Prompt Is Enough

A hook is code, and wrong in its own ways, as a gate that reads strings is. Four cases where the sentence should stay a sentence.

The act is reversible and loud. A wrong formatting choice, a verbose commit message: a miss costs a re-run and everyone sees it.

The instruction is about judgement, not an act. "Prefer the simpler design." No event carries these and no code can evaluate them; Bound, Don't Script argues they should be most of what you write.

The model has to understand why. A hook denies; it does not teach. The Fence It Wrote for Itself quotes the file an agent wrote for a night with no human in the loop; its opening paragraph says "work that needs a person is not deferred politely, it is out of scope for this run". Nothing in that file executes, and no hook could say that.

The bar is a human. If nothing ships without a person's review, the person is the control.

The line is the one Confidence Is Not Consent draws for autonomy: reversibility and blast radius. Advise where a miss is cheap. Refuse, in code, where it is not.

An Example from Supplier Master Data

A finance team runs an agent that reconciles supplier records against incoming documents and updates the ERP, bank details included. "Never change bank details without a verified callback" was in its project file from day one. Here is where each control went.

The sandbox and identity: the agent runs on a segment that reaches the ERP and nothing else, and signs in as itself with a clerk's rights, able to edit a supplier record and not to approve a payment. Permissions: reads run without asking; the ERP write tool asks for confirmation on any field in the payment group. Hooks: a PreToolUse hook on that tool denies any change to a bank field unless the request carries a verification reference the callback tool issued this session, and its denial names that tool; the PreToolUse hook logs every attempted write, allowed or denied, and a PostToolUse hook (with PostToolUseFailure) logs each one that ran, to a ledger the agent cannot edit; a Stop hook sends the agent back to work while the reconciliation table has open rows, within the harness's cap on repeated continuations. The rule stays in the project file as the reason: it tells the model why the denial will come, so it does the callback first instead of fighting the gate.

The sentence did not get less true. It got a mechanism behind it, and a ledger that proves the mechanism fired.


What to Do Next

  • List your controls and sort them. For each instruction you count as a safeguard, say whether anything executes it. The ones in the prompt are advice.
  • Move the one that matters to the act. Put a PreToolUse hook on the single irreversible or expensive action in your agent's reach, one that denies without evidence and says how to get it.
  • Count how often each hook fires. One that fires on every prompt or every session is likely chrome. Make it rare or make it a gate.
  • Check what the gate reads. If it scans transcript text for a name, it reads strings; bind it to the event or the artifact and replay it over real sessions.

Related reading: Agents Will Lie to Escape the Loop for the two refusal patterns, Confidence Is Not Consent for why deterministic gates carry the weight, The Agent Sandbox You Already Run for the layer beneath permissions, and Instructions That Outlive the Model for what belongs in the prompt.