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): visualize subagents as connected nodes + /loop badge
enesab39df8026b8
diff --git a/src/main/claude-hooks.ts b/src/main/claude-hooks.tsindex 8320a28fa..a6ef2e73d 100644--- a/src/main/claude-hooks.ts+++ b/src/main/claude-hooks.ts@@ -14,7 +14,18 @@ import path from 'path'import { app, type BrowserWindow } from 'electron'import { IPC } from '../shared/ipc'-const CLAUDE_EVENTS = ['SessionStart', 'UserPromptSubmit', 'Stop', 'Notification', 'SessionEnd']+const CLAUDE_EVENTS = [+ 'SessionStart',+ 'UserPromptSubmit',+ 'Stop',+ 'Notification',+ 'SessionEnd',+ 'PreToolUse',+ 'PostToolUse'+]++// Tool names that represent a spawned subagent (the only PreToolUse/PostToolUse we forward).+const SUBAGENT_TOOLS = new Set(['Agent', 'Task'])// The single managed hook command, registered under each event above. Must stay byte-stable// so install is idempotent and uninstall can find it. Reads the hook payload from stdin and@@ -126,16 +137,27 @@ export function initClaudeHooks(win: BrowserWindow): void {session_id?: stringnotification_type?: stringlast_assistant_message?: string+ prompt?: string+ tool_name?: string+ tool_use_id?: string+ tool_input?: { subagent_type?: string; description?: string; prompt?: string }}- if (p.hook_event_name && !win.isDestroyed()) {- win.webContents.send(IPC.claudeStatus, {- nodeId,- event: p.hook_event_name,- sessionId: p.session_id,- notificationType: p.notification_type,- lastMessage: p.last_assistant_message- })- }+ if (!p.hook_event_name || win.isDestroyed()) continue+ // Tool events flood (every Bash/Edit) — only forward subagent spawns.+ const isTool = p.hook_event_name === 'PreToolUse' || p.hook_event_name === 'PostToolUse'+ if (isTool && !SUBAGENT_TOOLS.has(p.tool_name ?? '')) continue+ win.webContents.send(IPC.claudeStatus, {+ nodeId,+ event: p.hook_event_name,+ sessionId: p.session_id,+ notificationType: p.notification_type,+ lastMessage: p.last_assistant_message,+ prompt: p.prompt,+ toolName: p.tool_name,+ toolUseId: p.tool_use_id,+ subagentType: p.tool_input?.subagent_type,+ taskLabel: p.tool_input?.description || p.tool_input?.prompt+ })} catch {// partial/garbled line; ignore}diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex fe958c64a..1c8fa6ec7 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -10,7 +10,7 @@ import {useReactFlow,type Viewport} from '@xyflow/react'-import type { Node } from '@xyflow/react'+import type { Edge, Node } from '@xyflow/react'import { TerminalNode } from '../nodes/TerminalNode'import { StickyNode } from '../nodes/StickyNode'import { GroupNode } from '../nodes/GroupNode'@@ -53,6 +53,8 @@ import { ExplorerPanel } from '../components/ExplorerPanel'import { transport } from '../terminal/local-transport'import { useProjects } from '../state/projects'import { useClaudeStatus } from '../state/claudeStatus'+import { useAgentNodes } from '../state/agentNodes'+import { SubagentNode } from '../nodes/SubagentNode'import { branchClaudeSession } from '../lib/claudeBranch'import { useSettings } from '../state/settings'import {@@ -120,11 +122,54 @@ export function Canvas() {sticky: withNodeBoundary(StickyNode),group: withNodeBoundary(GroupNode),editor: withNodeBoundary(EditorNode),- diff: withNodeBoundary(DiffNode)+ diff: withNodeBoundary(DiffNode),+ subagent: withNodeBoundary(SubagentNode)}),[])+ // Ephemeral subagent nodes + edges (driven by Claude hooks; never persisted / no undo).+ // Laid out fanning below the parent Claude node.+ const agentById = useAgentNodes((s) => s.byId)+ const { ephemeralNodes, ephemeralEdges } = useMemo(() => {+ const eNodes: CanvasNode[] = []+ const eEdges: Edge[] = []+ const byParent: Record<string, string[]> = {}+ for (const id of Object.keys(agentById)) {+ ;(byParent[agentById[id].parentNodeId] ??= []).push(id)+ }+ for (const [pid, childIds] of Object.entries(byParent)) {+ const parent = nodes.find((n) => n.id === pid)+ if (!parent) continue+ const ph = parent.measured?.height ?? (parent.height as number) ?? 400+ childIds.forEach((cid, i) => {+ const v = agentById[cid]+ eNodes.push({+ id: cid,+ type: 'subagent',+ position: { x: parent.position.x + i * 240, y: parent.position.y + ph + 60 },+ draggable: false,+ selectable: false,+ data: {+ title: v.label ?? '',+ color: '#d97757',+ group: null,+ subagentType: v.type,+ subagentState: v.state+ }+ } as CanvasNode)+ eEdges.push({+ id: `e-${cid}`,+ source: pid,+ target: cid,+ animated: v.state === 'working',+ style: { stroke: '#d97757', strokeWidth: 1.5 }+ })+ })+ }+ return { ephemeralNodes: eNodes, ephemeralEdges: eEdges }+ }, [agentById, nodes])+// 1) Load the whole workspace once and hydrate the projects store.useEffect(() => {let cancelled = false@@ -270,8 +315,11 @@ export function Canvas() {// ---- canvas interactions ----const handleNodesChange: typeof onNodesChange = useCallback((changes) => {- onNodesChange(changes)- if (changes.some((c) => c.type !== 'select')) markDirty()+ // Drop changes targeting ephemeral subagent nodes (they live outside the managed state).+ const eph = useAgentNodes.getState().byId+ const filtered = changes.filter((c) => !('id' in c && c.id in eph))+ onNodesChange(filtered)+ if (filtered.some((c) => c.type !== 'select')) markDirty()},[onNodesChange, markDirty])@@ -835,12 +883,16 @@ export function Canvas() {nodeId: e.nodeId})}+ const an = useAgentNodes.getState()switch (e.event) {case 'UserPromptSubmit':cs.setState(e.nodeId, 'working')+ an.clearForParent(e.nodeId) // new turn → drop the previous fan-out+ if (/^\s*\/loop\b/.test(e.prompt ?? '')) cs.setLoop(e.nodeId, true)breakcase 'Stop':cs.setState(e.nodeId, 'done')+ cs.bumpLoop(e.nodeId) // count loop iterations (no-op if not looping)alert('finished', 'Claude finished its turn.')breakcase 'Notification':@@ -852,9 +904,25 @@ export function Canvas() {alert('needs input', 'Claude is waiting for your response.')}break+ case 'PreToolUse':+ if (e.toolUseId) {+ an.start(e.toolUseId, {+ parentNodeId: e.nodeId,+ type: e.subagentType,+ label: e.taskLabel+ })+ }+ break+ case 'PostToolUse':+ if (e.toolUseId) an.finish(e.toolUseId)+ breakcase 'SessionStart':+ cs.setState(e.nodeId, undefined)+ breakcase 'SessionEnd':cs.setState(e.nodeId, undefined)+ cs.setLoop(e.nodeId, false)+ an.clearForParent(e.nodeId)break}})@@ -1050,7 +1118,8 @@ export function Canvas() {<div className="flow-wrap" ref={flowWrapRef}><ReactFlow- nodes={nodes}+ nodes={ephemeralNodes.length ? [...nodes, ...ephemeralNodes] : nodes}+ edges={ephemeralEdges}nodeTypes={nodeTypes}onNodesChange={handleNodesChange}onMove={onMove}diff --git a/src/renderer/nodes/SubagentNode.tsx b/src/renderer/nodes/SubagentNode.tsxnew file mode 100644index 000000000..fceb9b959--- /dev/null+++ b/src/renderer/nodes/SubagentNode.tsx@@ -0,0 +1,22 @@+import { Handle, Position, type NodeProps } from '@xyflow/react'+import type { CanvasNode } from '../state/workspace'++/**+ * Display-only node visualizing a subagent a Claude session spawned. It has no terminal+ * (subagents run inside the parent's process); it just shows the agent type, task, and+ * working/done state, with a target handle for the edge from its parent Claude node.+ */+export function SubagentNode({ data }: NodeProps<CanvasNode>) {+ const working = data.subagentState !== 'done'+ return (+ <div className={`subagent-node${working ? ' working' : ' done'}`}>+ <Handle type="target" position={Position.Top} isConnectable={false} />+ <div className="subagent-node__head">+ <span className="subagent-node__dot" />+ <span className="subagent-node__type">{(data.subagentType as string) || 'subagent'}</span>+ <span className="subagent-node__state">{working ? 'working' : 'done'}</span>+ </div>+ {data.title && <div className="subagent-node__task">{data.title}</div>}+ </div>+ )+}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex e50fda6e7..2e8f64426 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -9,6 +9,7 @@ import { NodeTags } from '../components/NodeTags'import { Tooltip } from '../components/Tooltip'import { useSettings } from '../state/settings'import { useClaudeStatus } from '../state/claudeStatus'+import { useAgentNodes } from '../state/agentNodes'import { COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'/**@@ -126,6 +127,7 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {cleanups.forEach((fn) => fn())useClaudeStatus.getState().setActive(id, false)useClaudeStatus.getState().remove(id)+ useAgentNodes.getState().clearForParent(id)if (sessionId) transport.kill(sessionId)term.dispose()termRef.current = null@@ -278,6 +280,12 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {RUNNING</span>)}+ {status?.loop && (+ <span className="term-node__status term-node__status--loop" title="Running /loop">+ <span className="term-node__status-dot" />+ LOOP ×{status.loop.count}+ </span>+ )}{(status?.state === 'waiting' || status?.state === 'blocked') && (<spanclassName="term-node__status term-node__status--attention"diff --git a/src/renderer/state/agentNodes.ts b/src/renderer/state/agentNodes.tsnew file mode 100644index 000000000..b90f17437--- /dev/null+++ b/src/renderer/state/agentNodes.ts@@ -0,0 +1,47 @@+import { create } from 'zustand'++/**+ * Transient visualization of subagents a Claude node spawns (Task/Agent tool), keyed by the+ * tool_use_id from the hooks. These render as ephemeral nodes + edges on the canvas; they are+ * never persisted to workspace.json and never enter undo/redo (see Canvas).+ */+export interface SubagentViz {+ /** The Claude terminal node that spawned this subagent. */+ parentNodeId: string+ /** Subagent type, e.g. 'general-purpose'. */+ type?: string+ /** The task description/prompt. */+ label?: string+ state: 'working' | 'done'+}++interface AgentNodesState {+ byId: Record<string, SubagentViz>+ start(toolUseId: string, viz: Omit<SubagentViz, 'state'>): void+ finish(toolUseId: string): void+ /** Remove all subagents spawned by a given parent node (turn/session ended, or node closed). */+ clearForParent(parentNodeId: string): void+}++export const useAgentNodes = create<AgentNodesState>((set) => ({+ byId: {},++ start: (toolUseId, viz) =>+ set((s) => ({ byId: { ...s.byId, [toolUseId]: { ...viz, state: 'working' } } })),++ finish: (toolUseId) =>+ set((s) => {+ const prev = s.byId[toolUseId]+ if (!prev || prev.state === 'done') return s+ return { byId: { ...s.byId, [toolUseId]: { ...prev, state: 'done' } } }+ }),++ clearForParent: (parentNodeId) =>+ set((s) => {+ const ids = Object.keys(s.byId).filter((id) => s.byId[id].parentNodeId === parentNodeId)+ if (!ids.length) return s+ const byId = { ...s.byId }+ for (const id of ids) delete byId[id]+ return { byId }+ })+}))diff --git a/src/renderer/state/claudeStatus.ts b/src/renderer/state/claudeStatus.tsindex 1882345cb..489f6a87a 100644--- a/src/renderer/state/claudeStatus.ts+++ b/src/renderer/state/claudeStatus.ts@@ -16,6 +16,8 @@ export interface ClaudeNodeStatus {session?: string/** Claude session id (from hooks) — used to resume/branch the conversation. */sessionId?: string+ /** Set when the node is running a /loop (heuristic); count = iterations so far. */+ loop?: { count: number }}interface ClaudeStatusState {@@ -28,6 +30,10 @@ interface ClaudeStatusState {setSessionId(id: string, sessionId: string): voidmarkUnread(id: string): voidclearUnread(id: string): void+ /** Start (active=true, resets count) or stop a /loop indicator. */+ setLoop(id: string, active: boolean): void+ /** Increment the /loop iteration count (only while a loop is active). */+ bumpLoop(id: string): voidremove(id: string): void}@@ -117,6 +123,22 @@ export const useClaudeStatus = create<ClaudeStatusState>((set) => ({return { byId }}),+ setLoop: (id, active) =>+ set((s) => {+ const prev = s.byId[id] ?? EMPTY+ if (active) return { byId: { ...s.byId, [id]: { ...prev, loop: { count: 0 } } } }+ if (!prev.loop) return s+ const { loop: _drop, ...rest } = prev+ return { byId: { ...s.byId, [id]: rest } }+ }),++ bumpLoop: (id) =>+ set((s) => {+ const prev = s.byId[id]+ if (!prev?.loop) return s+ return { byId: { ...s.byId, [id]: { ...prev, loop: { count: prev.loop.count + 1 } } } }+ }),+remove: (id) =>set((s) => {if (!(id in s.byId)) return sdiff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex a651da70b..4e847232a 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -516,6 +516,10 @@ body,color: #ff9f0a;}+.term-node__status--loop {+ color: #bf7af0;+}+.term-node__status--attention .term-node__status-dot {animation: nt-pulse 1.1s ease-in-out infinite;}@@ -2539,6 +2543,67 @@ body,color: var(--text);}+/* ---- Subagent (ephemeral, hook-driven) node ---- */+.subagent-node {+ width: 210px;+ padding: 10px 12px;+ background: #1c1c1e;+ border: 1px solid var(--border);+ border-left: 3px solid #d97757;+ border-radius: 10px;+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);+ font-size: 12px;+ color: var(--text);+}++.subagent-node__head {+ display: flex;+ align-items: center;+ gap: 7px;+}++.subagent-node__dot {+ width: 8px;+ height: 8px;+ flex: none;+ border-radius: 50%;+ background: #d97757;+}++.subagent-node.working .subagent-node__dot {+ animation: nt-pulse 1.1s ease-in-out infinite;+}++.subagent-node.done .subagent-node__dot {+ background: #30d158;+}++.subagent-node__type {+ font-weight: 600;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}++.subagent-node__state {+ margin-left: auto;+ font-size: 9.5px;+ font-weight: 700;+ letter-spacing: 0.05em;+ color: var(--muted);+}++.subagent-node__task {+ margin-top: 6px;+ color: var(--muted);+ font-size: 11.5px;+ line-height: 1.4;+ display: -webkit-box;+ -webkit-line-clamp: 2;+ -webkit-box-orient: vertical;+ overflow: hidden;+}+/* ---- Minimap ---- */.minimap {background: rgba(40, 40, 42, 0.85) !important;diff --git a/src/shared/types.ts b/src/shared/types.tsindex c11f54471..555ee593a 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -12,7 +12,8 @@ export interface PtyCreateOptions {persistKey?: string}-export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff'+// 'subagent' is render-only (ephemeral hook-driven viz) and never persisted.+export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff' | 'subagent'/** Persisted state of a single canvas node (terminal, sticky note, group frame, or editor). */export interface CanvasNodeState {@@ -308,13 +309,20 @@ export interface NotifyPayload {/** A Claude Code lifecycle hook event, forwarded from the main process. */export interface ClaudeStatusEvent {nodeId: string- /** SessionStart | UserPromptSubmit | Stop | Notification | SessionEnd */+ /** SessionStart | UserPromptSubmit | Stop | Notification | SessionEnd | PreToolUse | PostToolUse */event: stringsessionId?: string/** For Notification events: e.g. 'permission_prompt' | 'idle_prompt'. */notificationType?: string/** Claude's last assistant message (on Stop) — used as the notification body. */lastMessage?: string+ /** The user's prompt (UserPromptSubmit) — used to detect `/loop`. */+ prompt?: string+ /** Subagent tool events (PreToolUse/PostToolUse, tool_name Agent/Task). */+ toolName?: string+ toolUseId?: string+ subagentType?: string+ taskLabel?: string}export interface NodeTerminalApi {