Skip to content

fix(claude): apply mid-turn permission mode changes to canCallTool#764

Merged
tiann merged 1 commit into
tiann:mainfrom
swear01:fix/claude-mid-turn-permission-mode-735
Jun 1, 2026
Merged

fix(claude): apply mid-turn permission mode changes to canCallTool#764
tiann merged 1 commit into
tiann:mainfrom
swear01:fix/claude-mid-turn-permission-mode-735

Conversation

@swear01
Copy link
Copy Markdown
Contributor

@swear01 swear01 commented Jun 1, 2026

Summary

PermissionHandler stored its own permissionMode field and only updated it inside handleModeChange, which fires when a new batch is pulled from the queue. The SetSessionConfig RPC (web dropdown changes) updates runClaude.ts's currentPermissionMode and the session keepalive metadata, but never reaches the handler — so switching from default to Yolo while a turn was in progress left canCallTool checking the stale mode and still prompting for approval.

Drop the stored field and read live from session.getPermissionMode(), mirroring how the OpenCode permission handler already works. Override Session.getPermissionMode() in claude/session.ts to return the Claude-narrow PermissionMode, which is sound because the matching setPermissionMode setter only accepts that subset, so the field cannot hold a foreign flavor value.

Closes #735.

Why #735 triggers this

In #735's repro:

  1. Plan finishes → exit_plan_mode approval card
  2. User clicks 確定 without picking a mode (web has no mode selector here — that's Web UI: exit-plan-mode approval lacks permission mode and implementation mode options #444)
  3. Handler unshifts PLAN_FAKE_RESTART with permissionMode: 'default' and Claude restarts a new turn under default
  4. User now manually switches to Yolo via the dropdown — RPC updates session/metadata but not the handler
  5. Every subsequent tool call in the fake-restart turn still pops an approval card

After this fix step 5 auto-approves as expected.

Disclosure

Vibe-coded with Claude Opus 4.7 (via HAPI).

Test plan

  • bun typecheck passes
  • bun run test src/claude — 95/95 pass including new regression test
  • Manual: isolated hub + runner, ran the plan模式结束后,切换到yolo模式不生效 #735 repro on fix/claude-mid-turn-permission-mode-735 source — switching to Yolo mid-turn after exit_plan_mode now auto-approves subsequent tool calls; before the fix the same flow kept prompting

🤖 Generated with Claude Code

`PermissionHandler` stored its own `permissionMode` field and only updated
it inside `handleModeChange`, which is called when a new batch is pulled
from the queue. The `SetSessionConfig` RPC (web dropdown changes) updates
`runClaude.ts`'s `currentPermissionMode` and the session keepalive
metadata, but never reaches the handler — so switching to Yolo mid-turn
left `canCallTool` checking the stale mode and still prompting for
approval. Closes tiann#735.

Drop the stored field and read live from `session.getPermissionMode()`,
mirroring how the OpenCode permission handler already works. Override
`Session.getPermissionMode()` in `claude/session.ts` to return the
Claude-narrow `PermissionMode`, sound because the matching
`setPermissionMode` setter only accepts that subset.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings
No issues found in the added or modified lines.

Summary
Review mode: initial
The diff makes PermissionHandler read the live Claude session permission mode, keeps handleModeChange and approval responses writing through the session, and adds a regression test for mid-turn web dropdown changes. Residual risk: I could not execute the local test suite in this runner because bun is unavailable.

Testing
Not run: bun test cli/src/claude/utils/permissionHandler.test.ts and bun typecheck both failed with bun: command not found.

HAPI Bot

@tiann tiann merged commit bd13fac into tiann:main Jun 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plan模式结束后,切换到yolo模式不生效

2 participants