
Agent Hooks
Agent Hooks are predefined checkpoints in the workflow of an AI assistant where custom code is automatically executed. Developers use them to check, log, or deliberately halt the assistant's behavior.
Some AI programs don’t just answer questions — they carry out multi-step tasks on their own. They search through files, write text, run commands on the computer. Such programs are called agents. Their workflow consists of many small steps that happen one after another. Agent Hooks are predefined points within this workflow where the program briefly pauses and executes an instruction set by a human. The name comes from the English word for a hook: you attach something at a particular point.
Why agents need an emergency brake
An agent makes its own decisions. That’s exactly what makes it useful and risky at the same time. If it’s allowed to delete a file, it might delete the wrong file. If it’s allowed to send emails, it might choose the wrong address. Without checkpoints, you only notice this after the fact.
Hooks solve this problem without requiring any changes to the AI model itself. You define a rule outside the model: before a command is executed, a small program checks whether it’s allowed. This check is deterministic, meaning it always produces the same result for the same input. A language model doesn’t do this — it can answer the same question differently each time.
A common misconception is that you can simply give the model the rules within the instructions. That often works, but not always. A hook, on the other hand, is ordinary program code and cannot be talked out of anything. For companies, this difference is crucial, since they need to be able to prove their rules are being followed.
Checkpoints in an agent’s workflow
An agent works in loops. It reasons, selects a tool, uses it, looks at the result, and reasons again. Between these stages lie the typical checkpoints. Common ones are: before a tool call, after a tool call, upon receiving a user request, and at the end of a session.
At each of these points, a developer can attach a custom function. This function receives the data of that step, such as the planned command. It can then do one of three things: wave it through, modify it, or block it. If it blocks, the agent receives an error message and has to find another way.
A concrete example: a hook placed before every terminal command checks the text for the phrase “rm -rf”, which can delete entire folders. If it finds it, it aborts and writes an entry to the log. A second hook, running after every file change, automatically triggers the project’s tests. Both are just a few lines of code, yet they take effect on every single run.
Hooks in today’s developer tools
Hooks are most commonly found in AI assistants for programming. Tools like Claude Code, Cursor, or OpenAI Codex offer configuration files in which such checkpoints can be defined. Software libraries for building custom agents, such as LangChain, also know this principle under names like callbacks or middleware.
In companies, hooks primarily serve traceability. Every step an agent takes is recorded, including timestamp, cost, and result. If something goes wrong later, the chain of events can be reconstructed. This recording is called observability, meaning the ability to monitor a system from the outside.
In the news, Agent Hooks usually come up in discussions about the safety of autonomous systems. They are not a marketing term but a technical detail. Anyone reading about agents should understand them for what they are: the points where a human can still grab the steering wheel.