Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(agents): pure version gate for `--permission-mode auto`

enes2433d9e5a537
diff --git a/src/shared/agents/auto-mode-gate.test.ts b/src/shared/agents/auto-mode-gate.test.ts
new file mode 100644
index 000000000..85d96aa3e
--- /dev/null
+++ b/src/shared/agents/auto-mode-gate.test.ts
@@ -0,0 +1,84 @@
+// The `auto` permission mode only exists in Claude Code >= 2.1.90. Older CLIs REJECT it
+// (`error: option '--permission-mode <mode>' argument 'auto' is invalid.` → exit 1), which would
+// kill every Claude node launch. These tests pin the version predicate + the gate that degrades
+// `auto` to the bare command (and nothing else) when the CLI is too old or unknown.
+import { describe, it, expect } from 'vitest'
+import {
+ AUTO_PERMISSION_MODE_MIN_VERSION,
+ supportsAutoPermissionMode,
+ gatePermissionMode,
+ withPermissionMode,
+ ALL_PERMISSION_MODES,
+ type AgentPermissionMode
+} from './config'
+
+describe('supportsAutoPermissionMode', () => {
+ it('accepts the first version that knows `auto` and everything above it', () => {
+ expect(AUTO_PERMISSION_MODE_MIN_VERSION).toBe('2.1.90')
+ expect(supportsAutoPermissionMode('2.1.90')).toBe(true)
+ expect(supportsAutoPermissionMode('2.1.91')).toBe(true)
+ expect(supportsAutoPermissionMode('2.1.207')).toBe(true)
+ expect(supportsAutoPermissionMode('2.2.0')).toBe(true)
+ expect(supportsAutoPermissionMode('3.0.0')).toBe(true)
+ })
+
+ it('rejects the versions that reject the flag value', () => {
+ expect(supportsAutoPermissionMode('2.1.50')).toBe(false)
+ expect(supportsAutoPermissionMode('2.1.89')).toBe(false)
+ expect(supportsAutoPermissionMode('2.0.99')).toBe(false)
+ expect(supportsAutoPermissionMode('1.9.999')).toBe(false)
+ })
+
+ it('reads the real `claude --version` output shape', () => {
+ expect(supportsAutoPermissionMode('2.1.207 (Claude Code)')).toBe(true)
+ expect(supportsAutoPermissionMode('2.1.50 (Claude Code)\n')).toBe(false)
+ })
+
+ it('fails open (unsupported) on anything it cannot read', () => {
+ expect(supportsAutoPermissionMode('')).toBe(false)
+ expect(supportsAutoPermissionMode(null)).toBe(false)
+ expect(supportsAutoPermissionMode(undefined)).toBe(false)
+ expect(supportsAutoPermissionMode('command not found')).toBe(false)
+ // A two-segment version can't be compared against a patch floor — treat as unknown.
+ expect(supportsAutoPermissionMode('2.1')).toBe(false)
+ })
+
+ it('does not confuse a longer number that merely starts with a supported prefix', () => {
+ expect(supportsAutoPermissionMode('12.1.90')).toBe(true)
+ expect(supportsAutoPermissionMode('0.2.99')).toBe(false)
+ })
+})
+
+describe('gatePermissionMode', () => {
+ it('degrades auto to manual (= no flag, bare command) when the CLI is too old', () => {
+ expect(gatePermissionMode('auto', false)).toBe('manual')
+ expect(withPermissionMode('claude', 'claude', gatePermissionMode('auto', false))).toBe('claude')
+ })
+
+ it('keeps auto when the CLI supports it', () => {
+ expect(gatePermissionMode('auto', true)).toBe('auto')
+ expect(withPermissionMode('claude', 'claude', gatePermissionMode('auto', true))).toBe(
+ 'claude --permission-mode auto'
+ )
+ })
+
+ it('leaves every other mode alone regardless of the probe', () => {
+ // Only `auto` is version-gated: the other four are accepted by every CLI we support, so a
+ // failed/never-run probe must not silently strip them.
+ for (const mode of ALL_PERMISSION_MODES.filter((m) => m !== 'auto')) {
+ expect(gatePermissionMode(mode, false)).toBe(mode)
+ expect(gatePermissionMode(mode, true)).toBe(mode)
+ }
+ expect(withPermissionMode('claude', 'claude', gatePermissionMode('plan', false))).toBe(
+ 'claude --permission-mode plan'
+ )
+ expect(withPermissionMode('claude', 'claude', gatePermissionMode('bypassPermissions', false))).toBe(
+ 'claude --permission-mode bypassPermissions'
+ )
+ })
+
+ it('never throws on a forged mode (it just stays unrecognized → bare command)', () => {
+ const forged = 'auto; rm -rf /' as unknown as AgentPermissionMode
+ expect(withPermissionMode('claude', 'claude', gatePermissionMode(forged, true))).toBe('claude')
+ })
+})
diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.ts
index a42ae5545..623a7cd45 100644
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@ -118,9 +118,58 @@ export function resumeCommand(id: AgentId, sessionId: string): string | null {
* `--permission-mode` flag does.
*
* `dontAsk` is deliberately not exposed: from the user's point of view it overlaps `auto`.
+ *
+ * VERSION GATE: `auto` is the one value here that older Claude CLIs do NOT accept — see
+ * AUTO_PERMISSION_MODE_MIN_VERSION / gatePermissionMode below. Never hand a raw `auto` to a
+ * launch command without running it through `gatePermissionMode` first.
*/
export type AgentPermissionMode = 'manual' | 'auto' | 'acceptEdits' | 'plan' | 'bypassPermissions'
+/**
+ * First Claude Code version whose `--permission-mode` accepts `auto`. Earlier CLIs validate the
+ * value against their own choices list and EXIT 1:
+ * error: option '--permission-mode <mode>' argument 'auto' is invalid.
+ * Allowed choices are acceptEdits, bypassPermissions, default, dontAsk, plan.
+ * Since `auto` is our default, an ungated flag would break every Claude launch on an older CLI.
+ * The other four modes are accepted by every CLI we support, so ONLY `auto` is gated.
+ */
+export const AUTO_PERMISSION_MODE_MIN_VERSION = '2.1.90'
+
+const MIN_AUTO_VERSION: readonly number[] = AUTO_PERMISSION_MODE_MIN_VERSION.split('.').map(Number)
+
+/**
+ * Does this `claude --version` output know `--permission-mode auto`? Pure (the probe that feeds it
+ * lives in core/claude-cli.ts). FAILS OPEN to `false` on anything unreadable — an unknown version
+ * means we omit the flag and launch the bare command (today's behavior), never a failed launch.
+ */
+export function supportsAutoPermissionMode(versionOutput: string | null | undefined): boolean {
+ const m = (versionOutput ?? '').match(/(\d+)\.(\d+)\.(\d+)/)
+ if (!m) return false
+ const v = [Number(m[1]), Number(m[2]), Number(m[3])]
+ for (let i = 0; i < MIN_AUTO_VERSION.length; i++) {
+ if (v[i] > MIN_AUTO_VERSION[i]) return true
+ if (v[i] < MIN_AUTO_VERSION[i]) return false
+ }
+ return true // exactly the minimum
+}
+
+/**
+ * The mode a session can ACTUALLY start in on the CLI that will run it. `auto` degrades to
+ * `manual` — which emits no flag at all, i.e. the bare `claude` command nodeterm shipped before
+ * this setting existed — when that CLI is too old to know the value (or the probe never
+ * answered). Every other mode passes through untouched, so a failed probe can never strip
+ * `plan` / `acceptEdits` / `bypassPermissions`.
+ *
+ * The user's SETTING stays `auto`: only the emitted command line changes, and it changes back
+ * the moment they upgrade the CLI.
+ */
+export function gatePermissionMode(
+ mode: AgentPermissionMode,
+ autoSupported: boolean
+): AgentPermissionMode {
+ return mode === 'auto' && !autoSupported ? 'manual' : mode
+}
+
// Declared first: its `Record<AgentPermissionMode, string>` type forces every member of the
// union to be present, which is what makes ALL_PERMISSION_MODES below impossible to desync.
export const PERMISSION_MODE_LABELS: Record<AgentPermissionMode, string> = {