ClaudeCode.Hook behaviour (ClaudeCode v0.21.0)
View SourceBehaviour for hook callbacks.
Implement this behaviour in a module, or pass an anonymous function
with the same call/2 signature. Used by both :can_use_tool and
:hooks options.
Return types by event
The return type depends on which event the hook is registered for:
can_use_tool / PreToolUse (permission decisions)
:allow
{:allow, updated_input}
{:allow, updated_input, permissions: [permission_update]}
{:deny, reason}
{:deny, reason, interrupt: true}PostToolUse / PostToolUseFailure (observation only)
:okUserPromptSubmit
:ok
{:reject, reason}Stop / SubagentStop
:ok
{:continue, reason}PreCompact
:ok
{:instructions, custom_instructions}Notification / SubagentStart (observation only)
:ok
Summary
Functions
Invokes a hook callback (module or function) with error protection.