Claude Code hooks lifecycle

All seven hook events Claude Code fires during a session, in the order they run.

Flow diagram of seven Claude Code hooks arranged left to right and top to bottom: SessionStart fires at CLI launch, UserPromptSubmit on each user message, PreToolUse and PostToolUse wrap every tool call, Notification fires when Claude needs the user, Stop fires when the main agent ends its turn, and SubagentStop fires when a subagent finishes.
Figure: Claude Code Hooks Lifecycle — Session Start to Stop. SVG is open under CC BY 4.0 — credit claude-code-examples.vercel.app.

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

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →