Skip to main content

Module context

Module context 

Source
Expand description

Hook context types — data passed to hooks at each lifecycle point.

Each context type captures the relevant state for its trigger point. Contexts are read-only snapshots; hooks cannot mutate agent state directly (they return HookAction or CompactResult to influence flow).

§Lifecycle

Every run opens with RunStartContext, then interleaves any number of tool calls (PreToolUse → tool → PostToolUse) and compaction passes (PreCompact → compact → PostCompact), and finally closes with RunEndContext. Every callback receives a context whose fields mirror the moment it fires: pre-contexts carry the about-to-happen inputs, post-contexts carry the what-happened results, and the run contexts bracket the whole run.

Structs§

CompactResult
Result of a pre-compact hook check.
PostCompactContext
Context provided to on_post_compact hooks.
PostToolUseContext
Context provided to on_post_tool_use hooks.
PreCompactContext
Context provided to on_pre_compact hooks.
PreToolUseContext
Context provided to on_pre_tool_use hooks.
RunEndContext
Context provided to on_run_end hooks.
RunStartContext
Context provided to on_run_start hooks.

Enums§

CompactTrigger
Why compaction was triggered.
RunEndReason
Why the run ended.