Skip to content

Hooks Overview

New here? Start with GettingStarted/first-hook.md to create a working hook in under 10 minutes. Once your first hook is working, sections 1-3 below cover everything you need. Skip sections 4 (Matcher semantics), 5 (Scope & configuration), 6 (Security model), and 7 (Additional subsystems) until you need them.

Reference for Claude Code’s event hook system — lifecycle events, handler types (command / http / prompt / agent), matcher syntax, and security model. Configure in settings.json or in skill/agent frontmatter.

  1. How event hooks work
  2. Event reference
  3. Handler types
  4. Matcher semantics
  5. Scope & configuration
  6. Security model
  7. Additional hook subsystems (internal)
  8. Discrepancies & notes

8 sections, ~34 entries — 26 events across 8 categories + 4 handler types.

#SectionDescriptionEntries
1How event hooks workLifecycle events, handler types, matchers, scope precedence, SSRF protection, and Stop→SubagentStop auto-conversion.narrative
2Event referenceAll 26 hook events grouped by category — Session Lifecycle, User Input, Tool Use, Sub-Agents, Tasks, Environment Changes, Compaction, Elicitation.26 events / 8 categories
3Handler typesThe four handler types — command, http, prompt, agent — with config fields, behavior, security, and YAML examples.4 entries
4Matcher semanticsHow matcher fields filter events per category — regex for tools, glob for files, exact name for agents/config.narrative
5Scope & configurationCross-links to settings.json hooks key, skill/agent frontmatter hooks: field, plugin hooks, and managed-only keys.narrative
6Security modelSSRF guard (blocks RFC1918, link-local, cloud metadata), env-var allowlist, shell-execution gate, managed lockdown, timeouts.narrative
7Additional hook subsystems (internal)Hedged references to internal hook machinery files NOT inspected — registry, config manager, file-watcher, post-sampling hooks.narrative
8Discrepancies & notesUndocumented handler fields (statusMessage, once, if, shell, asyncRewake), matcher variations, decision precedence, SSRF edge cases.narrative
EventFires whenMatcher?Blockable?Handler typesScope
Session Lifecycle
SessionStartSession begins or resumesNoNocommand, prompt, agentsettings, skill, agent, plugin
InstructionsLoadedCLAUDE.md or rules file loadsNoNocommand, prompt, agentsettings, skill, agent, plugin
NotificationClaude sends a notificationNoNocommand, prompt, agent, httpsettings, skill, agent, plugin
StopClaude finishes respondingNoYescommand, prompt, agentsettings, skill, agent, plugin
StopFailureTurn ends due to API errorNoNocommand, prompt, agentsettings, skill, agent, plugin
SessionEndSession terminates or times outNoNocommand, prompt, agentsettings, skill, agent, plugin
User Input
UserPromptSubmitBefore Claude processes user promptNoYes (block only)command, prompt, agentsettings, skill, agent, plugin
Tool Use
PreToolUseBefore tool executiontool nameYes (approve/block)command, prompt, agent, httpsettings, skill, agent, plugin
PermissionRequestPermission dialog appearstool name / ruleYes (allow/deny)command, prompt, agent, httpsettings, skill, agent, plugin
PermissionDeniedAuto mode denies a tool calltool nameNocommand, prompt, agentsettings, skill, agent, plugin
PostToolUseAfter tool succeedstool nameYescommand, prompt, agent, httpsettings, skill, agent, plugin
PostToolUseFailureAfter tool failstool nameNocommand, prompt, agent, httpsettings, skill, agent, plugin
Sub-agents & Team
SubagentStartSubagent spawnedagent typeNocommand, prompt, agent, httpsettings, skill, agent, plugin
SubagentStopSubagent finishesagent typeYescommand, prompt, agent, httpsettings, skill, agent, plugin
TeammateIdleAgent team teammate goes idleagent typeYescommand, prompt, agent, httpsettings, skill, agent, plugin
Tasks
TaskCreatedTask created via TaskCreateNoYescommand, prompt, agentsettings, skill, agent, plugin
TaskCompletedTask marked completeNoYescommand, prompt, agentsettings, skill, agent, plugin
Environment & Files
ConfigChangeConfig file (settings.json, CLAUDE.md) changesconfig keyNocommand, prompt, agentsettings, skill, agent, plugin
CwdChangedWorking directory changesNoNocommand, prompt, agentsettings, skill, agent, plugin
FileChangedWatched file changesfile globNocommand, prompt, agentsettings, skill, agent, plugin
WorktreeCreateWorktree createdNoYescommand, prompt, agentsettings, skill, agent, plugin
WorktreeRemoveWorktree removedNoYescommand, prompt, agentsettings, skill, agent, plugin
Context Management
PreCompactBefore context compactionNoNocommand, prompt, agentsettings, skill, agent, plugin
PostCompactAfter compaction completesNoNocommand, prompt, agentsettings, skill, agent, plugin
MCP & Elicitation
ElicitationMCP server requests user inputNoNocommand, prompt, agentsettings, skill, agent, plugin
ElicitationResultUser responds to MCP elicitationNoNocommand, prompt, agentsettings, skill, agent, plugin