Skip to content

Examples

Each page picks one capability of the framework, frames it as a problem you've actually hit, and links to a self-contained docs/examples/*.py file you can drop into your hooks directory. Every example file ships with inline tests = {...} you can run via capt-hook --hooks docs/examples test.

Example Teaches
Audit Logging JSONL audit log with custom fields and hourly rotation.
Code Quality Layered detection: regex hook → AST lint → signal nudgellm_gate.
Command Safety block_command plus evt.command_line.q.* for AST-level command predicates.
Custom Condition The CustomCondition protocol for project-specific predicates.
Failure Recovery Signal-driven Stop nudge that points at debug tools when failures repeat.
Multi-Step Workflow workflow / Step / Artifact enforcing a checklist before SubagentStop.
Session Workflow @workflow_state group spanning PreToolUse, UserPromptSubmit, and Stop.
Settings Config HooksSettings subclass plus a sibling hook that reads evt.ctx.c.*.
Test Integrity prompt_check with Prompt.from_template detecting weakened tests.