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(claude): live subagent transcript (click to expand, streams while working)

enes89b30d658da0
diff --git a/src/main/claude-hooks.ts b/src/main/claude-hooks.ts
index ec101bd48..e9f1f75fe 100644
--- a/src/main/claude-hooks.ts
+++ b/src/main/claude-hooks.ts
@@ -13,6 +13,7 @@ import os from 'os'
import path from 'path'
import { app, type BrowserWindow } from 'electron'
import { IPC } from '../shared/ipc'
+import { createSubagentTail } from './subagent-tail'
const CLAUDE_EVENTS = [
'SessionStart',
@@ -94,6 +95,7 @@ export function initClaudeHooks(win: BrowserWindow): void {
}
const offsets = new Map<string, number>()
+ const subagentTail = createSubagentTail(win)
const scan = () => {
let files: string[]
@@ -135,6 +137,7 @@ export function initClaudeHooks(win: BrowserWindow): void {
const p = JSON.parse(t) as {
hook_event_name?: string
session_id?: string
+ transcript_path?: string
notification_type?: string
last_assistant_message?: string
prompt?: string
@@ -153,6 +156,11 @@ export function initClaudeHooks(win: BrowserWindow): void {
// 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
+ // Tail the subagent's live transcript while it runs.
+ if (p.tool_use_id) {
+ if (p.hook_event_name === 'PreToolUse') subagentTail.track(p.tool_use_id, p.transcript_path)
+ else if (p.hook_event_name === 'PostToolUse') subagentTail.finish(p.tool_use_id)
+ }
const tr = p.tool_response
const result = tr?.content
?.filter((c) => c.type === 'text' && c.text)
diff --git a/src/main/subagent-tail.ts b/src/main/subagent-tail.ts
new file mode 100644
index 000000000..9e882e072
--- /dev/null
+++ b/src/main/subagent-tail.ts
@@ -0,0 +1,146 @@
+// Streams a subagent's live transcript to the renderer while it runs.
+//
+// Each subagent Claude spawns gets its own transcript at
+// <parent transcript dir>/<sessionId>/subagents/agent-<agentId>.jsonl
+// plus an agent-<agentId>.meta.json that carries the spawning tool_use_id. We resolve the
+// file by matching that toolUseId, then tail it (offset-based) and forward formatted lines.
+// All read-only — if Claude changes the format we just stream less (no crash).
+import fs from 'fs'
+import path from 'path'
+import { type BrowserWindow } from 'electron'
+import { IPC } from '../shared/ipc'
+
+interface Tracked {
+ dir: string
+ file: string | null
+ offset: number
+}
+
+function textOf(content: unknown): string {
+ if (typeof content === 'string') return content
+ if (Array.isArray(content)) {
+ return content
+ .map((c) => (c && typeof c === 'object' && 'text' in c ? String((c as { text: unknown }).text ?? '') : ''))
+ .filter(Boolean)
+ .join('\n')
+ }
+ return ''
+}
+
+// Render one transcript line into readable text. Includes everything substantive
+// (assistant text + tool calls, user/tool results); skips pure-metadata lines.
+function formatLine(line: string): string {
+ let o: { type?: string; message?: { content?: unknown } }
+ try {
+ o = JSON.parse(line)
+ } catch {
+ return ''
+ }
+ const content = o.message?.content
+ if (o.type === 'assistant' && Array.isArray(content)) {
+ return content
+ .map((c: { type?: string; text?: string; name?: string; input?: unknown }) => {
+ if (c.type === 'text') return c.text ?? ''
+ if (c.type === 'tool_use') {
+ const input = c.input ? JSON.stringify(c.input) : ''
+ return `→ ${c.name}${input ? ` ${input.slice(0, 120)}` : ''}`
+ }
+ return ''
+ })
+ .filter(Boolean)
+ .join('\n')
+ }
+ if (o.type === 'user' && Array.isArray(content)) {
+ return content
+ .map((c: { type?: string; text?: string; content?: unknown }) => {
+ if (c.type === 'text') return c.text ?? ''
+ if (c.type === 'tool_result') {
+ const r = textOf(c.content)
+ return r ? `⮑ ${r.slice(0, 400)}` : ''
+ }
+ return ''
+ })
+ .filter(Boolean)
+ .join('\n')
+ }
+ return ''
+}
+
+export interface SubagentTail {
+ track(toolUseId: string, transcriptPath: string | undefined): void
+ finish(toolUseId: string): void
+}
+
+export function createSubagentTail(win: BrowserWindow): SubagentTail {
+ const tracked = new Map<string, Tracked>()
+ let timer: ReturnType<typeof setInterval> | null = null
+
+ const send = (toolUseId: string, chunk: string) => {
+ if (chunk && !win.isDestroyed()) win.webContents.send(IPC.claudeSubagentActivity, { toolUseId, chunk })
+ }
+
+ const readOne = (toolUseId: string, e: Tracked) => {
+ try {
+ if (!e.file) {
+ let metas: string[]
+ try {
+ metas = fs.readdirSync(e.dir)
+ } catch {
+ return // dir not created yet
+ }
+ for (const m of metas) {
+ if (!m.endsWith('.meta.json')) continue
+ try {
+ const meta = JSON.parse(fs.readFileSync(path.join(e.dir, m), 'utf-8'))
+ if (meta.toolUseId === toolUseId) {
+ e.file = path.join(e.dir, m.replace(/\.meta\.json$/, '.jsonl'))
+ break
+ }
+ } catch {
+ // ignore unparseable meta
+ }
+ }
+ if (!e.file) return
+ }
+ const size = fs.statSync(e.file).size
+ if (size <= e.offset) return
+ const buf = Buffer.alloc(size - e.offset)
+ const fd = fs.openSync(e.file, 'r')
+ fs.readSync(fd, buf, 0, buf.length, e.offset)
+ fs.closeSync(fd)
+ e.offset = size
+ const out = buf
+ .toString('utf-8')
+ .split('\n')
+ .filter(Boolean)
+ .map(formatLine)
+ .filter(Boolean)
+ .join('\n')
+ if (out) send(toolUseId, out + '\n')
+ } catch {
+ // file may not exist yet / transient read error
+ }
+ }
+
+ const tick = () => {
+ for (const [toolUseId, e] of tracked) readOne(toolUseId, e)
+ if (!tracked.size && timer) {
+ clearInterval(timer)
+ timer = null
+ }
+ }
+
+ return {
+ track(toolUseId, transcriptPath) {
+ if (!transcriptPath || tracked.has(toolUseId)) return
+ const dir = path.join(transcriptPath.replace(/\.jsonl$/, ''), 'subagents')
+ tracked.set(toolUseId, { dir, file: null, offset: 0 })
+ if (!timer) timer = setInterval(tick, 400) // only runs while subagents are active
+ },
+ finish(toolUseId) {
+ const e = tracked.get(toolUseId)
+ if (e) readOne(toolUseId, e) // final flush
+ setTimeout(() => tracked.delete(toolUseId), 1500)
+ }
+ }
+}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 5b12385cd..bb66585ad 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -113,6 +113,11 @@ const api: NodeTerminalApi = {
const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)
ipcRenderer.on(IPC.claudeStatus, handler)
return () => ipcRenderer.removeListener(IPC.claudeStatus, handler)
+ },
+ onSubagentActivity: (listener) => {
+ const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)
+ ipcRenderer.on(IPC.claudeSubagentActivity, handler)
+ return () => ipcRenderer.removeListener(IPC.claudeSubagentActivity, handler)
}
}
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 666ef60f9..a58499a5d 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -166,7 +166,8 @@ export function Canvas() {
subagentDurationMs: v.durationMs,
subagentTokens: v.tokens,
subagentToolUses: v.toolUses,
- subagentResult: v.result
+ subagentResult: v.result,
+ subagentActivity: v.activity
}
} as CanvasNode)
eEdges.push({
@@ -853,6 +854,15 @@ export function Canvas() {
useEffect(() => window.nodeTerminal.onFocusNode(focusNodeById), [focusNodeById])
+ // Stream live subagent transcript chunks into the agent-nodes store.
+ useEffect(
+ () =>
+ window.nodeTerminal.onSubagentActivity((e) =>
+ useAgentNodes.getState().appendActivity(e.toolUseId, e.chunk)
+ ),
+ []
+ )
+
// Claude Code lifecycle, reported by Claude's own hooks (see main/claude-hooks.ts):
// UserPromptSubmit → working, Stop → done, Notification → waiting/blocked. On a turn
// finishing / needing attention while the window is in the background: mark unread +
diff --git a/src/renderer/nodes/SubagentNode.tsx b/src/renderer/nodes/SubagentNode.tsx
index df5c47fa2..be45190d7 100644
--- a/src/renderer/nodes/SubagentNode.tsx
+++ b/src/renderer/nodes/SubagentNode.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from 'react'
+import { useEffect, useRef, useState } from 'react'
import { Handle, Position, type NodeProps } from '@xyflow/react'
import type { CanvasNode } from '../state/workspace'
@@ -24,7 +24,15 @@ export function SubagentNode({ data }: NodeProps<CanvasNode>) {
const tokens = data.subagentTokens as number | undefined
const toolUses = data.subagentToolUses as number | undefined
const result = (data.subagentResult as string) || ''
+ const activity = (data.subagentActivity as string) || ''
+ const body = activity || result
const [expanded, setExpanded] = useState(false)
+ const bodyRef = useRef<HTMLDivElement>(null)
+
+ // Auto-scroll the live transcript to the bottom as it grows (while expanded).
+ useEffect(() => {
+ if (expanded && bodyRef.current) bodyRef.current.scrollTop = bodyRef.current.scrollHeight
+ }, [body, expanded])
// Live elapsed timer while working.
const [now, setNow] = useState(() => Date.now())
@@ -61,13 +69,9 @@ export function SubagentNode({ data }: NodeProps<CanvasNode>) {
)}
{meta && <div className="subagent-node__meta">{meta}</div>}
{expanded && (
- <div className="subagent-node__result nodrag nowheel">
+ <div className="subagent-node__result nodrag nowheel" ref={bodyRef}>
{data.title ? <div className="subagent-node__result-task">{data.title as string}</div> : null}
- {result
- ? result
- : working
- ? 'Working… the subagent runs inside Claude; its output appears here when it finishes.'
- : 'No output.'}
+ {body || (working ? 'Working…' : 'No output.')}
</div>
)}
</div>
diff --git a/src/renderer/state/agentNodes.ts b/src/renderer/state/agentNodes.ts
index 5421335a3..4fb8eb0f3 100644
--- a/src/renderer/state/agentNodes.ts
+++ b/src/renderer/state/agentNodes.ts
@@ -21,6 +21,8 @@ export interface SubagentViz {
toolUses?: number
/** What the subagent produced (shown when the node is expanded). */
result?: string
+ /** Live transcript text streamed while the subagent runs (shown when expanded). */
+ activity?: string
}
export interface SubagentResult {
@@ -34,6 +36,8 @@ interface AgentNodesState {
byId: Record<string, SubagentViz>
start(toolUseId: string, viz: Omit<SubagentViz, 'state' | 'startedAt'>): void
finish(toolUseId: string, result: SubagentResult): void
+ /** Append a chunk of the subagent's live transcript. */
+ appendActivity(toolUseId: string, chunk: string): void
/** Remove all subagents spawned by a given parent node (turn/session ended, or node closed). */
clearForParent(parentNodeId: string): void
}
@@ -53,6 +57,14 @@ export const useAgentNodes = create<AgentNodesState>((set) => ({
return { byId: { ...s.byId, [toolUseId]: { ...prev, state: 'done', ...result } } }
}),
+ appendActivity: (toolUseId, chunk) =>
+ set((s) => {
+ const prev = s.byId[toolUseId]
+ if (!prev) return s
+ const activity = ((prev.activity ?? '') + chunk).slice(-12000) // keep the tail bounded
+ return { byId: { ...s.byId, [toolUseId]: { ...prev, activity } } }
+ }),
+
clearForParent: (parentNodeId) =>
set((s) => {
const ids = Object.keys(s.byId).filter((id) => s.byId[id].parentNodeId === parentNodeId)
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index c58c23ef2..815233906 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -15,6 +15,7 @@ export const IPC = {
appNotify: 'app:notify',
appFocusNode: 'app:focus-node',
claudeStatus: 'claude:status',
+ claudeSubagentActivity: 'claude:subagent-activity',
appUpdateAvailable: 'app:update-available',
appUpdateDownloaded: 'app:update-downloaded',
appRestartToUpdate: 'app:restart-to-update',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 66cde127a..b2b5ecbe6 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -332,6 +332,12 @@ export interface ClaudeStatusEvent {
result?: string
}
+/** A chunk of a subagent's live transcript, streamed while it works. */
+export interface SubagentActivity {
+ toolUseId: string
+ chunk: string
+}
+
export interface NodeTerminalApi {
pty: PtyApi
workspace: WorkspaceApi
@@ -355,4 +361,6 @@ export interface NodeTerminalApi {
onFocusNode(listener: (nodeId: string) => void): () => void
/** Fires on each Claude Code hook event (start/working/idle/attention). Returns unsubscribe. */
onClaudeStatus(listener: (e: ClaudeStatusEvent) => void): () => void
+ /** Fires with live subagent transcript chunks while a subagent runs. Returns unsubscribe. */
+ onSubagentActivity(listener: (e: SubagentActivity) => void): () => void
}