Feature Request: Allow Permission Mode Switching in PermissionRequest Hooks
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):
- "Yes, accept all edits" - Approve and switch to
acceptEditsmode - "Yes" - Approve and switch to
defaultmode
In Default Mode (general tool approvals):
- "Yes, allow all edits during this session" - Approve and switch to
acceptEditsmode - "Yes" - Approve and stay in
defaultmode
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
updatedInputpattern (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+Tabcycles modes interactively, but there's no programmatic equivalent - This applies to all
PermissionRequesthooks, not justExitPlanMode
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/6227
- https://github.com/anthropics/claude-code/issues/11825
- 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
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
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.
+1 on this — being able to switch back to dontAsk mid-session without restarting would be a huge qol win
Please implement this
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.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.