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§
- Compact
Result - Result of a pre-compact hook check.
- Post
Compact Context - Context provided to
on_post_compacthooks. - Post
Tool UseContext - Context provided to
on_post_tool_usehooks. - PreCompact
Context - Context provided to
on_pre_compacthooks. - PreTool
UseContext - Context provided to
on_pre_tool_usehooks. - RunEnd
Context - Context provided to
on_run_endhooks. - RunStart
Context - Context provided to
on_run_starthooks.
Enums§
- Compact
Trigger - Why compaction was triggered.
- RunEnd
Reason - Why the run ended.