claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Allow Permission Mode Switching in PermissionRequest Hooks

Open vikvorona opened this issue 11 months ago • 2 comments

Feature Request: Allow Permission Mode Switching in PermissionRequest Hooks

Summary

Add ability to programmatically switch Claude CLI permission modes when responding to PermissionRequest hooks.

Problem Statement

Currently, there's no way to programmatically control the session's permission mode from hooks. The permission_mode field in hook input is read-only, and there's no API to change it.

Current behavior: When approving a permission request via a PermissionRequest hook, Claude remains in its current permission mode. There's no way to replicate the native approval prompt options like "Yes, accept all edits" (switch to acceptEdits) vs "Yes" (stay in current mode).

Desired behavior: Allow hook responses to optionally switch permission modes when approving permission requests.

Use Case

When building external approval workflows for any PermissionRequest (not just ExitPlanMode), it would be valuable to programmatically control the permission mode. This enables emulating the native approval prompt options:

In Plan Mode (ExitPlanMode approval):

  1. "Yes, accept all edits" - Approve and switch to acceptEdits mode
  2. "Yes" - Approve and switch to default mode

In Default Mode (general tool approvals):

  1. "Yes, allow all edits during this session" - Approve and switch to acceptEdits mode
  2. "Yes" - Approve and stay in default mode

This would enable external tools to offer the same flexibility that exists in the native Claude Code interactive approval prompts.

Proposed Solution

Option 1: Add switchToMode Field in Hook Response

Allow hooks to request a permission mode switch in the decision response:

{
  "hookSpecificOutput": {
    "hookEventName": "PermissionRequest",
    "decision": {
      "behavior": "allow",
      "switchToMode": "acceptEdits"
    }
  }
}

Valid values: "default", "plan", "acceptEdits", "bypassPermissions" (or null to leave unchanged)

Option 2: Add permission_mode to Tool Input

Instead of permission_mode being session-level metadata only, include it as a modifiable field in tool_input. This would allow hooks to change the mode via updatedInput:

Current structure:

{
  "session_id": "...",
  "permission_mode": "plan",  // Read-only, not in tool_input
  "tool_name": "ExitPlanMode",
  "tool_input": {
    "plan": "..."
  }
}

Proposed structure:

{
  "session_id": "...",
  "tool_name": "ExitPlanMode",
  "tool_input": {
    "plan": "...",
    "permission_mode": "plan"  // Now modifiable via updatedInput
  }
}

Hook response:

{
  "hookSpecificOutput": {
    "hookEventName": "PermissionRequest",
    "decision": {
      "behavior": "allow",
      "updatedInput": {
        "permission_mode": "acceptEdits"
      }
    }
  }
}

Example Hook Implementation

Using Option 1 (switchToMode):

#!/bin/bash
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
CURRENT_MODE=$(echo "$INPUT" | jq -r '.permission_mode')

# External logic determines user's approval preference
DESIRED_MODE=$(get_user_approval_preference "$TOOL_NAME" "$CURRENT_MODE")

if [[ "$DESIRED_MODE" == "current" ]]; then
  echo '{"hookSpecificOutput":{"hookEventName":"PermissionRequest","decision":{"behavior":"allow"}}}'
else
  echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PermissionRequest\",\"decision\":{\"behavior\":\"allow\",\"switchToMode\":\"$DESIRED_MODE\"}}}"
fi

Using Option 2 (updatedInput):

#!/bin/bash
INPUT=$(cat)
DESIRED_MODE=$(get_user_approval_preference)

echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PermissionRequest\",\"decision\":{\"behavior\":\"allow\",\"updatedInput\":{\"permission_mode\":\"$DESIRED_MODE\"}}}}"

Benefits

  • Enables external automation tools to fully replicate native approval UX
  • Works for all permission requests, not just specific tools
  • Consistent with existing hook decision structure (Option 1) or existing updatedInput pattern (Option 2)
  • No breaking changes - feature is opt-in
  • Provides parity with native interactive approval prompts

Additional Context

  • Platform: macOS (but issue affects all platforms)
  • Related keyboard shortcut: Shift+Tab cycles modes interactively, but there's no programmatic equivalent
  • This applies to all PermissionRequest hooks, not just ExitPlanMode

vikvorona avatar Dec 15 '25 13:12 vikvorona

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/6227
  2. https://github.com/anthropics/claude-code/issues/11825
  3. https://github.com/anthropics/claude-code/issues/3389

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

github-actions[bot] avatar Dec 15 '25 13:12 github-actions[bot]

In case someone lands here and wants this, I'm using a workaround by pressing keystrokes when the hook approves (in my case ExitPlanMode). Hope this helps: https://gist.github.com/tomsiwik/db577114972300928bb40359e17a492e

tomsiwik avatar Jan 09 '26 11:01 tomsiwik

This feature would also be valuable for Stop hooks.

Use case: When using auto-accept edits mode for a task, automatically return to normal mode when Claude finishes (Stop event fires). This prevents unintended auto-accepts on subsequent interactions.

Currently there's no way to programmatically exit auto-accept mode - users must manually press Shift+Tab. A switchToMode field in Stop hook responses would solve this.

chrisbeardy avatar Jan 20 '26 15:01 chrisbeardy

+1 on this — being able to switch back to dontAsk mid-session without restarting would be a huge qol win

NerdyMihir avatar Jan 31 '26 06:01 NerdyMihir

Please implement this

cdr-x avatar Mar 01 '26 02:03 cdr-x

YES PLEASE!

On CC 2.1.73, they have since broken this feature, and now Mr. Claude refuses to exit Plan mode after prompting the user to agree, clear context, and execute. This worked up until 2.1.71, and started slowly breaking, and then... refused to work 2.1.72+ onwards.

Maybe they should open-source the tool, or something, to avoid their own development team from absolutely breaking changes.

xsyetopz avatar Mar 11 '26 21:03 xsyetopz

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

github-actions[bot] avatar Apr 09 '26 10:04 github-actions[bot]

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.

github-actions[bot] avatar Apr 17 '26 14:04 github-actions[bot]