@devries-cameron20 / t3code-1 / commits / 73e49aa6cd
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): terminal history strips queries with embedded controls (#36027)

Julius Marminge committed Nov 12, 2026 at 22:12 UTC 73e49aa6cd605e27c0b9cd70ea8d26483220dc4c
2 files changed +40 -5
apps/server/src/terminal/Manager.test.ts
+22
@@ -1419,6 +1419,28 @@ it.layer(
1419 }),
1420 );
1421
1422 + // Ghostty executes 0x00-0x0F inside a CSI and ignores DEL and 0x10-0x1F; none change the query.
1423 + it.effect.each([
1424 + { name: "NUL in DA", data: "A\u001b[0\u0000cB", history: "AB" },
1425 + { name: "DEL in DA", data: "A\u001b[0\u007fcB", history: "AB" },
1426 + { name: "NUL in DECRQM", data: "A\u001b[?2026\u0000$pB", history: "AB" },
1427 + { name: "CR in DSR", data: "AB\u001b[5\rnC", history: "AB\rC" },
1428 + { name: "DLE in DSR", data: "AB\u001b[5\u0010nC", history: "ABC" },
1429 + ])(
1430 + "strips a query with an embedded control but keeps what the terminal ran ($name)",
1431 + ({ data, history }) =>
1432 + Effect.gen(function* () {
1433 + const { manager, ptyAdapter } = yield* createManager();
1434 + yield* manager.open(openInput());
1435 + ptyAdapter.processes[0]!.emitData(data);
1436 + yield* manager.close({ threadId: "thread-1" });
1437 +
1438 + const reopened = yield* manager.open(openInput());
1439 + const restored = reopened.history.replaceAll("\u0000", "");
1440 + expect(restored.split("\u001b[?1049h")[0]).toBe(history);
1441 + }),
1442 + );
1443 +
1444 it.effect.each([
1445 { name: "OSC", sequence: "\u001b]0;unfinished" },
1446 { name: "DCS", sequence: "\u001bPunfinished" },
apps/server/src/terminal/Manager.ts
+18 -5
@@ -1274,17 +1274,30 @@ function sanitizeTerminalHistoryChunk(
1274
1275 if (nextCodePoint === 0x5b) {
1276 let cursor = index + 2;
1277 + // Inside a CSI Ghostty executes 0x00-0x0F and ignores DEL and 0x10-0x1F, which it would
1278 + // print in ground state. None join the parameters; only executed ones survive a strip.
1279 + let body = "";
1280 + let executedControls = "";
1281 while (cursor < input.length) {
1278 - const cancelled = isControlSequenceCancel(input.charCodeAt(cursor));
1279 - if (cancelled || isCsiFinalByte(input.charCodeAt(cursor))) {
1280 - const sequence = input.slice(index, cursor + 1);
1281 - const body = input.slice(index + 2, cursor);
1282 + const cursorCodePoint = input.charCodeAt(cursor);
1283 + const cancelled = isControlSequenceCancel(cursorCodePoint);
1284 + if (cancelled || isCsiFinalByte(cursorCodePoint)) {
1285 if (cancelled || !shouldStripCsiSequence(body, input[cursor] ?? "")) {
1283 - append(sequence);
1286 + append(input.slice(index, cursor + 1));
1287 + } else {
1288 + append(executedControls);
1289 }
1290 index = cursor + 1;
1291 break;
1292 }
1293 + if (cursorCodePoint < 0x10) {
1294 + executedControls += input[cursor];
1295 + } else if (
1296 + (cursorCodePoint >= 0x20 || cursorCodePoint === 0x1b) &&
1297 + cursorCodePoint !== 0x7f
1298 + ) {
1299 + body += input[cursor];
1300 + }
1301 cursor += 1;
1302 }
1303 if (cursor >= input.length) {