Claude Code hooks lifecycle
All seven hook events Claude Code fires during a session, in the order they run.
Figure: Claude Code Hooks Lifecycle — Session Start to Stop. SVG is open under CC BY 4.0 — credit claude-code-examples.vercel.app.
- SessionStart — CLI launches, before any user input. Use to inject env or banners.
- UserPromptSubmit — each user message. Use to validate or block disallowed prompts.
- PreToolUse — before every tool call. Use to gate, log, or mutate arguments.
- PostToolUse — after every tool call. Use to audit results.
- Notification — when Claude wants the user's attention. Push to Slack or terminal.
- Stop — main agent turn ends. Cleanup, summary log.
- SubagentStop — subagent finishes. Aggregate child results.
Hooks live in ~/.claude/settings.json or .claude/settings.json. A return code of 2 blocks the action and surfaces stderr to Claude.
Related code examples