# Claude Code Hook

> A script Claude Code runs on its own at a fixed point, such as before a tool.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** hooks, hook handler, Claude Code hooks

## Think of it like

It is like a doorbell that rings a bell in the next room. You choose what that bell does.

## Definition

A Claude Code hook is a script or other handler that Claude Code runs on its own at a fixed point in a session. The point is called an event, such as PreToolUse before a tool runs or Stop when Claude finishes. You set hooks in a settings file. A hook gets the details as JSON and can answer back, for example to block a tool call.

## Example

Lucy wants each file Claude edits to be tidy. She adds a hook that runs her code tidier after each edit. It never forgets.

## Example code

```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "npx prettier --write ." }]
      }
    ]
  }
}
```

Format the code after every edit.

## Why it matters

A rule in CLAUDE.md is a request. A hook always runs, so it is how you make something sure to happen.

## Common mistake

Putting must-do steps in CLAUDE.md and hoping. Claude can skip a note. It cannot skip a hook.

## Three principles

- **Runs on its own.** At an event.
- **Set in settings.** JSON.
- **Can answer back.** Block or add.

## Related terms

- [/hooks Command](https://learn.benibix.com/term/ai/hooks-command)
- [PreToolUse Hook](https://learn.benibix.com/term/ai/pretooluse-hook)
- [Stop Hook](https://learn.benibix.com/term/ai/stop-hook)

![The order hook events fire in: a session, each turn, and each tool call inside it.](https://learn.benibix.com/diagrams/hook-lifecycle.svg)

---

Source: https://learn.benibix.com/term/ai/claude-code-hook
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-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
