claude-code - 💡(How to fix) Fix Permissions: command-level matching instead of string prefix matching [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52409Fetched 2026-04-24 06:07:56
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Root Cause

This does not match git -C /my-project pull because -C /my-project appears before pull. There's no way to reliably deny git push across all flag combinations (git -C /path push, git --no-pager push, etc.).

Code Example

"allow": ["Bash(git pull*)"]

---

"allow": ["Bash(npm test*)"]

---

{
  "permissions": {
    "allow": ["Bash(git *)"],
    "deny": ["Bash(git push*)"]
  }
}
RAW_BUFFERClick to expand / collapse

Problem

Bash permissions currently use string prefix matching. This leads to several issues:

1. Flags/arguments before the subcommand break matching

"allow": ["Bash(git pull*)"]

This does not match git -C /my-project pull because -C /my-project appears before pull. There's no way to reliably deny git push across all flag combinations (git -C /path push, git --no-pager push, etc.).

2. Pipes break matching

"allow": ["Bash(npm test*)"]

Matches npm test | head, but cat foo | npm test would match Bash(cat*) instead. The allowed command is in the pipeline but not at the string prefix position.

3. No effective deny rules

There's no way to express "allow all git subcommands except push" robustly. A deny rule like Bash(git push*) has the same prefix-matching limitation — git -C /path push would bypass it.

Proposed solution

Parse the Bash command semantically instead of string-matching:

  • Identify the base command and subcommands regardless of flag positions
  • Recognize commands in pipes — match against each segment individually
  • Support deny rules with glob or regex patterns that operate on the parsed command

Example

{
  "permissions": {
    "allow": ["Bash(git *)"],
    "deny": ["Bash(git push*)"]
  }
}

Should deny git push, git -C /path push, git --no-pager push origin main, etc.

Use case

Users who want to work with minimal permission prompts (similar to other AI coding tools) but still maintain guardrails for destructive or externally-visible operations like git push, rm -rf, or docker push.

extent analysis

TL;DR

Implement semantic parsing of Bash commands to accurately identify base commands and subcommands, regardless of flag positions, to improve permission matching.

Guidance

  • Identify the base command and subcommands in Bash commands, considering flag positions and pipes, to enhance permission rules.
  • Develop a parsing mechanism to recognize commands within pipes and match them against each segment individually.
  • Introduce support for deny rules using glob or regex patterns that operate on the parsed command, enabling more robust permission control.
  • Test the proposed solution with various command combinations, including flags and pipes, to ensure accurate permission matching.

Example

{
  "permissions": {
    "allow": ["Bash(git *)"],
    "deny": ["Bash(git push*)"]
  }
}

This example demonstrates how the proposed solution can deny git push and its variations while allowing other git subcommands.

Notes

The implementation of semantic parsing may require significant changes to the existing permission system, and its effectiveness depends on the accuracy of the parsing mechanism.

Recommendation

Apply the proposed solution to implement semantic parsing of Bash commands, as it provides a more robust and accurate way to manage permissions, especially for users who require minimal permission prompts while maintaining guardrails for destructive operations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING