fix(claude): apply mid-turn permission mode changes to canCallTool#764
Merged
Merged
Conversation
`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>
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PermissionHandlerstored its ownpermissionModefield and only updated it insidehandleModeChange, which fires when a new batch is pulled from the queue. TheSetSessionConfigRPC (web dropdown changes) updatesrunClaude.ts'scurrentPermissionModeand the session keepalive metadata, but never reaches the handler — so switching from default to Yolo while a turn was in progress leftcanCallToolchecking 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. OverrideSession.getPermissionMode()inclaude/session.tsto return the Claude-narrowPermissionMode, which is sound because the matchingsetPermissionModesetter only accepts that subset, so the field cannot hold a foreign flavor value.Closes #735.
Why #735 triggers this
In #735's repro:
exit_plan_modeapproval cardPLAN_FAKE_RESTARTwithpermissionMode: 'default'and Claude restarts a new turn under defaultAfter this fix step 5 auto-approves as expected.
Disclosure
Vibe-coded with Claude Opus 4.7 (via HAPI).
Test plan
bun typecheckpassesbun run test src/claude— 95/95 pass including new regression testfix/claude-mid-turn-permission-mode-735source — 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