Reminders Are Not Always Reliable
An agent may forget to read the project instructions first, or forget to verify its work after editing a file. When it comes to a dangerous Git command, a reminder in the conversation is not always enough. The value of a Hook is that it turns these reminders into working rules with a fixed trigger, a fixed scope, and a fixed response.
Every Hook Answers Four Questions
- Event: When does it fire? For example SessionStart, PreToolUse, PostToolUse, or Stop.
- Matcher: Which cases should it run for? For example only Bash, or only after Edit/Write.
- Handler: What should it check, or what context should it add?
- Stop rule: When should it allow, deny, or hand the decision to a person?
These four parts make automation more predictable. The rule runs whenever it is triggered, instead of hoping the model happens to remember. The matcher narrows the scope so that slow checks do not hold up every action. The stop rule keeps the automation from turning into an endless loop.
Start with a Safe, Narrow Scope
I put together 15 practical scenarios, ranging from correcting project scope and privacy reminders at startup, to intercepting dangerous Git commands before a tool runs, to minimal verification after edits and quality checks on public content. The first thing worth trying is usually not complex auto-repair, but two kinds of narrow Hooks:
- On PreToolUse/Bash, intercept
git reset --hard, force pushes, or destructive cleanup and hand them back for human confirmation. - On Stop, check that any public content changed in this turn keeps its sources, has sensitive data removed, and passes a basic layout check.
A Hook is not about letting the agent do more on its own. It is about making it stop more reliably at the points it must not forget, check its work, or hand the decision back to a person.
Claude Code and Codex Settings Are Not Interchangeable
The two share similar concepts, but their configuration and supported capabilities cannot simply be copied from one to the other. When I implement Hooks, I first check each tool's official documentation, then start with a local command handler that makes no external network calls. Existing settings stay in place; a new Hook is first verified with simulated input, then reviewed and trusted by a person.
Starting with one narrow matcher usually shows the value more clearly than building a whole rule set at once.