The best way to control Claude Code, Codex and more from any computer or phone
perf(server): colored terminal output no longer copies history one character at a time (#21209)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alyx committed
Oct 18, 2026 at 20:09 UTC
c6dfda8e56d37a50fea783d7e6e3db34977248a3
1 file changed
+6
-2
apps/server/src/terminal/Manager.ts
+6
-2
@@ -1061,6 +1061,7 @@ function findEscapeSequenceEndIndex(input: string, start: number): number | null
1061
1062
// eslint-disable-next-line no-control-regex -- Terminal sequence introducers must reach the parser.
1063
const HISTORY_SEQUENCE_START = /[\u001b\u0090\u009b\u009d\u009e\u009f]/;
1064
+const NEXT_HISTORY_SEQUENCE_START = new RegExp(HISTORY_SEQUENCE_START.source, "g");
1065
1066
function sanitizeTerminalHistoryChunk(
1067
pendingControlSequence: string,
@@ -1175,8 +1176,11 @@ function sanitizeTerminalHistoryChunk(
1176
continue;
1177
}
1178
1178
- append(input[index] ?? "");
1179
- index += 1;
1179
+ // One slice per printable run: every chunk of coloured output reaches this loop.
1180
+ NEXT_HISTORY_SEQUENCE_START.lastIndex = index + 1;
1181
+ const nextSequenceStart = NEXT_HISTORY_SEQUENCE_START.exec(input)?.index ?? input.length;
1182
+ append(input.slice(index, nextSequenceStart));
1183
+ index = nextSequenceStart;
1184
}
1185
1186
return { visibleText, pendingControlSequence: "" };