TLDRocket
Sign in

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.

Related stories

The daily briefing

Every AI story that matters, in your inbox by 8am.

TLDRocket reads all relevant sources, removes duplicate coverage, and summarises the day in two minutes. Follow companies and topics for alerts, or get the briefing in Slack. Free, no spam, unsubscribe anytime.