
What happened
In a real Claude Code 2.1.304 session, a PreToolUse hook script blocked 'rm -rf build' with exit code 2, but 'rm -fr build' ran and deleted the folder, and the author lists many bypasses such as 'rm -r -f' and 'find build -delete'.
Why it matters
The hook only pattern-matches command strings, so it works as an early net for common dangerous forms rather than a sandbox; the author says to pair it with permission settings and pre-work git commits.
Summaries like this, in your inbox every morning.
The test was run in a disposable folder with claude -p, the non-interactive mode, and with --dangerously-skip-permissions so that per-command approvals would not interfere; the author explicitly warns not to use that option in normal work. Even with approvals skipped, the hook returning exit code 2 stopped the command, and the error text was passed back to Claude. The author also tested the script standalone by feeding it JSON in the same shape Claude Code provides. That standalone run showed 'git push --force origin main' and 'git reset --hard HEAD~3' were stopped, while 'rm -fr build' and 'rm -r -f build' passed; the latter two were not tried in a live session.
The script depends on jq to read the command, and the author shows why the 'command -v jq' line matters. Without it, an environment missing jq would read nothing and exit 0, letting everything through — and because the exit code is 0, onFailure would not treat it as a failure. Removing jq from PATH in a real session, the version with the check blocked even 'ls build' with a 'jq is required' message, while the version without it let 'rm -rf build' delete the folder.
The onFailure setting was introduced in version 2.1.295, and in 2.1.294 a wrong script path did not stop the command. The author tested only the missing-script case and notes that the documentation also counts non-0/2 exit codes, timeouts, and unreadable JSON output as failures. The closing advice is to use permission settings for commands that must be blocked reliably, keep the hook as an early net, and confirm behavior in a dummy folder before trusting it.
Pick your industry and the AI tools you use, and get news related to your work every day.
Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →
Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.
Researchers ran 91 decoy US accounts across three income levels and three racial groups; ads began appearing a…

Microsoft said its Project Perception cybersecurity system, announced in July 2026, will be extended to monito…

On 40 Japanese tasks judged blind by GPT, Sarashina3 mini kept meaning in only 1 of 10 rewrite prompts, versus…

In the latest Zenn series installment, the author added SVG toolbar icons to a Qt/QML image viewer by listing…

tanashun rebuilt tanacode 2.0.0's chat mechanism from terminal screen-scraping to stream-json, completing the…

Claude Code 2.1.303 shipped with a changelog that lists no individual fixes, describing the release only as 'b…
