skip to content

Why is a Claude Code deny rule such as `Bash(git push *)` not a security boundary, and which commands does it actually stop?

level: seniorimportance: should knowfreq 14%

answer

  1. it reads text, not intent
  2. split first, then strip wrappers
  3. same program, different spelling
  4. enforcement lives in another layer

basics

~20 s

A Bash rule matches the command text Claude writes, after splitting compound commands and stripping a fixed set of wrappers; it stops git push origin main but not git -C . push, git 'push' or the same push inside sh -c.

solid answer

~50 s

Claude Code splits a compound command on shell operators, strips a fixed list of wrappers such as `timeout`, `nice`, `nohup` and bare `xargs`, and then compares the text with the rule. A deny or ask rule applies when any subcommand matches, including one nested in a subshell, a command substitution or a loop, so `cd app && git push origin main` is stopped. But the rule matches spelling, not the program: `git -C . push origin main`, `git -c push.default=current push`, `git 'push' origin main`, `/usr/bin/curl` against `Bash(curl *)`, or a push inside `sh -c` or a script all pass it. So a Bash deny guards the invocation Claude usually produces. For enforcement that does not depend on the text, use the OS-level sandbox; to inspect the full command with your own logic, a PreToolUse hook; or deny the whole `Bash` tool.

go deeper

for a junior

Recall that a Bash rule matches the command text Claude writes, so the same program written differently may not match.

for a middle

Explain compound-command splitting, the fixed wrapper list and why a wildcard placed before the subcommand over-approves.

for a senior

Name concrete bypass spellings and pair the rule with a text-independent layer such as the sandbox, a PreToolUse hook or a bare Bash deny.

for a principal

Decide where text-matching rules are adequate guard rails and where policy must move to OS isolation or to controls on the remote side.

## What a Bash rule compares A Bash permission rule is a pattern over **command text**. Before matching, Claude Code does two things: 1. **Splits compound commands** on the recognised separators `&&`, `||`, `;`, `|`, `|&`, `&` and newlines, and looks inside subshells, command substitutions and control-flow bodies such as `for` loops. 2. **Strips a fixed set of wrappers** that run their argument as the real command: `timeout`, `time`, `nice`, `nohup`, `stdbuf`, the builtins `command` and `builtin`, zsh's `noglob`, and bare `xargs` without flags. A deny or ask rule also matches past any leading variable assignment, so `FOO=bar rm -rf tmp/` still matches `Bash(rm *)`. The rule is then compared with what is left. That is useful and fast, but it is a comparison of strings, not an understanding of what the program will do. ## What `Bash(git push *)` stops | Command | Stopped? | Why | | :- | :- | :- | | `git push origin main` | Yes | direct match | | `cd app && git push origin main` | Yes | the compound is split; one part matches | | `echo "$(git push)"` | Yes | substitutions are inspected | | `timeout 60 git push origin main` | Yes | `timeout` is stripped first | | `git -C . push origin main` | **No** | `-C .` sits before the subcommand | | `git -c push.default=current push origin main` | **No** | `-c` option before the subcommand | | `git 'push' origin main` | **No** | quoted subcommand changes the text | The documentation's own examples make the same point for other programs: `Bash(curl *)` does not stop `/usr/bin/curl https://example.com` or `sh -c 'curl https://example.com'`, and `Bash(rm *)` does not stop `/bin/rm -rf build/` or `bash -c 'rm -rf build/'`. A script file that pushes, or an environment runner like `devbox run` or `npx` wrapping the command, is equally invisible to the pattern. What happens to those unmatched forms is decided by your other rules and the permission mode. ## The allow side has the mirror problem On the allow side, the danger is approving more than you meant: - **Wildcard before the subcommand.** `Bash(git * main)` matches `git push origin main` and even `git -c core.fsmonitor=<script> diff main`, where `-c` makes git run a program you name. Claude Code warns at startup about an allow rule with a `*` before the subcommand. - **Environment runners are not stripped.** `Bash(devbox run *)` approves whatever follows `run`, including `devbox run rm -rf .`. Write one rule per inner command instead, such as `Bash(devbox run npm test)`. - **Exec wrappers resist prefixes.** `watch`, `setsid`, `ionice`, `flock` and `find` with `-exec` or `-delete` cannot be auto-approved by a prefix rule and prompt in Manual mode. The documentation also calls argument-constraining patterns such as `Bash(curl http://github.com/ *)` fragile: options before the URL, another protocol, a redirect or a variable each slips past. ## What to use when the restriction must hold A Bash deny is a guard rail for the common spelling, and that is still worth having. When the rule must actually hold, pair it with a layer that does not depend on text: - **The sandbox**, Claude Code's OS-level filesystem and network isolation for shell commands and their child processes, covered in its own topic. - **A PreToolUse hook**, which sees the full command and can apply your own parsing before the call runs. - **A bare `Bash` deny**, which removes the tool from Claude's context when shell access is not needed at all. - **Controls outside the machine**, such as protected branches on the remote, for actions like pushing where the real authority is elsewhere. ## How to read a Bash rule in review 1. Find the first `*`: every word before it is what actually limits the rule. 2. Ask which other spellings reach the same program: an absolute path, an option before the subcommand, quoting, `sh -c`, a script or an environment runner. 3. Decide whether a miss matters. If it would, the rule is a convenience, and the protection must come from another layer. ## Why the question is asked It separates a candidate who has read the rule grammar from one who has thought about bypasses. A good answer credits what the matcher does well (splitting, wrapper stripping, substitutions) and then names concrete spellings that pass, instead of either trusting the rule completely or dismissing it as useless.

  • Why does `cd /tmp && git clean -f` still prompt when `Bash(git clean *)` is an ask rule?
    Claude Code splits compound commands on `&&`, `||`, `;`, pipes, `&` and newlines, and a deny or ask rule applies when any subcommand matches, including inside subshells, command substitutions and loops. `git clean -f` is one subcommand, so the ask rule fires; the documentation notes it prompts even in auto mode.
  • How should you approve `npm test` that runs through `devbox run`?
    Write an exact rule for the combination, `Bash(devbox run npm test)`, and one rule per inner command you want. Environment runners such as `devbox run`, `npx` and `docker exec` are not on the wrapper list, so `Bash(devbox run *)` would approve anything after `run`, including a destructive command.

A Bash deny rule is a bouncer checking names against a list: it reliably stops the guest who gives the listed name, even in a group, but not the same person arriving under a different spelling.

  • Bash(git push *) in deny makes pushing impossible for Claude
  • Chaining with && is enough to slip past a Bash deny rule
  • Bash(git * main) only allows harmless commands on the main branch
  • Denying curl and wget in Bash blocks all outbound network access
  • Wrappers like timeout let a command evade a Bash deny rule