Claude Code supports the following hooks that trigger at different points during execution:
- When it triggers: When Claude needs user input or attention
- Use case: Get notified when Claude is waiting for you
- Example: Play a sound or show a notification
- When it triggers: When Claude completes a task or stops processing
- Use case: Know when your requested task is done
- Matcher tip: Use
^(?!.*Bash).*$to exclude Bash commands
- When it triggers: Before Claude uses any tool (Bash, Write, Edit, etc.)
- Use case: Log actions, validate operations, or prepare environment
- Matcher examples:
"Bash"- Before running shell commands"Write|Edit"- Before file modifications"Read"- Before reading files
- When it triggers: After Claude completes using a tool
- Use case: Clean up, validate results, or log completions
- When it triggers: When you submit a prompt to Claude
- Use case: Log user requests, track usage
- When it triggers: When a Claude Code session begins
- Use case: Set up environment, start logging
- When it triggers: When a Claude Code session ends
- Use case: Clean up, save logs, send summary
- When it triggers: When a subagent completes its task
- Use case: Track complex multi-step operations
- When it triggers: Before Claude compacts conversation history
- Use case: Save conversation state, backup important context
The matcher field supports:
- Empty string
"": Matches everything - Tool names:
"Bash","Write","Edit","Read", etc. - Pipe for OR:
"Write|Edit"matches either Write or Edit - Regex patterns:
^(?!.*Bash).*$matches everything except Bash
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "your-notification-command"
}
]
}
]
}
}{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "notification-command"
}
]
}
],
"Stop": [
{
"matcher": "^(?!.*Bash).*$",
"hooks": [
{
"type": "command",
"command": "completion-command"
}
]
}
]
}
}Add PreToolUse and PostToolUse hooks to monitor all operations.
- Start simple: Begin with just Notification hook
- Test carefully: Hooks run frequently, avoid slow commands
- Use matchers: Filter hooks to specific tools to reduce noise
- Timeout: Add
"timeout": 5to prevent hanging hooks - Debug: Use
echocommands first to understand when hooks trigger