/claude-code-docs:hooks-referencefrom 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.
Ships in claude-code-docs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
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:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub dunc4nj/entropy-plugins --plugin claude-code-docs7 skills in this plugin
/mcp-referenceClaude Code MCP (Model Context Protocol) server configuration reference. Use when adding MCP servers, configuring external tools, or integrating third-party services./memory-referenceClaude Code memory (CLAUDE.md) configuration reference. Use when setting up project memory, understanding memory hierarchy, or configuring persistent instructions./plugins-referenceClaude Code plugins configuration reference. Use when creating plugins, bundling commands/agents/hooks/skills/MCP servers, setting up marketplaces, or distributing extensions.Other plugins' skills for the same job