Permission system doesn't match Claude's natural Bash generation patterns (multi-line scripts, variable-assignment prefixes)

Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Jun 25, 2026 · closed Jun 25, 2026

Summary

Claude Code's permission system evaluates Bash commands by matching the first token of the command string against an allowlist. Claude (the model) routinely generates two shell patterns that break this matching, causing spurious permission prompts even when every constituent command would individually be auto-allowed or is in the project allowlist.

Triggering patterns

1. Multi-line scripts

Claude frequently batches related commands into a single Bash call using newlines:

cd /path/to/project
echo "=== checking ==="
grep -rn "pattern" crates/
cargo test -p my-crate

The permission system sees the first token (cd) and then evaluates the rest as an opaque script block. Even though cd, echo, grep are all auto-allowed, the multi-line structure causes a prompt.

2. Variable-assignment prefixes

Claude uses shell variable assignments to avoid repeating long values:

B=http://localhost:8080/api/v1; curl $B/health; curl $B/accounts

The permission system sees B=http://... as the first token. It doesn't match any allowlist pattern (even Bash(curl *) won't help), so it always prompts.

Expected behavior

One of:

A. Parser-side fix — Walk the compound command AST. For &&-chains, semicolons, and newline-separated statements, check each constituent command independently. A multi-line script is auto-allowed if every statement in it is auto-allowed. A VAR=value; cmd prefix should resolve to cmd as the effective command.

B. Generation-side fix — Update model behavior (system prompt / fine-tuning) so Claude Code sessions default to patterns the permission system can evaluate: &&-chained single-line commands and inlined values instead of shell variable prefixes.

C. Both — Ideal: fix the parser to handle compound forms, and update generation to produce parseable output.

Impact

This causes a high rate of unnecessary prompts during normal development sessions — particularly when working across project directories (the cd /path && ... pattern appears in nearly every multi-step investigation). Users end up either approving dozens of safe operations one by one, or adding an instruction file as a workaround (which is how I discovered this issue).

Current workaround

Adding the following to ~/.claude/CLAUDE.md instructs the model to avoid these patterns:

## Bash command style

Avoid multi-line Bash scripts in a single tool call — use `&&`-chained single-line commands
or separate sequential Bash calls instead.

Avoid shell variable-assignment prefixes as the first token (`B=url; curl $B/...`) —
inline values directly so the permission system can match the actual command.

This works but it's a user-space patch for what is fundamentally a tool-level inconsistency.

Environment

  • Claude Code (claude-opus-4-8)
  • macOS Darwin 24.6.0

View original on GitHub ↗

3 Comments

dbbrandt · 3 months ago

Closing as duplicate. Existing issues cover this more thoroughly:

  • #16561 — Parse compound Bash commands and match each component against permissions (parser-side fix)
  • #58214 — Permission prompts for commands containing key=value arguments (variable-assignment prefix case)
  • #31523 — Compound command blocking and permission UX (broader context)

The workaround I found (adding generation instructions to ~/.claude/CLAUDE.md to avoid multi-line scripts and variable-assignment prefixes) may be useful context for those threads.

github-actions[bot] · 3 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/8581
  2. https://github.com/anthropics/claude-code/issues/28240
  3. https://github.com/anthropics/claude-code/issues/16037

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] · 1 month ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.