# Hook Callback

> Your own function that the kit runs at a set step.

**Field:** Artificial Intelligence  
**Category:** Claude Agent SDK  
**Also known as:** hooks option, HookCallbackMatcher, Agent SDK hooks, Claude Agent SDK Hook

## Think of it like

It is like a doorbell that rings in your own room.

## Definition

A hook callback is a function in your own code that the Agent SDK calls at a set point in the agent loop, such as before a tool runs. You pass them in the hooks option, keyed by event name, such as PreToolUse. A matcher such as Write|Edit limits which tools fire it. The callback can let the call go on, block it, or change its input. Hooks run before any permission rule.

## Example

Leo's hook checks every Write call. If the path is a .env file, it blocks the call and tells Claude why.

## Example code

```typescript
hooks: {
  PreToolUse: [{ matcher: "Write|Edit", hooks: [protectEnvFiles] }],
}
```

Run a check before each file write or edit.

## Why it matters

It is the first check a tool call meets. It can stop the call before any rule is read.

## Common mistake

Writing hooks in settings files and expecting the SDK to call your function. SDK hooks are passed in code.

## Three principles

- **Your function.** Called by the SDK.
- **Matcher filters.** By tool name.
- **First in order.** Before rules.

## Related terms

- [Claude Code Hook](https://learn.benibix.com/term/ai/claude-code-hook)
- [Hook Matcher](https://learn.benibix.com/term/ai/hook-matcher)
- [PreToolUse Hook](https://learn.benibix.com/term/ai/pretooluse-hook)
- [canUseTool Callback](https://learn.benibix.com/term/ai/can-use-tool-callback)

---

Source: https://learn.benibix.com/term/ai/sdk-hook-callback
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-20
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
