Expose Claude Code's auto permission mode in Chat tabs - #255
Merged
Conversation
The bundled CLI (2.1.221) supports an `auto` mode where it decides which tool calls are safe and only routes risky ones through the permission bridge. Both our spawn arg and the mid-session control_request already pass the mode through untouched, so this widens our own union and fixes the places that enumerated its variants. The mode badge now cycles default → acceptEdits → plan → auto, matching the TUI's shift+tab order. Settings gains a matching option; its onChange validator was coercing anything unrecognized to acceptEdits via a string comparison TypeScript could not flag, so it and the two other validators now share an isJsonClaudePermissionMode guard derived from the union itself. In auto mode the approval card no longer flips the session to acceptEdits when the user grants an edit tool — the CLI already decided that call was worth asking about, so downgrading the whole session to let one edit through would be surprising. It grants the edit-tool set for the session instead, which is what the button label promises. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
The bundled CLI (
@anthropic-ai/claude-code@2.1.221) supports anautopermission mode where it decides which tool calls are safe and only routes the risky ones through the permission bridge. The plumbing was already free — both the spawn arg (--permission-mode) and the mid-sessionset_permission_modecontrol request pass the mode string through untouched — so this is mostly about widening our own narrower union and fixing every place that enumerated its variants.default → acceptEdits → plan → auto → default, matching the TUI's shift+tab order.autorenders in the theme's warning color to stay distinct from the existing three.automode, approving an edit tool no longer flips the session toacceptEdits. The CLI had already judged that call risky enough to ask about, so silently downgrading the whole session to let one edit through would be surprising. It grants theEDIT_TOOL_NAMESset for the session instead, which is what the "Allow edits this session" label promises. Other modes are unchanged.bypassPermissionsanddontAskremain deliberately unexposed; the doc comment on the union (which is load-bearing for that decision) is updated to say so.The validators were the interesting part
Three separate places validated the mode by string comparison, e.g.
v === 'default' || v === 'plan' ? v : 'acceptEdits'. Because these compare strings rather than narrowing a type, TypeScript would not have flagged any of them — they'd have kept compiling while silently coercingautotoacceptEdits. Two of the three were beyond the SettingsonChangethat prompted the change:Settings.tsxonChange— would drop the user's selection immediately.main/index.tsconfig:setJsonModeDefaultPermissionMode— would refuse to persist it.build-initial-state.ts— would reset a persistedautoback toacceptEditson next boot.Rather than fix each in place, the union is now derived from a
JSON_CLAUDE_PERMISSION_MODESconst with anisJsonClaudePermissionModeguard that all three share, so adding a mode later can't leave a validator behind. The type-only spellings intypes.ts,build-backend.ts,persistence.ts, andmain/index.tsnow import the shared type instead of re-spelling it.The Haiku auto-approver (
auto-approver.ts,autoApprovePermissions) is intentionally untouched — no mutual-exclusivity logic, no warning banners.Test plan
npm run typecheck— cleannpx electron-vite build— cleannpx vitest run— affected slices 163/163. Note: the suite has 17 pre-existing failures ingit-ops-state,git-poll-cache,path-fix, andworktree-watcher(timing-flaky real-git/fs tests); verified they fail identically on a stashed clean tree and are unrelated to these files.permissionModeChangedwithauto, the settings default, and the new guard (including that it rejectsbypassPermissions/dontAsk).autoapplies mid-turn without a respawn.autoas the Settings default, restart, confirm it survives (the boot-path validator fix).automode, approve an edit via "Allow edits this session" and confirm the badge stays onauto.🤖 Generated with Claude Code