From claude-code-docs
Claude Code hooks configuration reference. Use when creating hooks, understanding hook events (PreToolUse, PostToolUse, Stop, SessionStart, etc.), debugging hook behavior, or implementing automation.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-code-docs:hooks-referenceThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Hooks are user-defined shell commands that execute at various points in Claude Code's lifecycle, providing deterministic control over behavior.
Hooks are user-defined shell commands that execute at various points in Claude Code's lifecycle, providing deterministic control over behavior.
| Event | When | Input | Can Control |
|---|---|---|---|
PreToolUse | Before tool runs | Tool name, inputs | Block/modify tool |
PostToolUse | After tool succeeds | Tool name, result | Feedback to Claude |
PostToolUseFailure | After tool fails | Tool name, error | Error handling |
PermissionRequest | Permission dialog shown | Details | Allow/deny |
UserPromptSubmit | User submits prompt | User input | Modify prompt |
Notification | Notification sent | Message | Custom notifications |
Stop | Claude stops | Reason | Continue/stop |
SubagentStop | Subagent completes | Result | Subagent behavior |
PreCompact | Before compaction | Context | Modify context |
SessionStart | Session begins | Session info | Env setup |
SessionEnd | Session ends | Stats | Cleanup |
~/.claude/settings.json # User-level (all projects)
.claude/settings.json # Project-level (team shared)
.claude/settings.local.json # Project-local (gitignored)
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "your-script.sh"
}
]
}
]
}
}
| Pattern | Matches |
|---|---|
* | All tools |
Bash | Bash tool only |
Write|Edit | Write or Edit tools |
Read.* | Read and any Read variants |
{
"type": "command",
"command": "jq '.tool_input' >> /tmp/log.txt"
}
{
"type": "prompt",
"prompt": "Review the output: $ARGUMENTS"
}
{
"type": "agent",
"prompt": "Verify the changes meet security requirements"
}
| Exit Code | Effect |
|---|---|
0 | Success, continue |
2 | Block (PreToolUse only) |
| Non-zero | Error, continue with warning |
{
"continue": true,
"decision": "approve",
"reason": "Looks good",
"suppressOutput": false
}
{
"PostToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": "jq -r '.tool_input.file_path' | xargs prettier --write"
}]
}]
}
{
"PreToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": "jq -e '.tool_input.file_path | test(\"\\\\.env|\\\\.git\")' && exit 2 || exit 0"
}]
}]
}
{
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "jq -r '.tool_input.command' >> ~/.claude/bash-log.txt"
}]
}]
}
| Variable | Value |
|---|---|
CLAUDE_PROJECT_DIR | Project root directory |
CLAUDE_PLUGIN_ROOT | Plugin installation path |
# View loaded hooks
/hooks
# Test hook manually with sample input
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | your-hook.sh
# Check exit code
echo $?
For complete documentation including all event schemas, see:
npx claudepluginhub DuncanJurman/entropy-plugins --plugin claude-code-docsFetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
Applies a firm's KYC/AML rules grid to parsed onboarding records: assigns risk rating, checks required documents, outputs rule outcomes with citations, and routes for escalation.
Generates daily or weekly digests of activity from connected sources (chat, email, docs, tasks, CRM), highlighting action items, decisions, mentions, and project updates.