What Are Hooks?
Hooks are callback functions that fire at specific points in the agent's lifecycle. They let you observe, modify, or block agent behavior without changing the agent's core logic. Think of them as checkpoints where you can inspect what the agent is doing and decide whether to let it continue.
The Hook Types
The SDK provides hooks at four critical lifecycle points:
Fires before a tool is executed. Inspect or modify the tool call parameters. Return deny to block the call entirely. Use this for input validation and permission enforcement.
Fires after a tool returns its result. Inspect or modify the result before Claude sees it. Use this for output sanitization, logging, and audit trails.
Fires when the agent wants to do something that requires explicit permission. Return allow or deny. Use this for human-in-the-loop approval workflows.
Fires when the agent is about to finish. You can inspect the final result or force the agent to continue working. Use this for quality validation.