Tarun Agarwal has released a suite of five bash scripts for Claude Code that shift the burden of correctness from prompt engineering to system-level enforcement. The core thesis is simple but provocative: instructions in CLAUDE.md drift, but exit codes do not. By leveraging Claude Code’s hook system, Agarwal demonstrates how to prevent the agent from declaring victory prematurely or executing irreversible commands.
The Veto Power of Exit Codes
The hook system operates on a binary logic: exit 0 allows the action, while exit 2 blocks it and returns stderr to the model. Agarwal’s first script acts as a dangerous-command blocker using PreToolUse. It parses the command string via jq and uses regex to catch high-risk operations like git push --force, rm -rf /, and SQL DROP statements. In a live test, when the agent attempted a force push, the hook blocked it, and Claude Code correctly pivoted to suggesting --force-with-lease rather than trying to bypass the restriction.
Enforcing 'Done' via Test Suites
The most critical hook is the Stop event handler, which challenges the agent’s self-assessment of completion. Instead of trusting Claude’s claim that a task is finished, the hook executes the project’s test suite. If tests fail, the script exits with code 2, injecting the failure output back into the context and forcing the agent to continue working. Agarwal’s script includes a counter to prevent infinite loops, capping attempts at three per session before yielding control to the human user. This mechanism ensures that 'done' is defined by passing tests, not by the model’s confidence interval.
Context Injection and Audit Logs
Beyond blocking, the hooks enhance situational awareness. A SessionStart hook injects the current git branch, recent commits, and uncommitted files directly into the context window, reducing the need for the agent to run discovery commands. Meanwhile, PostToolUse hooks append every executed bash command to a JSON log, creating an audit trail that excludes blocked commands. A Notification hook also alerts the user when the agent is stuck waiting for permission, preventing idle time during long sessions.
Key Takeaways
- Hooks provide a deterministic veto power that prompts cannot match, ensuring safety checks are never skipped due to context window limits.
- The
Stophook effectively decouples task completion from model self-evaluation, enforcing objective pass/fail criteria. - Agarwal’s implementation includes safeguards like attempt counters and clean-tree checks to prevent infinite loops and unnecessary latency.
- The scripts are tested against Claude Code 2.1.319 on Linux, with a focus on bash, jq, and git integration.
The Bottom Line
Prompt engineering is fragile; system-level enforcement is robust. Agarwal’s hooks prove that the future of reliable AI coding agents lies not in better instructions, but in stricter gates.