[BUG] Claude Code generates commands with 2>&1 redirects that its own permission patterns cannot match

Resolved 💬 4 comments Opened Mar 21, 2026 by suchapalaver Closed Apr 19, 2026

Bug Description

Claude Code appends 2>&1 to commands it generates (e.g., cargo clippy --all-targets --all-features -- -D warnings 2>&1), but no Bash(...) permission pattern syntax can match commands containing shell redirects. This means users cannot pre-approve commands that Claude Code itself routinely creates.

Reproduction

  1. Add Bash(cargo clippy *) (or Bash(cargo clippy:*), or Bash(cargo:*)) to ~/.claude/settings.json permissions.allow
  2. Ask Claude to run clippy — it generates: cargo clippy --all-targets --all-features -- -D warnings 2>&1
  3. User is prompted for approval despite the allow pattern

Patterns tested (all fail for 2>&1)

| Pattern | Matches bare cargo fmt? | Matches cargo clippy ... 2>&1? |
|---------|--------------------------|----------------------------------|
| Bash(cargo clippy *) | n/a | No |
| Bash(cargo clippy:*) | n/a | No |
| Bash(cargo:*) | No | No |
| Bash(cargo *) | n/a (not tested alone) | No |

Note: Bash(cargo fmt *) does match bare cargo fmt (no redirect), confirming the space-wildcard syntax works for normal arguments but not shell operators.

Expected behavior

Either:

  1. Permission patterns should match commands containing redirects (2>&1, >, >>, 2>/dev/null), OR
  2. Claude Code should not append redirects to commands when the user has pre-approved the base command

Workaround

A PreToolUse hook with regex matching works but is unnecessarily complex for what should be a simple permission rule:

"hooks": {
  "PreToolUse": [{
    "matcher": "Bash",
    "hooks": [{
      "type": "command",
      "command": "jq -r '.tool_input.command // \"\"' | grep -qE '^(SQLX_OFFLINE=true |RUST_LOG=[^ ]+ )*cargo( |$)' && echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"allow\",\"permissionDecisionReason\":\"auto-allowed cargo command\"}}' || true"
    }]
  }]
}

Related issues

  • #29421 (closed/locked) — same root cause with redirects
  • #33340 — piped commands not matching
  • #13154 — feature request for regex support in patterns

Environment

  • Claude Code v2.1.78
  • macOS (Darwin 24.6.0)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗