🧩Hook Callback
Also known as hooks option, HookCallbackMatcher, Agent SDK hooks, Claude Agent SDK Hook
Your own function that the kit runs at a set step.
Think of it like
It is like a doorbell that rings in your own room.
Example
Leo's hook checks every Write call. If the path is a .env file, it blocks the call and tells Claude why.
Why it matters
It is the first check a tool call meets. It can stop the call before any rule is read.
Definition
Example code
typescript
hooks: {
PreToolUse: [{ matcher: "Write|Edit", hooks: [protectEnvFiles] }],
}Common mistake
Key takeaways
- 1Your function. Called by the SDK.
- 2Matcher filters. By tool name.
- 3First in order. Before rules.