S16-03 - Around the Stream
Purpose: What wb writes to the terminal around the filtered stream, the
terminal environment the guest gets, and how guest text in wb’s
other output is escaped.
Design
Section titled “Design”Around the stream
Section titled “Around the stream”wb itself writes these to the terminal:
- the window title (“Title”);
- the reset on exit (“Reset on exit”);
- the
CSI ? 6 nsentinel query of the input drain (“Input drain”).
It writes them only when its standard output is a terminal. The drain also needs standard input to be one.
Standard error with frames of its own passes a filter of its own. When
it goes to a terminal and got output, it also gets that filter’s reset.
So wb claude -p … > out.txt in a terminal still resets what the
guest’s standard error changed, before the summary on standard error.
wb claude -p … > out.txt gets nothing else. Its output still passes
the filter (S16-01-filterS16-01-filter: FilterWhere wb filters guest output, how the filter splits it into tokens, and the allowlist of what passes., “Where”).
Before wb stops itself for job control, it writes the reset, drains
the input and restores the title too (S05-02-exit-status-and-signalsS05-02-exit-status-and-signals: Exit Status and SignalsWhat wb claude exits with, and what it does with each signal.,
“Job control”).
wbsaves the user’s window title on the terminal’s title stack (CSI 22 t).- It sets its own:
wb: <session id>, or the shell id forwb shell. - On exit it restores the saved one (
CSI 23 t).
A guest title would reach desktop notifications through the bell
(SEC14-no-fake-approvalsSEC14-no-fake-approvals: Approvals cannot be spoofed by the guestApproval prompts are never rendered in the agent's terminal stream.). iTerm2’s Notification Center alerts and
Ghostty’s bell-features = title do that.
Reset on exit
Section titled “Reset on exit”After the relay ends, and before wb prints anything, it resets what
the guest may have changed:
- colors and style;
- the alternate screen;
- mouse modes, bracketed paste, focus events and color scheme reports;
- synchronized output;
- cursor visibility and style;
- the scroll region and the character sets;
- the kitty keyboard stacks: the guest’s pushes popped, the alternate screen’s before leaving it;
modifyOtherKeys(CSI > 4 m) and the keypad mode (ESC >);- tab stops (
CSI ? 5 W); - the progress indicator;
- the program status records, with
OSC 7501 ; state=clear, when the guest sent a report (S16-01-filterS16-01-filter: FilterWhere wb filters guest output, how the filter splits it into tokens, and the allowlist of what passes., “Program status”).
When the guest left pushes on the alternate screen and then returned
to the main screen, wb visits the alternate screen to pop them, with
synchronized output on so the terminal doesn’t draw the visit.
Then it starts a new line. It doesn’t send ESC c, which can clear
the scroll-back.
Without the reset, the guest can print a fake summary in the
background color, and hide the real flags that SEC03-no-host-execSEC03-no-host-exec: No host code execution via returned workNothing the agent produces executes on the host without an explicit user action; returned changes to files the host may later execute are flagged.
relies on. The summary is advisory, and wb diff is authoritative.
Input drain
Section titled “Input drain”Before it restores cooked mode, wb:
- sends a sentinel query that the allowlist never passes:
CSI ? 6 n(extended cursor position); - reads and discards input until the reply of that form
(
CSI ? … R) arrives, or 100 ms pass.
Terminals answer in order. So every reply to a guest query comes
first, and a guest CSI 6 n can’t end the drain early. A late reply
to a guest query doesn’t reach the user’s shell.
Input to the guest is not filtered.
Environment
Section titled “Environment”The guest session gets these host variables, and no others:
TERM,TERM_PROGRAM,TERM_PROGRAM_VERSIONandCOLORTERM. Claude Code picks its sequences from these and from query replies.LANG,LC_ALLandLC_CTYPE. They keep the guest’s character encoding the same as the host’s, also on a host that setsLC_ALLorLC_CTYPEwithoutLANG.LC_ALLalso sets the formatting categories, as it does on the host.
These stay out:
- the other
LC_*variables, which set one formatting category each (LC_TIME,LC_NUMERIC, …); TMUXandSTY, which make Claude Code wrap sequences in DCS;SSH_*,TERMINFO,LC_TERMINALandITERM_SESSION_ID.
The window size crosses as resize messages.
Terminfo
Section titled “Terminfo”TERM crosses unchanged when the guest has a terminfo entry for it.
wb never maps it to another name. With the entry, what Claude Code
prints is the same as on the host.
Claude Code doesn’t read terminfo. Programs in the session such as
less, vim and top look TERM up in it. TERMINFO names a path
on the host, and doesn’t cross.
The guest looks TERM up in the terminfo database of its image
(S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Terminfo”). That database has ncurses’ entries,
and the names Ghostty and kitty set: xterm-ghostty and xterm-kitty.
The less, vim and top that macOS ships can’t read the kitty
entries (“macOS’s ncurses” below).
wb-guestd checks TERM before it starts a session of a project
user. When neither the image’s database nor the one macOS ships has an
entry of that exact name, the session gets TERM=xterm-256color
instead (I474I474 (closed): wb shell: the host's TERM has no terminfo in the guest (xterm-ghostty)wb shell passes the host's TERM to the guest unchanged (#471, S06-09-session-lifecycle).). An entry is a regular file in a directory of the
database, and a symbolic link doesn’t count. A session without TERM
gets none. The root shell of wb vm admin isn’t a project session,
and gets the host’s TERM unchanged.
A TERM that isn’t a terminfo name gets xterm-256color too: one with
a byte other than a letter, a digit, ., _, + and -, one that
doesn’t start with a letter or a digit, or one over 128 bytes.
wb-guestd never looks a value of that kind up, and a TERM can’t
name a path. Each replacement is logged with its rule,
shell-term-unknown or shell-term-malformed, and the value the host
sent. It doesn’t refuse the session.
macOS’s ncurses
Section titled “macOS’s ncurses”/usr/bin/less, vim and top link macOS’s own ncurses 6.0. It
can’t read an entry in the extended number format, which tic from
ncurses 6.1 or later writes for an entry with a number above 32767.
kitty and xterm-kitty (pairs#0x10000) are among them.
- Those programs report an unknown terminal for kitty.
- Programs that link Homebrew’s ncurses read the entry.
- For a name macOS ships, such as
xterm-256color, macOS’s ncurses skips the file it can’t read, and uses its own copy.
This was measured on a macOS 27 host with ncurses 6.6 (I83I83 (closed): Guest terminfo for the host TERM passed into the sessionS05-cli ("Terminal stream", #81) passes the host's TERM into the guest session, because Claude Code picks its sequences from it.). I203I203 (closed): Guest terminfo: xterm-kitty unreadable by macOS's own ncursesSo a kitty user running less or vim from /usr/bin in wb shell still gets no terminfo entry.
decides whether xterm-kitty gets an entry macOS can read.
Guest text elsewhere
Section titled “Guest text elsewhere”wb prints text the guest influenced in other places too:
- the id in the window title;
- the session summary and its link list;
- the
wraith box:line of a failure; wb diff,wb sessions,wb approve,wb audit,wb learn reportandwb status.
There it never passes a code point of the escaped set:
- a control: Unicode category Cc, which holds
ESC, and so every escape sequence; - a format character (Cf), such as the bidirectional controls and the zero-width characters;
- a line or paragraph separator (Zl, Zp);
- a
Default_Ignorable_Code_Point, such as the tag characters, the variation selectors and the Hangul fillers.
wb diff, logs and audit records show them escaped, where a reviewer
sees them. S09-11-auditS09-11-audit: AuditWhat the audit log records, the budgets that bound it, and what happens when the log can't be written. gives the form for audit records. Other output
removes them (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC14-no-fake-approvalsSEC14-no-fake-approvals: Approvals cannot be spoofed by the guestApproval prompts are never rendered in the agent's terminal stream.).
The wraith box: line speaks for Wraith Box, after the reset. So
wb-hostd never passes on a failure message from wb-guestd as the
guest wrote it. It words a failure by its rule itself, or quotes the
guest’s message, stripped, as the guest reported: "<message>". A
" or \ in the message gets a backslash in front, so the guest
can’t end the quote and write on as Wraith Box.
Decisions
Section titled “Decisions”Write around the stream only to a terminal
Section titled “Write around the stream only to a terminal”What wb writes around the stream needs standard output to be a
terminal, and the drain also standard input.
- Decided: I37I37 (closed): S03-requirements, S05-cli: treat the host terminal stream as a boundarywb claude relays the guest's PTY output in raw mode to the user's terminal emulator (S05-cli)., 2026-10-06.
Reset on exit, not an alternate screen
Section titled “Reset on exit, not an alternate screen”wb resets the terminal on exit.
- Rejected: running the session on an alternate screen of
wb’s own. That resets everything, but doesn’t leave the session’s output in the scroll-back, unlikeclaude(FR01-drop-inFR01-drop-in: Drop-in for claudewb is the single entry point for everything, structured as wb [wb flags] <command> [command args].). - Decided: I37I37 (closed): S03-requirements, S05-cli: treat the host terminal stream as a boundarywb claude relays the guest's PTY output in raw mode to the user's terminal emulator (S05-cli)., 2026-10-06.
Replace a TERM the guest has no entry for
Section titled “Replace a TERM the guest has no entry for”wb-guestd gives a session xterm-256color for a TERM the guest
lacks. Without it, clear reports an unknown terminal, and zsh’s line
editor draws a typed line twice.
- Why: the check runs in the guest, next to the database. The host doesn’t keep a list of the image’s entries. The fallback only narrows the value.
- Cost: Claude Code in such a session picks its sequences for
xterm-256color, not for the host’s terminal. - Rejected: keeping
TERMunchanged (I83I83 (closed): Guest terminfo for the host TERM passed into the sessionS05-cli ("Terminal stream", #81) passes the host's TERM into the guest session, because Claude Code picks its sequences from it.), which leaves those programs impaired. - Decided: I474I474 (closed): wb shell: the host's TERM has no terminfo in the guest (xterm-ghostty)wb shell passes the host's TERM to the guest unchanged (#471, S06-09-session-lifecycle)., 2026-10-31. I669I669 (open): Image build: terminfo for Ghostty, kitty, WezTerm, Alacritty and foot from ncurses, and TERMINFO_DIRS for project usersPackage IMG.5 of docs/implementation-plan.md, part 3 of 5 (IMG.5c). adds entries for more terminals to the image.
Status: Draft