Skip to content
All plugins

bash-prompt-guard

Denies Bash commands Claude Code's permission check cannot parse, so unattended runs do not stall on a prompt.

What it blocks

CommandResult
for f in *(N); do echo $f; doneDenied: zsh-only glob qualifier
rm -f $D/*.pngDenied: suggests "${D:?}"/*.png
grep "[a-z$(]" fileDenied: unclosed $(
grep -F '${size(x)}' fileAllowed: single quotes are not expanded
ls | xargs -n1 echoAllowed

What the agent sees when blocked

Every reason opens with [bash-prompt-guard] and ends with Fix: …. For for f in *(N); do echo $f; done:

text
[bash-prompt-guard] The command uses zsh-only syntax: a parameter flag `${(f)...}`, a modifier `${f:t}` or a glob qualifier `*(N)`. Claude Code parses commands as bash, so it cannot check this one and asks for confirmation ("Dangerous rm operation not ruled out"), even under bypass permissions, which stalls an unattended run. Fix: rewrite it in syntax bash also reads, for example `git diff --name-only --diff-filter=d | xargs pnpm exec eslint --fix` or `while IFS= read -r f; do ...; done < <(cmd)`. For a long sequence, write it to a script file and run `bash <script>` or `zsh <script>`.

Why this plugin

Scenario

Claude Code reads every Bash command as bash. A few command shapes make its permission check ask for confirmation, even under bypass permissions. An unattended session, or a background subagent, then waits on a prompt nobody answers.

Why use it

  • Denying is cheaper than waiting: the agent gets the reason at once and rewrites the command.
  • Every reason says how to rewrite the command (Fix: …).
  • Overnight and background runs keep going.

How it works

A PreToolUse hook on the Bash tool runs scripts/bash-prompt-guard.py before every command and checks it against the shapes below.

ShapeExampleFix the reason suggests
zsh-only syntax: parameter flags, modifiers, glob qualifiers${(f)"$(cmd)"}, ${f:t}, *(N)bash-readable syntax (xargs, while IFS= read -r f; do …; done < <(cmd)) or a script file
rm / rmdir in the same command as a multi-line inline scriptrm -rf a; bash -c '<newline>…'run the removal as its own call with literal paths
rm targets Claude Code treats as critical pathsrm -f $D/*.png, rm -rf "$(cmd)""${D:?}"/*.png; run the substitution first, then remove the literal path
A $( that never closesgrep "[a-z$(]"single quotes, or \$( inside double quotes
A ${ bash does not read as a parameter expansiongrep "frame ${size(x)}"grep -F '…' with single quotes, or \${
A ( … ) subshell after &&, ||, ;, | or a newline inside $(...)c=$(a || (b && c))a { …; } group ($(a || { b && c; })), or separate commands

Text the shell does not expand is ignored: single-quoted strings, backslash escapes, comments and the bodies of quoted heredocs (<<'EOF').

Every error, missing field or non-Bash tool allows the call (exit 0, no output). Commands over 512,000 characters are allowed unchecked, so the scan stays inside the 5 s timeout. No network, no model call.