@devries-cameron20 / t3code-1 / commits / e4ff8433ee
Fork 0

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

fix(shared): command output keeps text after an unterminated OSC (#30479)

spoukyii committed Nov 5, 2026 at 20:31 UTC e4ff8433ee8d17964cec4bc2cee2758a612d1288
2 files changed +7 -1
packages/shared/src/terminalOutput.test.ts
+3
@@ -83,6 +83,9 @@ describe("appendTerminalOutput", () => {
83
84 it("drops an escape sequence that never terminates and resumes after it", () => {
85 expect(feed(["ok\u001b]", "x".repeat(200), "\nafter"]).text).toBe("ok\nafter");
86 + expect(feed(["ok\u001b]0;title\u001b", "\u001b[31mred"]).text).toBe(
87 + "ok\u001b[0;31mred\u001b[0m",
88 + );
89 });
90 });
91
packages/shared/src/terminalOutput.ts
+4 -1
@@ -246,6 +246,8 @@ const STRING_SEQUENCE_INTRODUCERS = new Set(["]", "P", "X", "_", "^"]);
246 function escapeLength(input: string, index: number): number {
247 const next = input[index + 1];
248 if (next === undefined) return -1;
249 + // A second ESC restarts the sequence.
250 + if (next === ESC) return 1;
251 if (next === "[") {
252 for (let cursor = index + 2; cursor < input.length; cursor += 1) {
253 const code = input.charCodeAt(cursor);
@@ -258,9 +260,10 @@ function escapeLength(input: string, index: number): number {
260 for (let cursor = index + 2; cursor < input.length; cursor += 1) {
261 if (input[cursor] === "\u0007") return cursor - index + 1;
262 if (input[cursor] === "\n") return cursor - index;
263 + // Like xterm.js, an ESC that does not start ST ends the string and begins the next sequence.
264 if (input[cursor] === ESC) {
265 if (cursor + 1 >= input.length) return -1;
263 - if (input[cursor + 1] === "\\") return cursor - index + 2;
266 + return input[cursor + 1] === "\\" ? cursor - index + 2 : cursor - index;
267 }
268 }
269 return -1;