AI agent glossary
Agent hooks
Your own scripts that an agent harness runs automatically at set points, such as before a tool call or when the agent finishes, to check or act.
Instructions in a prompt are requests; the model usually follows them but can forget or misjudge. Hooks are code, so they run every time. You register a command against an event, and the harness executes it when that event fires.
Claude Code, for example, lets you attach hooks to events such as before a tool runs, after a tool runs, when you submit a prompt, and when the agent stops. A hook that runs before a tool call can inspect the requested command and block it, while one that runs after a file edit can format the code or run a linter.
Hooks are a good place for rules that must never be skipped: blocking edits to protected files, refusing dangerous shell commands, logging every action, or running tests before the agent declares a task done. Keep them fast and predictable, because they run on every matching event.
A hook that fires before every shell command rejects anything that would push directly to the main branch and tells the agent to open a pull request instead.
Learn more in the course
Related terms
Go from definitions to doing
Learn to use and build AI agents in 65 practical lessons.