Claude Code hooks are configured in settings.json or settings.local.json files.
This directory contains example hook scripts that can be referenced in your configuration.
Add hooks to your settings file:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "path/to/hook-script.sh"
}
]
}
]
}
}
| Event | Description | Has Matcher |
|---|---|---|
PreToolUse |
Before tool execution | Yes |
PostToolUse |
After tool completes | Yes |
PermissionRequest |
When permission dialog shown | Yes |
Notification |
When notifications sent | Yes |
UserPromptSubmit |
When user submits prompt | No |
Stop |
When agent finishes | No |
SubagentStop |
When subagent finishes | No |
PreCompact |
Before context compaction | No |
SessionStart |
Session begins/resumes | No |
SessionEnd |
Session ends | No |
0: Success2: Blocking error (stderr shown to Claude)See the example scripts in this directory for common patterns.