← sources

I tested 10 companies' Claude Code guard hooks against other spellings of the commands they block. What got through, how to check yours, and how to fix it.

source: reddit (reddit:ClaudeCode)published 2026-10-20 16:27ingested 2026-10-21 02:40

retained text

A PreToolUse hook that blocks dangerous commands is one of the most common things teams commit to `.claude/settings.json`: no force push to main, no `rm -rf`, no `git reset --hard`.

This week I ran 10 of them, from company repos, with the exact JSON Claude Code sends, against other spellings of the commands they block. Every one let at least one through.

**What got through most**

- `git -C . push --force origin main` (a git option before the subcommand)
- `git push origin +main` (the `+` is a force push, no `--force` needed)
- `rm -fr /` or `rm -r -f /` (the pattern only knew `-rf`)
- `sh -c '...'` around the blocked command
- one guard exited 1 instead of 2. Claude Code treats that as an error and runs the command, so it never blocked anything.

**Check yours in 10 seconds**

From your repo root, with your hook's path:

    printf '%s' '{"tool_name":"Bash","tool_input":{"command":"git -C . push --force origin main"}}' | .claude/hooks/your-guard.sh; echo "exit $?"

`exit 2` means blocked. Anything else means Claude Code runs it. Try each spelling above the same way.

**How to fix the patterns**

- Block with `exit 2` (or a deny decision on stdout). Exit 1 is a non-blocking error, and the command runs.
- Allow git's own options between `git` and the subcommand: `-C <dir>`, `-c key=value`, `--no-pager`.
- Treat a `+` before the branch as a force push.
- Accept rm's flags in any order and form (`-rf`, `-fr`, `-r -f`, `--recursive --force`), and decide what to do about `find ... -delete`.
- Under `#!/bin/sh`, read the input with `printf '%s'`, not `echo`: on macOS `echo` turns `\r` into a carriage return, and `\rm -rf /` slipped past one guard that way.
- Decide whether to allow `sh -c` / `bash -c` at all, since a pattern can't reliably see inside the quotes.
- Deny rules in settings match the command as written, so `Bash(git push --force*)` doesn't cover `git push origin main --force`. They share the same blind spots.

I've opened issues with tested fixes on the repos that accept them, and I'm not naming anyone here.

Disclosure on the last part: to run all of these at once I built an open-source checker. `uvx paveo test` runs your Claude Code hooks against 41 spellings of 5 dangerous actions and exits 1 when one gets through, so it can run in CI. Nothing leaves your machine. https://github.com/paveo-dev/paveo (Apache-2.0). Tell me which spellings it misses.

document fetched 2026-10-21 00:39 · canonical https://reddit.com/r/ClaudeCode/comments/1xawsfz/i_tested_10_companies_claude_code_guard_hooks