Don't rely on instructions, use Agent Hooks to enforce guardrails
Zarar's blog
A developer describes using Agent Hooks in Claude Code to enforce guardrails on agent-generated code, explaining two specific use cases: blocking raw HTML input tags via a PreToolUse hook and preventing the agent from finishing until a design-system test passes via a Stop hook. Agent Hooks intercept the agent's workflow at specific points—before tool execution and when declaring completion—by running shell commands against JSON payloads, unlike instruction-based guardrails in CLAUDE.md that agents frequently ignore. This approach provides deterministic enforcement compared to post-hoc checks like linting or git hooks that run after code generation is already complete.
Why it matters
Agent Hooks allow developers to interject themselves into an agent's workflow while it's working rather than after, enabling deterministic checks that work 100% of the time by preventing agents from ignoring rules and failing tests.