Purpose: User-defined shell commands that execute at Claude Code lifecycle points
Hooks provide deterministic control over Claude Code's behavior. Unlike prompting (which suggests), hooks guarantee certain actions happen at specific points in the workflow.
settings.json or plugin's hooks/hooks.json| Use Case | Event | Example |
|---|---|---|
| Auto-format | PostToolUse |
Run prettier after Edit/Write |
| Notifications | Notification |
Desktop alert when input needed |
| File protection | PreToolUse |
Block edits to .env files |
| Logging | PreToolUse |
Track all bash commands |
| Feedback | PostToolUse |
Lint check after code changes |
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "jq -r '.tool_input.command' >> ~/.claude/bash-log.txt"
}]
}]
}
}
Hooks run with your credentials. Malicious hooks can exfiltrate data. Always review hook implementations before adding them.
../lookup/hook-events.md - All hook events../examples/hooks/ - Hook examplesReference: https://docs.anthropic.com/en/docs/claude-code/hooks