Skip to content

Expose Claude Code's auto permission mode in Chat tabs - #255

Merged
frenchie4111 merged 1 commit into
mainfrom
feat/json-mode-auto-permission-mode
Aug 16, 2026
Merged

Expose Claude Code's auto permission mode in Chat tabs#255
frenchie4111 merged 1 commit into
mainfrom
feat/json-mode-auto-permission-mode

Conversation

@frenchie4111

Copy link
Copy Markdown
Collaborator

Summary

The bundled CLI (@anthropic-ai/claude-code@2.1.221) supports an auto permission 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-session set_permission_mode control 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.

  • Mode badge now cycles default → acceptEdits → plan → auto → default, matching the TUI's shift+tab order. auto renders in the theme's warning color to stay distinct from the existing three.
  • Settings gains a matching option for the per-chat default.
  • Approval card: in auto mode, approving an edit tool no longer flips the session to acceptEdits. 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 the EDIT_TOOL_NAMES set for the session instead, which is what the "Allow edits this session" label promises. Other modes are unchanged.

bypassPermissions and dontAsk remain 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 coercing auto to acceptEdits. Two of the three were beyond the Settings onChange that prompted the change:

  • Settings.tsx onChange — would drop the user's selection immediately.
  • main/index.ts config:setJsonModeDefaultPermissionMode — would refuse to persist it.
  • build-initial-state.ts — would reset a persisted auto back to acceptEdits on next boot.

Rather than fix each in place, the union is now derived from a JSON_CLAUDE_PERMISSION_MODES const with an isJsonClaudePermissionMode guard that all three share, so adding a mode later can't leave a validator behind. The type-only spellings in types.ts, build-backend.ts, persistence.ts, and main/index.ts now 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 — clean
  • npx electron-vite build — clean
  • npx vitest run — affected slices 163/163. Note: the suite has 17 pre-existing failures in git-ops-state, git-poll-cache, path-fix, and worktree-watcher (timing-flaky real-git/fs tests); verified they fail identically on a stashed clean tree and are unrelated to these files.
  • Reducer coverage extended for permissionModeChanged with auto, the settings default, and the new guard (including that it rejects bypassPermissions / dontAsk).
  • Manual: cycle the badge through all four modes and confirm auto applies mid-turn without a respawn.
  • Manual: set auto as the Settings default, restart, confirm it survives (the boot-path validator fix).
  • Manual: in auto mode, approve an edit via "Allow edits this session" and confirm the badge stays on auto.

🤖 Generated with Claude Code

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>
@frenchie4111
frenchie4111 merged commit 9ea776b into main Aug 16, 2026
1 check 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.

1 participant