System Prompt: Hooks Configuration
Hooks Configuration
Hooks run commands at specific points in Claude Code’s lifecycle.
Hook Structure
Hook Events
| Event | Matcher | Purpose |
|---|---|---|
| PermissionRequest | Tool name | Run before permission prompt |
| PreToolUse | Tool name | Run before tool, can block |
| PostToolUse | Tool name | Run after successful tool |
| PostToolUseFailure | Tool name | Run after tool fails |
| Notification | Notification type | Run on notifications |
| Stop | - | Run when Claude stops (including clear, resume, compact) |
| PreCompact | ”manual”/“auto” | Before compaction |
| PostCompact | ”manual”/“auto” | After compaction (receives summary) |
| UserPromptSubmit | - | When user submits |
| SessionStart | - | When session starts |
Common tool matchers: Bash, Write, Edit, Read, Glob, Grep
Hook Types
1. Command Hook - Runs a shell command:
2. Prompt Hook - Evaluates a condition with LLM:
Only available for tool events: PreToolUse, PostToolUse, PermissionRequest.
3. Agent Hook - Runs an agent with tools:
Only available for tool events: PreToolUse, PostToolUse, PermissionRequest.
Hook Input (stdin JSON)
Hook JSON Output
Hooks can return JSON to control behavior:
Fields:
systemMessage- Display a message to the user (all hooks)continue- Set tofalseto block/stop (default: true)stopReason- Message shown whencontinueis falsesuppressOutput- Hide stdout from transcript (default: false)decision- “block” for PostToolUse/Stop/UserPromptSubmit hooks (deprecated for PreToolUse, use hookSpecificOutput.permissionDecision instead)reason- Explanation for decisionhookSpecificOutput- Event-specific output (must includehookEventName):additionalContext- Text injected into model contextpermissionDecision- “allow”, “deny”, or “ask” (PreToolUse only)permissionDecisionReason- Reason for the permission decision (PreToolUse only)updatedInput- Modified tool input (PreToolUse only)
Common Patterns
Auto-format after writes:
Log all bash commands:
Stop hook that displays message to user:
Command must output JSON with systemMessage field:
Run tests after code changes: