How Hooks Work
1
PreToolUse hooks
Run before the tool executes. They can block (exit code 2) or warn (stderr without blocking).
2
PostToolUse hooks
Run after the tool completes. They can analyze output but cannot block.
3
Stop hooks
Run after each Claude response.
4
SessionStart/SessionEnd hooks
Run at session lifecycle boundaries.
5
PreCompact hooks
Run before context compaction, useful for saving state.
Hook Types
PreToolUse Hooks
PostToolUse Hooks
Lifecycle Hooks
Hook Configuration
Hooks are defined inhooks.json in your plugin directory. Here’s the complete configuration:
hooks.json
Hook Input Schema
Hooks receive tool information as JSON on stdin:Exit Codes
0— Success (continue execution)2— Block the tool call (PreToolUse only)- Other non-zero — Error (logged but does not block)
Async Hooks
For hooks that should not block the main flow (e.g., background analysis):Cross-Platform Notes
All hooks in this plugin use Node.js (node -e or node script.js) for maximum compatibility across Windows, macOS, and Linux. Avoid bash-specific syntax in hooks.
Next Steps
Memory Persistence
Learn about session lifecycle hooks
Strategic Compact
Understand compaction suggestions
Custom Hooks
Create your own hooks