Manages lifecycle hooks. Hooks are registered per event type and run in registration order.
PreToolUse callback: function(tool_name, tool_input)
Returns list with action:
"allow"– proceed normally"deny"– block execution (add optionalmessage)"updated_input"– replace input withinputfield
PostToolUse callback: function(tool_name, tool_input, tool_output)
Returns list with action:
"allow"– pass output unchanged"updated_output"– replace output withoutputfield
PostToolUseFailure callback: function(tool_name, tool_input, error_message)
Return value ignored (informational only).
PermissionDenied callback: function(tool_name, tool_input, mode)
Return value ignored (informational only).
Methods
HookRegistry$register()
Register a hook for an event.
Arguments
eventCharacter. One of HookEvent values.
fnFunction. Hook callback.
tool_patternCharacter or NULL. Glob filter for tool name (only applies to tool-related events).
timeout_msInteger. Max ms before warning (default 2000).
HookRegistry$run_permission_request()
Fire PermissionRequest hooks. Returns "allow", "deny", or NULL (fall through to ask_fn).
HookRegistry$run_session_start()
Fire SessionStart hooks at the top of a session/turn.
Callback: function(context). Return value ignored.
Usage
HookRegistry$run_session_start(context = list())HookRegistry$run_stop()
Fire Stop hooks when the agent loop terminates.
Callback: function(stop_reason, context). Return value ignored.
Usage
HookRegistry$run_stop(stop_reason = "completed", context = list())HookRegistry$run_pre_compact()
Fire PreCompact hooks before context compaction.
Callback: function(level, context). Return value ignored.
Usage
HookRegistry$run_pre_compact(level = "unknown", context = list())HookRegistry$run_subagent_start()
Fire SubagentStart hooks when a sub-agent is launched.
Callback: function(description, context). Return value ignored.
Usage
HookRegistry$run_subagent_start(description = "", context = list())HookRegistry$run_subagent_stop()
Fire SubagentStop hooks when a sub-agent completes.
Callback: function(description, result, context). Return ignored.
Usage
HookRegistry$run_subagent_stop(
description = "",
result = NULL,
context = list()
)