types
types ¶
Event ¶
Bases: Flag
Hook lifecycle events that can trigger registered hooks.
Combinable with | to match multiple events in a single hook registration.
Example
hook(Event.Stop | Event.SubagentStop, message="review first", block=True)
Action ¶
Bases: StrEnum
Hook result action determining how the hook output is handled.
block: Prevents the tool use or stops the agent.warn: Adds advisory context without blocking.allow: Explicitly permits the action.
Tool
dataclass
¶
Condition matching the current event's tool name against a regex pattern.
Use in only_if or skip_if to filter hooks by which tool is being used.
Example
hook(Event.PreToolUse, only_if=[Tool("Bash|Execute")], message="...", block=True)
FilePath ¶
Bases: FilePathFields
Condition matching the current event's file path against glob patterns.
Accepts one or more glob patterns as positional arguments.
Example
hook(Event.PostToolUse, only_if=[FilePath(".py", ".pyi")], message="Python file edited")
Command
dataclass
¶
Condition matching the current event's bash command against a regex.
Only relevant for PreToolUse events targeting the Bash/Execute tool.
Example
hook(Event.PreToolUse, only_if=[Command(r"git\s+stash")], message="blocked", block=True)
Content
dataclass
¶
Condition matching the current event's file content against a regex.
Applies to Edit (new content) and Write (file content) tool events.
UsedSkill
dataclass
¶
Transcript-history condition: true when a Skill tool use with a matching name exists.
ReadFile ¶
Bases: ReadFileFields
Transcript-history condition: true when a Read tool use targeted a matching file.
Accepts one or more glob patterns as positional arguments.
TestFile
dataclass
¶
Condition that matches when the current event targets a test file (test_*.py, conftest.py).
Agent
dataclass
¶
Condition matching the current event's subagent type against a name pattern.
TouchedFile ¶
Bases: TouchedFileFields
Transcript-history condition: true when an Edit/Write targeted a file matching the glob.
Accepts one or more glob patterns as positional arguments.
RanCommand
dataclass
¶
Transcript-history condition: true when a Bash tool use with a matching command exists.
InPlanMode
dataclass
¶
Matches when the agent is in plan mode.
Reads permission_mode from the current event payload; falls back to
counting EnterPlanMode vs ExitPlanMode tool uses in the transcript
when the payload omits the field.
ConditionList
dataclass
¶
Container for a tuple of conditions; base class for combinators like Or.
CustomCondition ¶
Bases: Protocol
Protocol for user-defined hook conditions.
Implement check to create arbitrary matching logic beyond the
built-in condition types.
Example
class LargeFile(CustomCondition): ... def check(self, evt: BaseHookEvent) -> bool: ... return bool(evt.file and evt.file.path.stat().st_size > 1_000_000) ... app.hook(Event.PreToolUse, only_if=[LargeFile()], message="Large file", block=True)
Signal
dataclass
¶
A regex-based signal pattern used in the scoring pipeline.
Signals are matched against transcript text via re.search. Each match
contributes weight to the cumulative score. Use negative weights to
suppress false positives.
Example
Signal(pattern=r"retry", weight=2, flags=re.IGNORECASE)
Signals
dataclass
¶
Bundle of signal patterns with a scoring threshold.
When a bare list[Signal] is passed to a primitive, resolve_signals
wraps it with threshold=1 — meaning any single signal match triggers.
Pass a higher threshold to require multiple signals to fire together.
HookResult
dataclass
¶
The return value from a hook handler, specifying the action and optional message.
of
classmethod
¶
Build a HookResult, dedenting and stripping message for readable triple-quoted handler returns.
RegisteredHook
dataclass
¶
RegisteredHook(
*,
spec: HookSpec,
handler: Callable[[BaseHookEvent], HookResult | None]
| None = None,
name: str = "",
source_file: str = "",
)
A registered hook pairing a HookSpec with an optional handler callable.