[Bug] Bash allow rule glob pattern fails to match commands with multiline command substitution containing heredocs

Resolved 💬 3 comments Opened Mar 10, 2026 by gdigora Closed May 4, 2026

Bug Description

### Preflight Checklist

- [x] I have searched existing issues
- [x] I can reproduce this bug

### Environment

- Claude Code: 2.1.72
- Platform: macOS Darwin 25.3.0

### Description

`Bash(gh:*)` in project `.claude/settings.json` auto-approves simple commands like
`gh issue list` but prompts for permission on commands containing `$()`
command substitution with heredocs.

### Steps to Reproduce

1. Add `"Bash(gh:*)"` to `.claude/settings.json` allow list
2. Run: `gh issue list --limit 1` → **auto-approved** ✅
3. Run: `gh issue create --title "test" --body "$(cat <<'EOF'\ntest body\nEOF\n)"` → **permission prompt** ❌

### Expected

Both commands match `Bash(gh:*)` and auto-approve.

### Actual

Command with `$(cat <<'EOF'...)` triggers permission prompt.
Debug log shows `Permission suggestions for Bash: []` — no allow rules matched.

### Debug Evidence

Auto-approved command flow:

PreToolUse → Spawning shell (no permission check)


Prompted command flow:

PreToolUse → Permission suggestions for Bash: [] → executePermissionRequestHooks → Bash tool permission denied


### Root Cause Hypothesis

The permission matcher receives the full command string including the
heredoc content (multi-line). The `*` glob in `Bash(gh:*)` likely doesn't
match across newline characters, so the multi-line expanded command fails
to match even though it starts with `gh`.

### Workaround

Use `--body-file -` with stdin heredoc instead of `--body "$(cat ...)"`:
```bash
gh issue create --title "test" --body-file - <<'EOF'
body here
EOF

This keeps the command single-line and matches the allow rule.

Related

  • #25259 (closed) — heredoc content parsed as permission patterns
  • #11006 (open) — reduce heredoc usage


**Environment Info**
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.71
- Feedback ID: b76eed31-d7d8-4bf6-addf-23f1ac1595ca

**Errors**
```json
[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/digora/.local/share/claude/versions/2.1.71 (expected in multi-process scenarios)\n    at JbA (/$bunfs/root/src/entrypoints/cli.js:2603:2066)\n    at DFL (/$bunfs/root/src/entrypoints/cli.js:2603:1210)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-03-09T22:18:57.867Z"},{"error":"McpError: MCP error -32001: AbortError: The operation was aborted.\n    at O (/$bunfs/root/src/entrypoints/cli.js:53:91496)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:53:91754)\n    at abort (unknown)\n    at ld (/$bunfs/root/src/entrypoints/cli.js:13488:5109)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:13479:5244)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:13747)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3878)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3051)\n    at emit (/$bunfs/root/src/entrypoints/cli.js:594:528)\n    at oS6 (/$bunfs/root/src/entrypoints/cli.js:601:913)","timestamp":"2026-03-09T23:01:58.305Z"},{"error":"McpError: MCP error -32001: AbortError: The operation was aborted.\n    at O (/$bunfs/root/src/entrypoints/cli.js:53:91496)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:53:91754)\n    at abort (unknown)\n    at ld (/$bunfs/root/src/entrypoints/cli.js:13488:5109)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:13479:5244)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:13747)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3878)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3051)\n    at emit (/$bunfs/root/src/entrypoints/cli.js:594:528)\n    at oS6 (/$bunfs/root/src/entrypoints/cli.js:601:913)","timestamp":"2026-03-09T23:02:40.248Z"},{"error":"McpError: MCP error -32001: AbortError: The operation was aborted.\n    at O (/$bunfs/root/src/entrypoints/cli.js:53:91496)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:53:91754)\n    at abort (unknown)\n    at ld (/$bunfs/root/src/entrypoints/cli.js:13488:5109)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:13479:5244)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:13747)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3878)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:608:3051)\n    at emit (/$bunfs/root/src/entrypoints/cli.js:594:528)\n    at oS6 (/$bunfs/root/src/entrypoints/cli.js:601:913)","timestamp":"2026-03-09T23:02:52.635Z"},{"error":"Error: Tool mcp__creativegpt__list_schemas not found\n    at mW1 (/$bunf…

Note: Content was truncated.

View original on GitHub ↗

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