Available hook events with timing:
- SessionStart
- When it fires: Claude Code starts a new session or resumes existing one
- Why useful: Load development context, set environment variables, check git status
- Payload: Source type (startup/resume/clear), session information
- Example use: Auto-load recent issues, check git status, prime development context
- UserPromptSubmit
- When it fires: Immediately when user submits a prompt (before Claude processes it)
- Why useful: Validate prompts, inject context, add security filtering, enhance requests
- Payload: Prompt text, session_id, timestamp
- Example use: Add automatic context injection, validate dangerous requests, log all prompts
- PreToolUse
- When it fires: Before any tool execution (can block dangerous commands)
- Why useful: Security validation, permission checking, command filtering
- Payload: Tool name, tool input parameters
- Example use: Block rm -rf commands, prevent .env file access, validate file paths
- PostToolUse
- When it fires: After successful tool completion
- Why useful: Automatic formatting, testing, logging, notification sending
- Payload: Tool name, input parameters, tool response with results
- Example use: Auto-format code after editing, run tests after changes, update docs
- Stop
- When it fires: When conversation stops or user disconnects
- Why useful: Cleanup tasks, final commits, summary generation
- Payload: Session summary, final state
- Example use: Auto-commit changes, send summary reports, cleanup temp files
- Notification
- When it fires: When Claude Code sends notifications (waiting for input, etc.)
- Why useful: Custom alerts, text-to-speech, external notifications
- Payload: Message content, notification type
- Example use: Desktop notifications, TTS alerts, Slack messages