Points to Note When Using Hooks
Hooks are powerful, but because they always run as mechanism, their failures spread widely too. Four risks are worth understanding before adoption.
1. Infinite Loops
This happens when a hook’s own action satisfies the same hook’s trigger condition.
# A looping setup
Hook: after a file changes, write back the formatted result
→ the write-back counts as "a file change" and fires the hook againThe fix is narrowing the trigger.
- Exclude the hook’s own operations from the trigger
- Cap how many times a hook may fire within one session
- Skip the write-back when nothing actually changed
2. Latency
A hook runs on every tool call. Two seconds per run becomes 200 seconds across a hundred calls.
- Run heavy checks at step boundaries rather than every time
- Narrow the target, checking only files that changed
- Impose a time limit on slow processing
3. Over-Blocking
Adding blocks in the name of safety eventually stops legitimate work. Operators then reach for “just disable the hooks,” and safety ends up lower than before.
| State | Result |
|---|---|
| Blocking too loose | Dangerous operations get through |
| Blocking too strict | The hooks themselves get disabled |
The practical scope for blocking is irreversible operations. Everything else is better served by recording and warning without stopping.
4. Harder Debugging
Because hooks run behind the scenes, an unexpected result is hard to attribute: was it the AI’s judgment or the hook’s intervention?
- Record which hook did what, and when
- When blocking, return the reason to both the AI and the person
- Make it possible to disable a hook temporarily for isolation
Adopt in Order
Adding many hooks at once makes isolation difficult.
- Start with hooks that only record
- Use the real operational data to identify what should be stopped
- Add narrowly targeted blocks
Summary
- A hook whose action meets its own trigger creates an infinite loop
- Because hooks run on every tool call, their cost becomes overall latency
- Over-strict blocking backfires by getting the hooks disabled
- Start with recording, then add blocks only where the data justifies them