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

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

fix(terminal): use a byte budget for Ghostty scrollback (#8766)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Zero Two committed Nov 11, 2026 at 13:58 UTC dab06c0be19b9d6e109f5538c6ddc92f7f15fb6b
3 files changed +38 -4
apps/mobile/modules/t3-terminal/android/src/main/cpp/t3_terminal_jni.cpp
+4 -2
@@ -12,7 +12,9 @@ namespace {
12
13 constexpr uint32_t kSnapshotMagic = 0x54563354; // "T3VT" in little endian.
14 constexpr uint16_t kSnapshotVersion = 1;
15 -constexpr size_t kMaxScrollbackRows = 10000;
15 +// The pinned ABI measures max_scrollback in bytes despite its header saying lines.
16 +// Match Ghostty's default scrollback-limit.
17 +constexpr size_t kMaxScrollbackBytes = 10'000'000;
18
19 enum CellFlag : uint16_t {
20 kBold = 1 << 0,
@@ -205,7 +207,7 @@ Java_expo_modules_t3terminal_GhosttyBridge_nativeCreate(
207 GhosttyTerminalOptions options = {
208 .cols = static_cast<uint16_t>(std::clamp(cols, 1, 65535)),
209 .rows = static_cast<uint16_t>(std::clamp(rows, 1, 65535)),
208 - .max_scrollback = kMaxScrollbackRows,
210 + .max_scrollback = kMaxScrollbackBytes,
211 };
212 if (ghostty_terminal_new(nullptr, &session->terminal, options) != GHOSTTY_SUCCESS ||
213 ghostty_render_state_new(nullptr, &session->render_state) != GHOSTTY_SUCCESS ||
apps/web/src/terminal/ghostty/core.test.ts
+25
@@ -407,3 +407,28 @@ describe("GhosttyTerminalCore snapshots", () => {
407 expect(core.snapshot()).toEqual(reference.snapshot());
408 });
409 });
410 +
411 +describe("GhosttyTerminalCore scrollback", () => {
412 + it("retains thousands of rows of scrollback", async () => {
413 + const core = await GhosttyTerminalCore.create(
414 + 80,
415 + 10,
416 + 8,
417 + 16,
418 + {
419 + foreground: { r: 255, g: 255, b: 255 },
420 + background: { r: 0, g: 0, b: 0 },
421 + cursor: { r: 255, g: 255, b: 255 },
422 + },
423 + () => {},
424 + );
425 + try {
426 + core.write(Array.from({ length: 1_200 }, (_, index) => `${index}\r\n`).join(""));
427 + const scrollbar = core.scrollbarState();
428 + // max_scrollback is a byte budget in the pinned ABI, not a row count.
429 + expect(scrollbar!.total - scrollbar!.len).toBeGreaterThan(1_000);
430 + } finally {
431 + core.dispose();
432 + }
433 + });
434 +});
apps/web/src/terminal/ghostty/core.ts
+9 -2
@@ -9,7 +9,9 @@ import { GhosttyRuntime, loadGhosttyRuntime } from "./runtime";
9
10 const GHOSTTY_SUCCESS = 0;
11 const GHOSTTY_OUT_OF_SPACE = -3;
12 -const MAX_SCROLLBACK_ROWS = 10_000;
12 +// The pinned ABI measures max_scrollback in bytes despite its header saying lines.
13 +// Match Ghostty's default scrollback-limit.
14 +const MAX_SCROLLBACK_BYTES = 10_000_000;
15 // wasm32 GhosttyTerminalSelectionFormatOptions layout at the pinned libghostty-vt revision.
16 const SELECTION_FORMAT_OPTIONS_SIZE = 16;
17 const PALETTE_BYTES = 256 * 3;
@@ -261,7 +263,12 @@ export class GhosttyTerminalCore {
263 const options = this.runtime.alloc(optionsSize);
264 this.runtime.setField(options, "GhosttyTerminalOptions", "cols", cols);
265 this.runtime.setField(options, "GhosttyTerminalOptions", "rows", rows);
264 - this.runtime.setField(options, "GhosttyTerminalOptions", "max_scrollback", MAX_SCROLLBACK_ROWS);
266 + this.runtime.setField(
267 + options,
268 + "GhosttyTerminalOptions",
269 + "max_scrollback",
270 + MAX_SCROLLBACK_BYTES,
271 + );
272 this.terminalSlot = this.runtime.allocOpaque();
273 const terminalResult = this.runtime.call("ghostty_terminal_new", 0, this.terminalSlot, options);
274 this.runtime.free(options, optionsSize);