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.

fix(chat): find Claude's input box above the background-agent list

Paul Robertson0984dd3ebdba
diff --git a/CLAUDE.md b/CLAUDE.md
index 839a4f8b0..2ee6b36d8 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -4454,6 +4454,11 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile
re-reads at once; unknown focus polls), to disable the composer and show the dialog's lines; SSH and relay panes are not polled (a round trip per read) and rely
on the send-time check. Another CLI's layout would read as a permanent dialog, so an agent joins
the list only with its own measured reader.
+ The live box must end within `BOX_TAIL_LINES` (8) non-blank lines of the bottom, so an old box in
+ the history is not taken for it; the agent list Claude Code draws under its status lines while
+ background agents or teammates run (`● main`, `○ <name> …` rows, `↓ N more`; measured on 2.1.319)
+ does not count toward those lines (`isAgentListLine`). Before that, five agents were enough for the
+ view to say the input box was not on screen.
**Live progress (2026-09).** While the agent works, a `role=status` row closes the thread (the ONE
spinner + the placeholder's own "<agent> is working…"/"waiting for an answer" sentence; optimistic
right after a send, bounded by `CHAT_OPTIMISTIC_WORKING_MS`), and every hook event re-reads the
diff --git a/src/shared/agents/claude-screen.test.ts b/src/shared/agents/claude-screen.test.ts
index 1ef157cc5..f3c1c4de6 100644
--- a/src/shared/agents/claude-screen.test.ts
+++ b/src/shared/agents/claude-screen.test.ts
@@ -102,6 +102,35 @@ describe('readClaudeScreen', () => {
expect(readClaudeScreen(screen)).toEqual({ kind: 'prompt' })
})
+ it('reads the input box as a prompt above the agent list background agents add', () => {
+ // Field shape (2.1.319): two status lines, then one row per agent and an overflow line, which
+ // together pushed the box past the status-line allowance.
+ const statusline = [' 🧠 Opus 5.5 | ┤██▒ ├ 27% | 💰 $1.23', ' ⏵⏵ auto mode on (shift+tab to cycle)']
+ const agents = [
+ '● main',
+ '○ worker-1 Implement ticket 01 (place… idle',
+ '○ worker-2 Implement ticket 02 (squar… idle',
+ '○ worker-4 Implement ticket 04 (P+P C… 3m 36s · ↓ 193.7k tokens',
+ '○ worker-5 Implement ticket 05 ({L+P}… 19m 17s · ↓ 228.6k tokens',
+ '○ worker-3 Implement ticket 03 (squar… 11m 52s · ↓ 151.8k tokens',
+ '↓ 1 more'
+ ]
+ const scrolled = [...agents.slice(0, -1), '↑ 2 more · ↓ 1 more']
+
+ const screen = (list: string[]) => [...HEADER, RULE, '❯ ', RULE, ...statusline, '', ...list].join('\n')
+
+ expect(readClaudeScreen(screen(agents))).toEqual({ kind: 'prompt' })
+ expect(readClaudeScreen(screen(scrolled))).toEqual({ kind: 'prompt' })
+ })
+
+ it('still ignores an input box left in the history when only agent-list-like lines are under it', () => {
+ const shellOutput = Array.from({ length: 9 }, (_, i) => `line ${i}`)
+
+ const gone = [IDLE, '● main', '○ worker-1 idle', ...shellOutput, 'user@host ~ % '].join('\n')
+
+ expect(readClaudeScreen(gone)).toEqual({ kind: 'no-prompt' })
+ })
+
it('a dialog ABOVE a visible input box is still a dialog — the footer decides', () => {
const above = [...HEADER, ' Set up auto mode defaults?', ' ❯ Yes', ' No', ' Enter to confirm · Esc to cancel', RULE, '❯ ', RULE, ...STATUS].join('\n')
diff --git a/src/shared/agents/claude-screen.ts b/src/shared/agents/claude-screen.ts
index 555a69f66..f5081bb5a 100644
--- a/src/shared/agents/claude-screen.ts
+++ b/src/shared/agents/claude-screen.ts
@@ -46,8 +46,24 @@ const isFooter = (line: string): boolean => {
}
/** Non-blank lines allowed under the box's bottom rule — the status lines (a custom statusline can
- * take several). */
+ * take several). The agent list below them does not count (`isAgentListLine`). */
const BOX_TAIL_LINES = 8
+/** At most this many agent-list lines are skipped, so an old box far up the history still is not
+ * taken for the live one. */
+const AGENT_LIST_MAX_LINES = 40
+
+/**
+ * A line of the agent list Claude Code draws UNDER its status lines while background agents or
+ * teammates run (MEASURED on 2.1.319, field screenshot + binary): one row per agent, starting with its
+ * status dot — `● main` for the one in view, `○ <name> <task> <state>` for the rest — and, when the
+ * list is longer than the space it gets, an overflow line `↓ 3 more` (`↑ 2 more · ↓ 3 more` once
+ * scrolled). With a few agents it pushed the input box past `BOX_TAIL_LINES` and the ⌘M view read the
+ * screen as having no input box.
+ */
+const isAgentListLine = (line: string): boolean => {
+ const t = line.trim()
+ return /^[●○] \S/.test(t) || /^(?:↑ \d+ more(?: · ↓ \d+ more)?|↓ \d+ more)$/.test(t)
+}
/** A footer with no box: a dialog's key hints are its last line (measured: trust prompt, /model). */
const FOOTER_TAIL_LINES = 3
/** A footer above a live box: a dialog drawn right on top of the input box. */
@@ -64,7 +80,18 @@ const nonBlankFromBottom = (lines: readonly string[]): number[] =>
/** The live input box: `[top rule, bottom rule]` line indexes, or null. */
function inputBox(lines: readonly string[]): [number, number] | null {
- const tail = nonBlankFromBottom(lines).slice(0, BOX_TAIL_LINES + 1)
+ // The bottom lines a box may end on: the first BOX_TAIL_LINES + 1 non-blank lines from the bottom,
+ // not counting the agent list's lines (up to AGENT_LIST_MAX_LINES of them).
+ const tail: number[] = []
+ let listLines = 0
+ for (const i of nonBlankFromBottom(lines)) {
+ if (tail.length > BOX_TAIL_LINES) break
+ if (isAgentListLine(lines[i]) && listLines < AGENT_LIST_MAX_LINES) {
+ listLines++
+ continue
+ }
+ tail.push(i)
+ }
for (const bottom of tail) {
if (bottom === 0 || !isRule(lines[bottom])) continue
for (let top = bottom - 1; top >= 0 && bottom - top <= 40; top--) {