[BUG] Permission pattern matching fails when quoted argument starts with hyphen (e.g., "-1h")
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Bug Report: Permission Pattern Matching Fails with Hyphen-Prefixed Quoted Arguments
Summary
Bash permission patterns using :* wildcard suffix fail to match commands when an argument is a quoted string starting with a hyphen (e.g., "-1h").
Environment
- Claude Code version: 2.0.76
- OS: macOS (Darwin 24.6.0)
- Architecture: arm64
Steps to Reproduce
- Add a permission pattern to
settings.json:
``json``
{
"permissions": {
"allow": ["Bash(mycli search:*)"]
}
}
- Test commands:
```bash
# These work (no permission prompt):
mycli search --query "test"
mycli search --start 1h
mycli search --start -1h # unquoted hyphen-prefixed arg
mycli search --start "1h" # quoted, no hyphen
# This prompts for permission (pattern fails to match):
mycli search --start "-1h" # quoted hyphen-prefixed arg
```
Expected Behavior
Bash(mycli search:*) should match any command starting with mycli search, regardless of whether arguments contain quoted strings with leading hyphens.
Actual Behavior
The permission pattern fails to match when any argument is a quoted string starting with -. The command prompts for permission instead of being auto-allowed.
Minimal Reproduction
| Command | Pattern Matches? |
|---------|-----------------|
| mycli search --flag "value" | ✓ Yes |
| mycli search --flag "1h" | ✓ Yes |
| mycli search --flag -1h | ✓ Yes |
| mycli search --flag "-1h" | ✗ No |
| mycli search --flag "-value" | ✗ No |
Key finding: The only difference between working and broken:
--flag "1h"→ ✓ works--flag "-1h"→ ✗ breaks
Analysis
The pattern matcher appears to interpret "-1h" as a potential flag/option because it starts with -, even though it's enclosed in quotes and is a value, not a flag.
Impact
This affects any CLI tool that uses relative time arguments (e.g., -1h, -30m, -7d) or negative numbers as values. Users must either:
- Avoid quoting these arguments (when shell allows)
- Manually approve each command
Suggested Fix
The permission pattern matcher should properly handle quoted strings and not interpret their contents as flags, regardless of whether they start with -.
What Should Happen?
The permission pattern Bash(mycli search:*) should match the command mycli search --start "-1h" and auto-allow it without prompting, just like it matches mycli search --start "1h".
Error Messages/Logs
No error message is displayed. The behavior difference is:
With permission `Bash(mycli search:*)` configured:
# Command WITHOUT hyphen in quoted arg - AUTO-ALLOWED ✓
$ mycli search --start "1h"
[command executes without permission prompt]
# Command WITH hyphen in quoted arg - PROMPTS FOR PERMISSION ✗
$ mycli search --start "-1h"
[Claude Code shows permission prompt asking user to approve]
The pattern should match both commands identically since they both start with "mycli search".
Steps to Reproduce
- Add permission to
~/.claude/settings.jsonor.claude/settings.local.json:
``json``
{
"permissions": {
"allow": ["Bash(mycli search:*)"]
}
}
- Ask Claude Code to run command with quoted arg WITHOUT hyphen:
``bash``
mycli search --start "1h"
✓ Auto-allowed (no prompt)
- Ask Claude Code to run command with quoted arg WITH hyphen:
``bash``
mycli search --start "-1h"
✗ Prompts for permission (should be auto-allowed)
- Additional test cases that work:
``bash``
mycli search --flag "value" # ✓ works
mycli search --flag -1h # ✓ works (unquoted)
mycli search --flag "1h" # ✓ works
- Test cases that fail:
``bash``
mycli search --flag "-1h" # ✗ prompts
mycli search --flag "-value" # ✗ prompts
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.76 (Claude Code)
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
Other
Additional Information
Terminal: Use WezTerm
The bug appears to be in the permission pattern parser interpreting "-1h" as a potential flag/option because it starts with a hyphen -, even though it's enclosed in quotes and is a value argument, not a flag.
Real-world impact: This affects any CLI tool that uses:
- Relative time formats:
-1h,-30m,-7d,-24h - Negative numbers as values:
--offset "-5",--delta "-100" - Options that happen to start with hyphen:
--format "-json"
Workaround: Users can avoid quoting arguments that start with - when the shell allows it:
mycli search --start -1h # works (unquoted)
mycli search --start "-1h" # fails (quoted)
However, this workaround isn't always possible when the argument contains spaces or special characters that require quoting.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗