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): launch claude nodes in the resolved permission mode (new, resume, branch)

enesc6e19503910e
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 99614afde..f8aa9b062 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -101,6 +101,7 @@ import {
canContextLink,
canControlCanvas,
resumeCommand,
+ withPermissionMode,
AGENT_CONFIG,
BUILTIN_AGENT_IDS,
type AgentId
@@ -110,6 +111,7 @@ import { AgentIcon } from '../lib/agentIcons'
import { branchClaudeSession } from '../lib/claudeBranch'
import { buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, type LinkEndpoint } from '../lib/noteLink'
import { useSettings } from '../state/settings'
+import { activePermissionMode } from '../state/permissionMode'
import { useRemoteHosting } from '../state/remoteHosting'
import { useContextWindow } from '../state/contextWindow'
import { useSessionNaming } from '../state/sessionNaming'
@@ -1409,7 +1411,16 @@ export function Canvas() {
)
setNodes((ns) => [
...ns,
- createAgentNode('claude', ns.length, project?.cwd, viewCenter(), prompt, undefined, account)
+ createAgentNode(
+ 'claude',
+ ns.length,
+ project?.cwd,
+ viewCenter(),
+ prompt,
+ undefined,
+ account,
+ activePermissionMode()
+ )
])
markDirty()
},
@@ -1572,7 +1583,8 @@ export function Canvas() {
center ?? viewCenter(),
undefined,
project?.ssh,
- account
+ account,
+ activePermissionMode()
)
return [...ns, groupId ? parentInto(node, groupId) : node]
})
@@ -2036,7 +2048,12 @@ export function Canvas() {
const copy = duplicateNode(source)
copy.data = {
...copy.data,
- initialCommand: `${claudeLaunchCommand()} -r ${originalId}`,
+ // Built fresh here (never re-wrapping a persisted command), so it is flagged exactly once.
+ initialCommand: withPermissionMode(
+ `${claudeLaunchCommand()} -r ${originalId}`,
+ 'claude',
+ activePermissionMode()
+ ),
title: `${source.data.title} (original)`
}
copy.position = {
@@ -2091,7 +2108,8 @@ export function Canvas() {
undefined,
// Inherit the source's Claude account (dropped by the factory unless the target is claude),
// so a claude→claude transfer resumes the transcript from the right account dir.
- source.data.accountId
+ source.data.accountId,
+ activePermissionMode()
)
node.position = {
x: source.position.x + ((source.width as number) ?? 600) + 32,
@@ -2625,7 +2643,11 @@ export function Canvas() {
const cmd = resumeCommand('claude', hit.sessionId)
if (!cmd) return
const node = createAgentNode('claude', nodesRef.current.length, hit.cwd, viewCenter())
- node.data = { ...node.data, initialCommand: cmd }
+ // The resume command replaces (never wraps) the factory's command, so it is flagged once.
+ node.data = {
+ ...node.data,
+ initialCommand: withPermissionMode(cmd, 'claude', activePermissionMode())
+ }
node.selected = true
setNodes((ns) => [...ns.map((n) => ({ ...n, selected: false })), node])
markDirty()
@@ -2769,7 +2791,8 @@ export function Canvas() {
placeBelow(i),
args.prompt,
undefined,
- account
+ account,
+ activePermissionMode()
)
)
)
@@ -2920,7 +2943,8 @@ export function Canvas() {
placeBelow(i),
r.prompt,
undefined,
- teamAccount
+ teamAccount,
+ activePermissionMode()
)
return r.title ? { ...node, data: { ...node.data, title: r.title, titleAuto: false } } : node
})
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index da1592060..5933a4b68 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -31,7 +31,8 @@ import { useAgentNodes } from '../state/agentNodes'
import { useProjects } from '../state/projects'
import { useSshConn } from '../state/sshConn'
import { accountChipLabel, COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'
-import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, resumeCommand, agentConfig, type AgentId } from '@shared/agents/config'
+import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, resumeCommand, withPermissionMode, agentConfig, type AgentId } from '@shared/agents/config'
+import { activePermissionMode } from '../state/permissionMode'
import { buildSshArgs, type SshConnection } from '@shared/ssh'
/** Backslash-escape shell-special characters, like a native terminal does on file drop. */
@@ -551,7 +552,12 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// prior conversation by its session id (known from hooks) when we have one; otherwise
// start the agent fresh. Plain terminals get nothing here — just the restored shell.
const priorId = useAgentStatus.getState().byId[id]?.sessionId
- const cmd = (priorId && resumeCommand(agentId, priorId)) || agentConfig(agentId)?.launchCmd
+ const base = (priorId && resumeCommand(agentId, priorId)) || agentConfig(agentId)?.launchCmd
+ // Re-resolve the mode at relaunch: it's a property of how a session is launched, not
+ // a persisted property of the node, so the current setting wins after a reboot. `base`
+ // is always freshly built here — never a command string read back from node data — so
+ // it can never end up double-flagged.
+ const cmd = base && withPermissionMode(base, agentId, activePermissionMode())
if (cmd) transport.write(sid, `${cmd}\n`)
}
})
diff --git a/src/renderer/state/permissionMode.ts b/src/renderer/state/permissionMode.ts
new file mode 100644
index 000000000..120030dc9
--- /dev/null
+++ b/src/renderer/state/permissionMode.ts
@@ -0,0 +1,19 @@
+import { resolvePermissionMode, type AgentPermissionMode } from '@shared/agents/config'
+import { useProjects } from './projects'
+import { useSettings } from './settings'
+
+/**
+ * The permission mode a session launched right now should start in: the active project's
+ * override, else the global setting.
+ *
+ * Lives in its own module rather than in workspace.ts because projects.ts imports workspace.ts
+ * (createProject) — importing the projects store from workspace.ts would close that cycle.
+ */
+export function activePermissionMode(): AgentPermissionMode {
+ const { settings } = useSettings.getState()
+ const { projects, activeProjectId } = useProjects.getState()
+ return resolvePermissionMode(
+ projects.find((p) => p.id === activeProjectId),
+ settings
+ )
+}
diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.ts
index 6dffd91b1..abe597715 100644
--- a/src/renderer/state/workspace.test.ts
+++ b/src/renderer/state/workspace.test.ts
@@ -296,3 +296,30 @@ describe('dino node serialization', () => {
expect(node.width).toBe(600)
})
})
+
+describe('createAgentNode permission mode', () => {
+ it('appends the flag for claude', () => {
+ const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, undefined, 'auto')
+ expect(node.data.initialCommand).toBe('claude --permission-mode auto')
+ })
+
+ it('stays bare in manual mode (legacy parity)', () => {
+ const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, undefined, 'manual')
+ expect(node.data.initialCommand).toBe('claude')
+ })
+
+ it('stays bare when no mode is passed at all (legacy parity)', () => {
+ const node = createAgentNode('claude', 0)
+ expect(node.data.initialCommand).toBe('claude')
+ })
+
+ it('keeps the flag after the initial prompt so the prompt stays claude argv', () => {
+ const node = createAgentNode('claude', 0, undefined, undefined, 'fix the bug', undefined, undefined, 'auto')
+ expect(node.data.initialCommand).toBe("claude 'fix the bug' --permission-mode auto")
+ })
+
+ it('never flags a non-capable agent', () => {
+ const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, undefined, 'auto')
+ expect(node.data.initialCommand).toBe('codex')
+ })
+})
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 2b30cde23..27ee1e5b2 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -1,7 +1,7 @@
import type { Node } from '@xyflow/react'
import type { CanvasMutation, CanvasNodeState, ClaudeAccount, NodeKind, Project } from '@shared/types'
-import type { AgentId } from '@shared/agents/config'
-import { agentConfig } from '@shared/agents/config'
+import type { AgentId, AgentPermissionMode } from '@shared/agents/config'
+import { agentConfig, withPermissionMode } from '@shared/agents/config'
import { sshHostKey } from '@shared/ssh'
import { useSettings } from './settings'
@@ -285,13 +285,19 @@ export function createAgentNode(
center?: { x: number; y: number },
initialPrompt?: string,
ssh?: Project['ssh'],
- accountId?: string
+ accountId?: string,
+ permissionMode?: AgentPermissionMode
): CanvasNode {
const { label, color, launchCmd } = resolveAgent(agentId)
const baseCmd = agentId === 'claude' ? claudeLaunchCommand() : launchCmd
- const initialCommand = initialPrompt
+ const withPrompt = initialPrompt
? `${baseCmd} ${shellSingleQuote(initialPrompt.replace(/\s+/g, ' ').trim())}`
: baseCmd
+ // Flag goes last: the prompt is claude's positional argv and must stay adjacent to the binary.
+ // No mode passed (e.g. a legacy/test call site) = bare command, exactly as before this setting.
+ const initialCommand = permissionMode
+ ? withPermissionMode(withPrompt, agentId, permissionMode)
+ : withPrompt
return {
id: nextId('term'),
type: 'terminal',