Hooks
Scripts the harness runs automatically at fixed points, such as before a tool call or after an edit.
Hooks are scripts the agent harness runs automatically at fixed points, such as before a tool call, after a file edit or when the agent tries to finish. A hook can format a file after every edit, block a dangerous command, or run tests before the agent stops.
Unlike instructions in a prompt, a hook always runs, so it turns a preference into a guarantee. In Claude Code, for example, events such as PreToolUse, PostToolUse and Stop trigger your scripts, and a script can block the action and tell the agent why (hooks reference). Other coding agents offer similar mechanisms under other names. Hooks run with your permissions on your machine, so a hook from an untrusted repository is code you execute; review it like any script. Slow hooks slow every step, so heavy checks usually go into the stop hook or CI.
They complement AGENTS.md and CLAUDE.md: prose explains the rule, the hook enforces it. In an evaluator-optimizer loop, a stop hook that runs the test suite plays the evaluator and sends the agent back to work until the checks pass. Hooks live inside the agent; guardrails usually mean checks on model input and output in a production application.
Sources
- Claude Code Docs: Hooks reference code.claude.com
Related terms
- AGENTS.md and CLAUDE.md: Files in a repository with the rules a coding agent reads at the start of every session.
- Guardrails: Checks around a model that block, fix or flag inputs and outputs that break the rules.
- Coding agent: An agent that reads a repository, edits files, runs commands and tests, and opens pull requests.
- Agent harness (harness engineering): Everything around the model that makes it an agent: the loop, tools, permissions, instructions, saved state, checks and session handoff.
- Evaluator-optimizer (maker-checker): One model drafts, another checks the draft against stated criteria and returns feedback, in a loop until it passes or a round limit stops it.
- Agent sandbox: An isolated environment where an AI agent runs code and commands without access to your network, secrets or real files.
- Validation loop (agent backpressure): Commands a coding agent runs after every change (tests, types, lint, build) and fixes against until they pass, so it checks itself before a person looks.
- Agent plugins (marketplaces): Installable packages that add commands, skills, subagents, hooks and MCP servers to a coding agent, shared through public or company marketplaces.
