Skip to content

S16-01 - Filter

Purpose: Where wb filters guest output, how the filter splits it into tokens, and the allowlist of what passes.

The filter runs on every stream that wb claude, wb shell or wb vm admin (S15-05-admin-pathS15-05-admin-path: The Admin PathHow the person at the host's terminal gets a root shell in their own guest, on a path that no agent, session, or guest process can start or reach.) writes to a terminal. On WSL that is the WSL-side wb, which writes to the terminal (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.).

A stream that goes to a pipe or a file passes the same full filter. Scripts read such a stream (claude -p), and a later | cat puts it on the terminal. The filter passes only output that is safe in a terminal, so a later cat of the file is as safe as the live session.

The filter passes text, Markdown and JSON unchanged when they:

  • are valid UTF-8;
  • don’t hold a control character that the allowlist below drops: C1, DEL, or a C0 control other than the ones it passes.

Invalid bytes become U+FFFD, so binary output through standard output isn’t supported. If moving files out of the guest is ever needed, it gets its own command, not an unfiltered stream.

The filter’s output is for a terminal that reads UTF-8. On a terminal that reads 8-bit bytes, some bytes inside a valid character act as C1 controls, 0x9B among them. So wb reads the host terminal’s charset before it relays a guest terminal stream. A charset other than UTF-8 refuses the session, with the rule terminal-charset-not-utf8 (I341I341 (closed): wb: refuse or warn when the host terminal's charset isn't UTF-8The terminal filter writes UTF-8 for a terminal that reads UTF-8 (S16-01-filter, "Where").):

  • on macOS and Linux, the charset is that of the first of LC_ALL, LC_CTYPE and LANG that is set and not empty, as setlocale reads them. None set is the C locale, which isn’t UTF-8;
  • on Windows, the charset is the console output code page. Until the relay runs there, the read fails, and wb refuses.

The refusal comes before any guest byte reaches the terminal, and nothing overrides it (S05-01-agent-commandsS05-01-agent-commands: Agent CommandsHow wb claude passes its arguments to Claude Code, how it runs interactive and non-interactive sessions, and what a session does., “A terminal that isn’t UTF-8”).

The filter splits the stream into text, controls and sequences. It passes a token only when a rule below allows it.

It drops any other token whole, from its ESC to its end. The terminal’s parser is then back in its ground state after every token.

It never escapes a dropped sequence into visible text, which would move what the TUI drew.

  • A CSI ends at its final byte (@ to ~).
  • Any byte that isn’t a parameter, intermediate, or final byte ends a CSI early. The CSI is dropped, counted as terminal-csi, and the byte begins the next token, unless that byte is CAN or SUB. So no token the filter passes holds a control inside a CSI.
  • A string sequence (OSC, DCS, APC, PM, SOS) ends at ST, written as ESC \ or as U+009C. An OSC also ends at BEL.
  • CAN and SUB end any sequence, and are dropped with it.
  • An ESC inside a string sequence that doesn’t start ST also ends it, and then begins the next token.

An OSC the filter passes keeps its terminator when that is BEL or ESC \. One that ended with U+009C is written with ESC \ instead, because a terminal that doesn’t read U+009C as ST would take the bytes after it as the payload.

The filter buffers at most 64 bytes of an unfinished CSI, and 16 KB of an unfinished string sequence. Past that it discards everything up to the sequence’s end, counted as one drop. So the tail of a long payload never shows as text.

Each drop is counted by rule, and the session summary reports the counts (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). A sequence that a new Claude Code version starts to use shows up there (S16-02-drops-and-linksS16-02-drops-and-links: Drops and LinksThe fixed rules that drops are counted by, and how wb records the links the filter drops., “Drop rules”).

Class Passes Dropped
Text valid UTF-8 C1 controls (U+0080 to U+009F); invalid bytes become U+FFFD
C0 controls, DEL BEL (at most one per second), BS, HT, LF, CR, SI the rest, DEL included
ESC 7, 8, M, D, E, =, >, ( B, ( 0, ) B, ) 0 the rest, ESC c included
CSI parameters digits, ; and :, at most 16 values of at most 5 digits, 64 bytes in all any other
CSI screen A to H, f, `, a, d, e, @, L, M, P, X, b, S, T, r, I, Z, g, m; J and K with 0 to 2; s and u without parameters CSI 3 J, which erases the host’s scroll-back
CSI modes ? h/l for 25, 1000, 1002, 1003, 1004, 1006, 1016, 1049, 2004, 2026, 2031; ? … $ p (mode query) for those modes other modes
CSI keyboard kitty keyboard > u (push, at most 4 deep per screen), < u (pop, only entries the guest pushed on that screen), ? u; > 4 ; 2 m and > 4 m; SP q = u, which changes the current entry in place; other > m; ! p (soft reset), because kitty then clears the user’s kitty keyboard stacks and a terminal may turn line wrap off
CSI queries c, > c, 5 n, 6 n, > q, 14 t, 16 t, 18 t other t: window moves, title reports, the title stack
OSC 9 ; 4 (progress) with numeric parameters; 10, 11, 12 with ? only; 7501 (program status) as “Program status” says; 9, 99 and 777 (notifications) become one BEL the rest: 0 to 2 (title), 8 (links), 52, 1337, 7, 133, …
DCS, APC, PM, SOS all, whole

The list is the one X19-terminal-filterX19-terminal-filter: Terminal stream filteringWhich terminal escape sequences does Claude Code emit, and can wb drop the ones that act on the host (clipboard writes, file transfer, terminal multiplexer control sequences) without visible damage in the common macOS… measured with Claude Code 2.1.289, tightened as the security review of PR66PR66 (merged): docs(spikes): X19-terminal-filter result, yes with conditionsAnswer: yes, with conditions, for Ghostty and Terminal.app, as far as a headless emulator can show. asked:

  • modes the recordings don’t hold are left off;
  • each cap is above the largest value recorded.

The soft reset ! p left the list later (I345I345 (closed): wb: kitty clears the user's kitty keyboard entry on a guest's soft resetThe filter passes CSI !).

OSC 10 to 12 queries stay, because the Claude Code binary holds the background color query.

OSC 7501 joined after I62I62 (closed): X19-terminal-filter: visual check in real terminalsSplit from #30 (X19-terminal-filter) during triage on 2026-10-04. saw Claude Code 2.1.296 send its query at every start (I270I270 (closed): S16-terminal-stream: bare guest paths become host links in Ghostty, and the OSC 7501 probe counts as a dropFound in the check by eye for #62 (X19-terminal-filter), 2026-10-16.).

Queries pass because the reply goes to the guest. Claude Code uses them to learn what the terminal supports. What a reply tells the guest is T09-terminal-fingerprintT09-terminal-fingerprint: Host terminal facts in the guestThe guest learns the host terminal's name and version, its colors, the window size in cells and pixels, the state of its modes, and which program states it shows, from the replies to the queries S16-terminal-stream pa….

The kitty keyboard protocol keeps one stack per screen. So wb counts the guest’s pushes on the main and the alternate screen apart. It drops a pop that would reach an entry the user’s shell pushed.

OSC 7501 is the Program Status Protocol. A program reports whether it is working, waiting on the user, or done, and the terminal may show that outside the window, for example as a notification. Claude Code 2.1.295 and later ask OSC 7501 ; ? at start, and send reports only when the terminal answers.

The filter passes the query ? as it is. It rebuilds a report from these pairs only:

Key Value
state idle, working, done, blocked, error or clear; required
id 1 to 8 segments of 1 to 32 characters from A-Z, a-z, 0-9, _ . + -, joined by /; at most 128 bytes
kind permission, question or auth
progress an integer from 0 to 100
app 1 to 32 characters from A-Z, a-z, 0-9, _ . + -

The terminal’s answer to the query names the states and kinds it supports, and goes to the guest (T09-terminal-fingerprintT09-terminal-fingerprint: Host terminal facts in the guestThe guest learns the host terminal's name and version, its colors, the window size in cells and pixels, the state of its modes, and which program states it shows, from the replies to the queries S16-terminal-stream pa…). The protocol has no other reply.

These never join the list:

  • the title report (CSI 21 t);
  • OSC 52 with ?;
  • DECRQSS (a DCS).

Each makes the terminal type guest-chosen text back into its input. That text would reach the user’s shell after wb exits.

A stream that goes to a pipe or a file passes the same full filter as terminal output.

OSC 7501 passes with state, id, kind, progress and app, and without title and msg.

Status: Draft