← ClaudeAtlas

claude-code-hookslisted

Claude Code hook system for pre/post tool execution. Triggers on: hooks, PreToolUse, PostToolUse, hook script, tool validation, audit logging.
aiskillstore/marketplace · ★ 329 · AI & Automation · score 85
Install: claude install-skill aiskillstore/marketplace
# Claude Code Hooks Execute custom scripts before/after Claude Code tool invocations. ## Quick Reference | Event | When | Has Matcher | |-------|------|-------------| | `PreToolUse` | Before tool execution | Yes | | `PostToolUse` | After tool completes | Yes | | `PermissionRequest` | Permission dialog shown | Yes | | `Notification` | Notifications sent | Yes | | `UserPromptSubmit` | User submits prompt | No | | `Stop` | Agent finishes | No | | `SubagentStop` | Subagent finishes | No | | `PreCompact` | Before context compaction | No | | `SessionStart` | Session begins/resumes | No | | `SessionEnd` | Session ends | No | ## Basic Configuration Add to `~/.claude/settings.json` or `.claude/settings.local.json`: ```json { "hooks": { "PreToolUse": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/hooks/validate.sh", "timeout": 5000 }] }] } } ``` ## Matcher Patterns | Pattern | Matches | |---------|---------| | `"Write"` | Only Write tool | | `"*"` or `""` | All tools | | `"mcp__*"` | All MCP tools | | `"Bash"` | Bash commands | ## Hook Script Requirements ```bash #!/bin/bash # Receives JSON via stdin: { "tool_name": "...", "tool_input": {...} } INPUT=$(cat) TOOL=$(echo "$INPUT" | jq -r '.tool_name') # Exit codes: # 0 = Success (continue) # 2 = Block with error (stderr shown to Claude) # Other = Non-blocking error ``` ## Common Use Cases | Use Case | Event | Example | |----------|---