Rudder
article 04 · terminal & harness runtime 2026-12-01 · 11 min read · rust pty · vt100 · osc 7501/777

Four Harnesses, One Terminal Engine: Multiplexing Claude Code, Codex, Gemini Antigravity, and OpenCode Over Live PTYs

Wrapper GUIs usually force an ugly choice: run coding agents in headless JSON mode and lose interactive TUI slash commands, terminal attachment, and subscription logins, or run raw PTYs and scrape brittle ANSI regexes. Rudder runs every harness inside a real interactive PTY while fusing four structured telemetry channels into one single-writer Rust state machine.

source native/src/pty_terminal.rs native/src/detect.rs native/src/delivery.rs native/src/permission_hook.mjs cloud/worker/asks.mjs

Why headless print modes fall short for power users

Almost every coding CLI offers a non-interactive flag (claude -p, codex exec, agy -p, opencode run). Building a wrapper around one-shot subprocesses is easy, and immediately costs you the features that make each harness great:

  • Interactive attachment: You can never press Enter to jump directly into the live terminal pane to run /login, inspect an interactive debugger, or use harness-native TUI pickers.
  • Mid-turn steering and queuing: In a live TUI, typing a correction while the model is running tools steers the current turn without tearing down process state or re-warming prompt caches.
  • Live prompt geometry: Subscription rate-limit menus, sandbox escalation prompts, and multi-question wizards render interactively on the terminal grid before they ever hit disk logs.

Rudder therefore keeps every local and Cloud agent inside an authentic Unix pseudo-terminal managed by native/src/pty_terminal.rs (up to MAX_OWNED_PTY_CHILDREN = 512 concurrent panes), while maintaining a strict single-writer invariant: only the central App loop owns PTY handles and mutates agent state.

Backpressure-bounded PTY readers and 4 ms UI frame budgets

When ten parallel agents run verbose Cargo builds or dump JSON fixtures to stdout simultaneously, an unbounded channel between reader threads and the UI loop will balloon resident memory to gigabytes and freeze keystroke handling. pty_terminal.rs enforces deterministic bounds at both ends of the pipe:

const PTY_READ_CHUNK_BYTES: usize = 8192;
const MAX_PTY_QUEUED_CHUNKS: usize = 32;
const MAX_PTY_DRAIN_BYTES: usize = 64 * 1024;
const PTY_DRAIN_BUDGET: Duration = Duration::from_millis(4);
const OUTPUT_BACKPRESSURE_POLL: Duration = Duration::from_millis(5);
  • Kernel-propagated backpressure: Each reader thread reads 8 KiB chunks into a bounded mpsc::sync_channel(32) (256 KiB in flight per pane). When full, enqueue_output sleeps in 5 ms increments without blocking any UI lock, allowing backpressure to propagate naturally through the kernel PTY slave buffer to the child process.
  • Frame-budgeted draining: On the main loop, draining output into the vt100 parser stops after 64 KiB or 4 ms per tick so 60 fps scrolling and keyboard input stay instantaneous even under heavy log floods.
  • Graceful exit drain: When a child exits, Rudder holds a 2s EXIT_OUTPUT_GRACE window on the readiness pipe so trailing panic traces or quota messages buffered in the kernel slave fd are never truncated.

Answering OSC 10/11 color queries on the reader thread

Modern TUI harnesses (especially OpenCode's Bubble Tea / OpenTUI renderer and Codex's ratatui startup probe) emit OSC 10 ; ? ST, OSC 11 ; ? ST, and DSR cursor queries during their first 50 milliseconds to detect light vs. dark terminal themes. To save CPU, Rudder drains unfocused background agent panes every 500 ms instead of every frame.

If OSC queries waited for the main loop's 500 ms unfocused drain, every background agent would time out its startup theme probe, stall launch by 1-2 seconds, and fall back to broken ANSI contrast. PtyReaderWork::run solves this by running QueryScanner byte-at-a-time directly on the reader thread the instant bytes leave read(2), writing the RGB response straight to the shared reply_writer mutex in microseconds.

Claude Code PermissionRequest + OSC 7501 OpenAI Codex rollout-*.jsonl + notify hook Gemini Antigravity (agy) conversations/*.db + transcript OpenCode opencode_plugin.mjs + SQLite Single-Writer PTY Engine • QueryScanner (OSC 10/11) • vt100 grid + scrollback • detect.rs InputBlock gate • delivery.rs receipt check • asks.mjs structured cards Mac · Web · iPhone UI Live chat & subagent steps 1-tap permission & ask cards Zero-loss TUI attach
Rudder fuses live PTY terminal state with sideband hooks and on-disk session logs so UI actions never guess blindly.

Four harnesses, four sideband protocols, one state machine

Terminal screen scraping alone cannot distinguish a model thinking silently for 40 seconds from a hung socket, nor can it extract structured multiple-choice options cleanly on a narrow phone screen. Rudder pairs the vt100 screen grid with harness-specific sideband hooks:

Harness Lifecycle & Turn Signal Interactive Ask / Permission Plane Transcript Store
Claude Code Injected hooks emitting custom OSC 7501 state transitions + JSON signal files permission_hook.mjs holds HTTP/FIFO wait open while user taps Allow/Deny or answers AskUserQuestion on phone ~/.claude/projects/.../*.jsonl
OpenAI Codex notify hook + live tail of event_msg / task_complete records request_user_input parsed from rollout events; answered by numbered PTY keystrokes ~/.codex/sessions/.../rollout-*.jsonl
Gemini Antigravity transcript.jsonl step statuses (PLANNER_RESPONSE, CHECKPOINT, background tasks) ask_question tool call extracted with options + recommended badge; answered via numbered choice or freeform steer conversations/<cid>.db + brain/<cid>
OpenCode opencode_plugin.mjs subscribes to internal bus events & writes atomic state snapshots Native REST reply against OpenCode's ephemeral loopback server (/question/:id/reply) ~/.local/share/opencode/opencode.db (WAL)

Why a PTY write is not a delivery receipt

One of Rudder's core invariants in AGENTS.md is: "A message write is not an agent acknowledgment." When you send a message from your iPhone into a busy CLI over a PTY, writing [200~...text...[201~ to the master file descriptor only proves the kernel accepted the bytes. If the TUI had an autocomplete popup open, swallowed the trailing carriage return during a render frame, or wrapped a multi-line paste into a collapsed chip, the prompt sits unsubmitted in the input box.

native/src/delivery.rs treats every steer as an unconfirmed intent until verified against transcript growth or TUI submission state, recording structured diagnostics to steer-receipts.jsonl whenever an attempt stalls. Studying 1,217 real production steer receipts across all four harnesses uncovered a subtle example of why empirical trace analysis matters: 60.4% of reported not_submitted receipts on Claude Code were false negatives caused by Claude wrapping multiline pastes and attachment paths inside <pasted_content id="XXXX">...</pasted_content> tags in its JSONL log while our matcher compared against raw unwrapped text. Normalizing pasted-content envelopes in the transcript verifier eliminated the phantom retry warnings immediately.

Before injecting bracketed-paste keystrokes, detect.rs runs terminal_composer_blocked(backend, visible_lines) so Rudder never types a paragraph into an open slash-command picker or permission dialog (InputBlock::MenuOpen / InputBlock::PermissionPrompt).

Getting that classifier wrong in either direction hurts: miss a real menu and keystrokes corrupt the picker; trigger a false positive and the Mac/iPhone app refuses to send messages with "A menu is open in the agent's terminal" while the agent is simply thinking. On Gemini Antigravity, active turns and background subagents render inline hints like Thinking... (12s · esc to cancel) or esc to clear directly above the composer rule. Scoping "esc to cancel" menu heuristics per harness in detect.rs, while explicitly routing Antigravity's numbered ask_question prompt to PermissionPrompt, keeps mid-turn steering unblocked without sacrificing modal safety.

Coalesced Mac and iPhone notifications from live agent signals

Running six agents in parallel only works if you can walk away from the terminal without constantly tabbing through panes to check whether one hit a permission prompt, asked a clarifying question, exhausted a 5-hour rate window, or finished its task. Most Claude Code notification scripts glue a shell bell or raw webhook onto a single hook, flooding macOS Notification Center with duplicate banners that linger long after you already answered the prompt.

Because Rudder's state engine already computes exact needsYou transitions and live -> done completions across all four harnesses, cloud/app/notifications.js, mac/App/AppModel.swift, and ios/App/DigestReminder.swift share one deterministic notification protocol across Mac, iPhone, and desktop browsers:

  • Deterministic per-agent identifiers (rudder.agent.<ws>.<run>): Repeated status updates for the same agent coalesce in place inside macOS and iOS Notification Center instead of stacking duplicate banners, grouped per repository via threadIdentifier = "rudder.project.<ws>".
  • Automatic dismissal on read or resolution: Opening the chat on any surface or answering the prompt triggers removeDeliveredNotifications(withIdentifiers:) immediately so Notification Center never holds stale prompts.
  • Window-closed Mac menu bar & iPhone background grace polling: Closing the Rudder Mac window hands notification authority cleanly from the active web view to the lightweight menu bar poller (eliminating double banners when the window is open while still alerting on both Agent needs you and Agent finished when closed). On iPhone, entering the background starts a beginBackgroundTask watch loop alongside the 9:01 AM daily digest, deep-linking straight to /app/p/<ws>/a/<run> on tap.

Attach to the raw TUI or steer from structured chat.

Switch seamlessly between full-fidelity terminal panes on macOS and clean structured cards, diffs, and one-tap approvals on your iPhone.

$ npm install -g @exla/rudder@latest