Hooks – Mangrove

GlossaryGuardrails and control

Hooks

Definition: Hooks are commands an agent tool runs automatically at set points in an agent's work; one that runs before an action, such as a tool call, can block it.

In Claude Code, hooks are user-defined shell commands, HTTP endpoints and other handlers that run at specific points in a session, such as when it starts, before a tool call and after one (Claude Code hooks reference). A PreToolUse hook runs after the model has written a tool call’s parameters and before the tool runs. Claude Code passes it the call as JSON, and the hook can allow the call, ask the user to confirm it or deny it. A deny decision, or an exit code of 2, stops the call. Anthropic’s guide says hooks give “deterministic control”, so that certain actions always happen “rather than relying on the LLM to choose to run them” (Claude Code hooks guide). Claude Code’s documentation names Claude Code as the harness in this arrangement and says it applies a hook “every time, no matter what the model decided to do” (Claude Code best practices). Cursor’s hooks also run before or after stages of the agent’s loop and, in its documentation’s words, “can observe, block, or modify behavior” (Cursor).

For example, a hook that runs before every order request may compare the order size with an account limit and deny any order above it, whatever the model wrote in the request. A hook enforces only what its own code checks, and its failures need handling. By default, a Claude Code PreToolUse hook that times out does not block the call, and Cursor lets the action through when a hook crashes or times out unless the hook is set to block on failure. Both tools also offer hooks that ask a language model to judge a condition, and those checks are made by a model rather than by fixed code. Rules, a separate entry, are the text counterpart: instructions the model reads and may not follow.

Tim Darrah, Mangrove’s CEO, holds that a model cannot “respect” a boundary it is able to ignore, and that the harness, the software around the model, has to enforce it. Hooks are one way an agent tool lets its user add that kind of enforcement.

The idea is older than AI agents. In Git, the version-control system, hooks are “programs you can place in a hooks directory to trigger actions at certain points” in Git’s work, and a pre-commit hook that exits with a non-zero status stops the commit (Git documentation). In a patch dated 31 July 2005, Josef Weidendorfer added a hook to git-receive-pack, the Git program that handles an incoming push. It ran a script just before Git updated a pushed branch, and the script could decline the update by exiting with a non-zero status. Claude Code’s changelog records “Released hooks” in version 1.0.38, which the npm registry shows was published on 30 June 2025. Cursor added hooks as a beta feature in version 1.7 on 29 September 2025.