Don't rely on instructions, use Agent Hooks to enforce guardrails
Zarar's blog 4 months ago 29
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.