Skip to main content

Module hooks

Module hooks 

Source
Expand description

Hook callbacks - 10 hook kinds dispatched by opaque callback_id.

SDK’s HookMatcher / HookContext machinery. Callbacks are registered at initialize time; the CLI emits hook_callback control_requests with an opaque callback_id (minted by the SDK) plus an input payload whose hook_event_name discriminates concrete types.

Wire-shape data (HookKind, HookContext, all *Input/*Output structs) lives in forge-primitives, re-exported here. The callback machinery (HookCallback trait, ErasedHookCallback, Hooks/HooksBuilder registry) stays SDK-side.

Re-exports§

pub use callback::ErasedHookCallback;
pub use callback::HookCallback;
pub use callback::HookDecision;
pub use registry::Hooks;
pub use registry::HooksBuilder;

Modules§

callback
Hook callback trait + decision type + type-erasure plumbing.
registry
Hook registry - stores callbacks, mints opaque callback_ids, and renders the hooks field of the initialize control_request payload.

Structs§

BaseHookInput
Fields shared by every hook input the CLI emits. Every concrete input type below flattens this struct so callbacks can access session_id, transcript_path, cwd, and (optionally) permission_mode without reaching back into super::HookContext.
HookContext
Context carried alongside every hook invocation.
NotificationInput
Input payload for Notification.
PermissionRequestInput
Input payload for PermissionRequest.
PostToolUseFailureInput
Input payload for PostToolUseFailure.
PostToolUseInput
Input payload for PostToolUse.
PreCompactInput
Input payload for PreCompact.
PreToolUseHookSpecificOutput
hookSpecificOutput shape for PreToolUse hook responses.
PreToolUseInput
Input payload for PreToolUse.
StopInput
Input payload for Stop.
SubagentContext
Optional sub-agent attribution present on tool-lifecycle hook inputs (PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest). Fields are populated when the hook fires inside a Task-spawned sub-agent so tool events can be attributed back to the right agent when multiple sub-agents interleave over the same control channel.
SubagentStartInput
Input payload for SubagentStart.
SubagentStopInput
Input payload for SubagentStop.
UserPromptSubmitHookSpecificOutput
hookSpecificOutput shape for UserPromptSubmit.
UserPromptSubmitInput
Input payload for UserPromptSubmit.

Enums§

HookKind
Identifies which hook point a callback is registered for. Sixteen event kinds mirrored from the CLI v0.1.64, plus Unknown as a fallback for forward-compatibility.