Don't rely on instructions, use Agent Hooks to enforce guardrails
TLDR
Devs writing AGENTS.md/CLAUDE.md rules for coding agents can now enforce them with Agent Hooks instead of hoping the AI listens. Hooks block bad actions before they happen and stop agents from declaring "done" when tests are red — no more ignored instructions.
Anyone who's spent time steering Claude Code or a similar coding agent knows the drill: you write a firm instruction in CLAUDE.md, the agent nods along, and then two turns later it does the exact thing you told it not to do. A developer writing on TLDR this week has a fix that doesn't rely on the agent's good behavior at all — Agent Hooks, which let you intercept the agent mid-workflow rather than catching mistakes after the fact.
The key distinction is timing. A git pre-commit hook, the kind most developers already use for formatting or linting, fires right before a commit — which means the flawed code has already been written, reviewed in your head, and is basically ready to ship. Agent hooks fire while the agent is still working. Claude Code, for instance, exposes a PreToolUse hook that runs right before any tool call, and a Stop hook that runs the instant the agent thinks it's finished. Both give you a chance to say no before the damage is committed to disk or the conversation ends.
The author's first example blocks the agent from ever writing a raw <input> tag, insisting on a custom <.cinput> component instead. The hook pipes the tool's JSON payload through jq, checks the content or new_string field (depending on whether it's a Write or an Edit), and if it spots the banned tag, exits with code 2 — which Claude Code treats as a hard stop, feeding the stderr message back to the agent as a correction. That distinction matters: exit 1 just logs a warning and lets the write through, while exit 2 actually kills it.
The second example is trickier and arguably more useful. The author keeps a
My take
This is the most practical piece I've read on agent reliability in a while, mostly because it admits the obvious thing everyone dances around: natural-language instructions to LLM agents are suggestions, not contracts, no matter how many capital letters you use. Treating an agent like unpredictable infrastructure — with real exit codes and real gates — is the only sane way to build on top of it, and I'd bet this pattern becomes standard practice long before anyone fixes instruction-following at the model level.
Read more about this at: TLDR