Hooks let you run custom code at defined points in an agent's lifecycle, adding behaviour without changing the harness itself.
Common Hook Points
- Before a tool call runs.
- After a tool call completes.
- When the user submits a prompt.
- When a session starts or ends.
- When the agent stops.
Uses
- Policy enforcement: block commands matching dangerous patterns, or edits to protected files.
- Automatic formatting: run a formatter after every file edit.
- Validation: run tests or linters and feed results back.
- Logging and audit: record actions to an external system.
- Context injection: add up-to-date information at session start.
- Notifications: alert people when an agent needs attention.
Why Hooks Beat Prompt Instructions
Instructions in prompts can be forgotten or ignored. Hooks run deterministically every time. Use them for rules that must always hold.
Care Required
Hooks run with your system's permissions. Review them like any other code, keep them fast, and handle their errors so they don't break the agent.