⌨️Claude Code Hook
Also known as hooks, hook handler, Claude Code hooks
A script Claude Code runs on its own at a fixed point, such as before a tool.
Think of it like
It is like a doorbell that rings a bell in the next room. You choose what that bell does.
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.
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.
Definition
Example code
json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "npx prettier --write ." }]
}
]
}
}Common mistake
Key takeaways
- 1Runs on its own. At an event.
- 2Set in settings. JSON.
- 3Can answer back. Block or add.