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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(claude): /branch node action + document Claude Code support
enes47aacf4b311a
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 656b17ff9..1a433f856 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -24,6 +24,7 @@ import { CommandPalette, type Command } from '../components/CommandPalette'import {IconClaude,IconCollapse,+ IconBranch,IconDuplicate,IconEditor,IconFit,@@ -51,6 +52,7 @@ import { ExplorerPanel } from '../components/ExplorerPanel'import { transport } from '../terminal/local-transport'import { useProjects } from '../state/projects'import { useClaudeStatus } from '../state/claudeStatus'+import { branchClaudeSession } from '../lib/claudeBranch'import { useSettings } from '../state/settings'import {COLLAPSED_HEIGHT,@@ -476,6 +478,34 @@ export function Canvas() {[setNodes, markDirty])+ // Run Claude's /branch in this node, then open a new node that resumes the original+ // conversation (claude -r <ORIGINAL_ID>). The source node stays on the new branch.+ const branchClaude = useCallback(+ async (nodeId: string) => {+ const source = nodesRef.current.find((n) => n.id === nodeId) as CanvasNode | undefined+ if (!source) return+ const res = await branchClaudeSession(nodeId)+ if (!res.ok || !res.originalId) {+ setConfirm({ message: res.error ?? 'Branch failed.', onConfirm: () => setConfirm(null) })+ return+ }+ const copy = duplicateNode(source)+ copy.data = {+ ...copy.data,+ initialCommand: `claude -r ${res.originalId}`,+ title: `${source.data.title} (original)`+ }+ copy.position = {+ x: source.position.x + ((source.width as number) ?? 600) + 32,+ y: source.position.y+ }+ copy.selected = true+ setNodes((ns) => [...ns.map((n) => ({ ...n, selected: false })), copy])+ markDirty()+ },+ [setNodes, markDirty]+ )+const setNodesColor = useCallback((ids: string[], color: string) => {const set = new Set(ids)@@ -604,6 +634,18 @@ export function Canvas() {{ type: 'colors', onPick: (c) => setNodesColor(ids, c) },{ type: 'separator' },{ label: 'Duplicate', icon: <IconDuplicate />, onClick: () => duplicateNodes(ids) },+ ...(ids.length === 1 &&+ ((nodesRef.current.find((n) => n.id === ids[0])?.data.tags as string[]) ?? []).includes(+ 'claude'+ )+ ? ([+ {+ label: 'Branch conversation',+ icon: <IconBranch />,+ onClick: () => void branchClaude(ids[0])+ }+ ] as MenuItem[])+ : []),{ label: 'Align to grid', icon: <IconGrid />, onClick: () => alignToGrid(ids) },{ label: 'Collapse / Expand', icon: <IconCollapse />, onClick: () => toggleCollapseNodes(ids) },...(ids.some((nid) => nodesRef.current.find((n) => n.id === nid)?.type === 'terminal')@@ -618,6 +660,7 @@ export function Canvas() {groupSelection,setNodesColor,duplicateNodes,+ branchClaude,alignToGrid,toggleCollapseNodes,toggleMarkdown,diff --git a/src/renderer/lib/claudeBranch.ts b/src/renderer/lib/claudeBranch.tsnew file mode 100644index 000000000..445515fd5--- /dev/null+++ b/src/renderer/lib/claudeBranch.ts@@ -0,0 +1,33 @@+// Drives Claude Code's own `/branch` slash command from a node action.+//+// Running `/branch` switches the CURRENT terminal onto a new branch and prints, e.g.:+// Branched conversation. You are now in the new branch (session <NEW_ID>). Use+// /resume <ORIGINAL_ID> to return to the original, or run claude -r <ORIGINAL_ID> in a+// new terminal.+// We parse <ORIGINAL_ID> so the caller can open a second node that resumes the parked+// original conversation (`claude -r <ORIGINAL_ID>`).++const ORIGINAL = /claude -r\s+([0-9a-fA-F-]{8,})/+const RESUME = /\/resume\s+([0-9a-fA-F-]{8,})/++const delay = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))++export interface BranchResult {+ ok: boolean+ originalId?: string+ error?: string+}++export async function branchClaudeSession(nodeId: string): Promise<BranchResult> {+ const sent = await window.nodeTerminal.pty.sendText(nodeId, '/branch')+ if (!sent) return { ok: false, error: 'Branch requires a persistent (tmux) session.' }++ // Poll the visible buffer until the branch output (with the original session id) appears.+ for (let i = 0; i < 20; i++) {+ await delay(300)+ const buf = await window.nodeTerminal.pty.capture(nodeId)+ const m = buf.match(ORIGINAL) ?? buf.match(RESUME)+ if (m) return { ok: true, originalId: m[1] }+ }+ return { ok: false, error: "Couldn't detect the branch result — open a Claude node manually if needed." }+}