Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(team): wait out Claude Code's stdin reset before typing the prompt

Jack Rudenkob119b54803ca
diff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.md
index 8ec873bd..c18e46ed 100644
--- a/ai-docs/architecture/pane-session.md
+++ b/ai-docs/architecture/pane-session.md
@@ -115,13 +115,20 @@ route: a pane child receives every prompt the way a user gives it — typed, pas
## Boot: read from screen content, and never accept a dialog
Boot is ready when the screen shows the REPL input box — a full-width `─` rule, a row starting
-`❯` + U+00A0, a second rule — with nothing typed, for 500 ms. Placeholder text in the box carries
+`❯` + U+00A0, a second rule — with nothing typed, for 3 s (`REPL_STABLE_MS`). Placeholder text in the box carries
magmux attribute 2 (faint) and does not count as typed. Under `--agent` the top rule carries the
agent's name at its right end (`──── dev:reviewer ─`); `isBoxRule` accepts that one label, and
until 10.4.2 it did not, so every slot given an `agent` failed `boot_timeout` at 90 s with a ready
box on screen (fixture `repl-boot-agent`). Measured spawn → empty box: 0.67–1.97 s
with catalog warm-up off; the ≈11 s of earlier research included claudish's 4–7 s catalog warm-up.
+**Why 3 s and not 500 ms.** Claude Code draws the box and then, 1–2 s later, resets stdin (a
+termios cooked→raw blip). A line typed into that window is lost or sits in the box unsubmitted, in
+normal editor mode as well as vim. Measured 2026-10-16 (Claude Code 2.1.301, magmux 0.15.1, magmux
+owner): with the box stable for 500 ms and `--settings {"editorMode":"normal"}`, 2/2 team slots
+failed `prompt_not_accepted`, the retry failed one, and the third try got through. A stable box is
+not proof the child reads its input, so boot waits the reset out; the cost is ≈2.5 s per boot.
+
What blocks boot is decided by **"no input box"**, and named by a closed list:
| screen (static 5 s, no input box) | outcome |
@@ -319,8 +326,13 @@ magmux refused it (`busy`, `pane_*`) or it was never written; when the REPLY was
(`client_timeout`, `client_lost`) magmux may already have typed it, so the next frame decides: the
line in the box (or, for an Enter send, its witness or echo) means it landed (`send_reply_lost`), and
only an empty box is typed again — a blind retry put the line in the box twice and no witness could
-match. With no witness 10 s after delivery, a line still in the box gets one more Enter
-(`resent_enter`). A panel command (`/cost`, `/usage`, `/config`: a full-screen panel, no record,
+match. With no witness 10 s after delivery, a line still in the box is cleared with ctrl-u, retyped
+once and submitted (`resent_enter`, then `retyped_prompt`): a line typed into the startup stdin
+reset (Boot, above) may show in the box without the child holding it as input, so a bare
+second Enter cannot be relied on to submit it. If ctrl-u left the line in
+place the remedy is one more Enter, and a box left holding anything else is `clear_failed` — a
+second copy is never typed. The retyped line is the same line, so the witness and read coverage
+are unchanged. A panel command (`/cost`, `/usage`, `/config`: a full-screen panel, no record,
input swallowed until Esc) gets an Esc 500 ms after delivery (`panel_dismissed`), and once the empty
box is back its admission ends without a turn (`panel_command`); it used to wait the 30 s bound and
was then taken as a degraded acceptance. The prompt a session was CREATED with must be accepted
diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.ts
index bae45176..2076e3be 100644
--- a/packages/cli/src/pane/pane-session.ts
+++ b/packages/cli/src/pane/pane-session.ts
@@ -120,8 +120,14 @@ export const DEGRADED_ENTRY_MS = 10_000;
export const SCREEN_SETTLE_QUIET_MS = 3_000;
/** A panel command's screen must have been up this long after delivery before Esc. */
const PANEL_SETTLE_MS = 500;
-/** The REPL box must read empty this long before boot is ready. */
-const REPL_STABLE_MS = 500;
+/**
+ * The REPL box must read empty this long before boot is ready. Claude Code draws its
+ * input box and then, 1–2 s later, resets stdin (a termios cooked→raw blip); a prompt
+ * typed into that window is lost or never submitted, in vim and normal editor mode
+ * alike. Measured 2026-10-16 (Claude Code 2.1.301, magmux 0.15.1): at 500 ms, 2/2 team
+ * slots failed `prompt_not_accepted`. 3 s waits the reset out.
+ */
+export const REPL_STABLE_MS = 3_000;
/** A dialog or choice screen static this long blocks boot. */
const BOOT_STATIC_MS = 5_000;
const TICK_MS = 250;
@@ -949,8 +955,12 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
}
private async deliver(adm: Admission): Promise<void> {
- const plan = adm.plan;
- if (plan.mode !== "typed" && plan.mode !== "file" && plan.mode !== "command") return;
+ if (await this.typeAndSubmit(adm.plan)) adm.deliveredAt = Date.now();
+ }
+
+ /** Type the plan's line and submit it. False for a plan with nothing to type. */
+ private async typeAndSubmit(plan: Delivery): Promise<boolean> {
+ if (plan.mode !== "typed" && plan.mode !== "file" && plan.mode !== "command") return false;
if (plan.mode === "command") {
await this.typeLine(plan.line, false);
await this.nextFrame(500);
@@ -961,7 +971,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
} else {
await this.typeLine(plan.line, true);
}
- adm.deliveredAt = Date.now();
+ return true;
}
/**
@@ -1082,16 +1092,34 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
return true;
}
- /** +10 s without a witness: the line still in the box → Enter again; a panel → Esc. */
+ /**
+ * +10 s without a witness: the line still in the box → clear it, retype it once and
+ * submit; a panel → Esc. The line sits unsent when it was typed into Claude Code's
+ * startup stdin reset (see `REPL_STABLE_MS`), where a bare second Enter cannot be relied
+ * on to submit it. Ctrl-U clears the box (phase2-captures keylog). The same line is
+ * retyped, so the turn's witness and read coverage are unchanged.
+ */
private nudge(adm: Admission): void {
const box = inputBox(this.screen);
const line = adm.plan.mode === "control" || adm.plan.mode === "refused" ? "" : adm.plan.line;
- if (!adm.resent && box && line && box.text.startsWith(line.slice(0, 40))) {
+ const head = line.slice(0, 40);
+ if (!adm.resent && box && line && box.text.startsWith(head)) {
adm.resent = true;
this.anomaly("resent_enter");
void (async () => {
if (box.menuOpen) await this.key("escape");
- await this.key("enter");
+ await this.key("ctrl-u");
+ await this.nextFrame(500);
+ const after = inputBox(this.screen);
+ if (after && after.text === "") {
+ this.anomaly("retyped_prompt");
+ await this.typeAndSubmit(adm.plan);
+ } else if (after?.text.startsWith(head)) {
+ // Ctrl-U did not take: the old remedy, one more Enter. Never type a second copy.
+ await this.key("enter");
+ } else {
+ this.anomaly("clear_failed");
+ }
})();
return;
}