Hook Trigger Points
Hooks run logic automatically at set points. What becomes possible depends on which point is chosen.
The Common Trigger Points
graph LR
Start["Session start"] --> Before["Before tool execution"]
Before --> Exec["Tool execution"]
Exec --> After["After tool execution"]
After --> Resp["Before the response"]
Resp --> End["Session end"]| Timing | What it enables | Example use |
|---|---|---|
| Session start | Injecting background information | Loading project conventions |
| Before tool execution | Blocking, or requesting approval | Blocking operations against production |
| After tool execution | Verifying, formatting, recording | Running tests after a change |
| Before the response | Inspecting the output | Checking for sensitive information |
| Session end | Wrap-up processing | Saving work logs, clearing temporary files |
To Block, Use Before Execution
The highest-value point is immediately before tool execution. It is the only place where an operation can be prevented from running.
- Abort when the target path falls outside the allowed scope
- Request approval for delete operations
- Stop when a connection to production is detected
Unlike an instruction, a hook operates as mechanism, so it keeps working even deep into long tasks.
To Verify, Use After Execution
Running verification immediately after a change keeps errors from carrying into the next step.
- Run tests or syntax checks after a file changes
- Confirm the output meets conventions
- On failure, return the result to the AI so it corrects course immediately
This is also a way to enforce self-correction as mechanism rather than leaving it to the AI’s judgment.
To Supply Context, Use Session Start
When the same background gets repeated every time, load it automatically at session start: project conventions, terminology rules, and anything that should always apply.
Choose From the Goal
More trigger points is not better. Work backward from the purpose.
| Goal | Point to choose |
|---|---|
| Prevent something dangerous | Before tool execution |
| Confirm the result is correct | After tool execution |
| Keep the baseline consistent | Session start |
| Inspect the output | Before the response |
Summary
- The main points are session start, before and after tool execution, before the response, and session end
- Only the before-execution point can actually prevent an operation
- Verification right after a change enforces self-correction as mechanism
- Choose points from the goal rather than attaching hooks everywhere