Skip to content

research(terminal): evaluate xterm.js alternatives for AI CLI tool hosting #145

@Fldicoahkiin

Description

@Fldicoahkiin

Context

2code's primary use case is hosting AI CLI tools (Claude Code, Codex, etc.). xterm.js has several limitations for this use case:

This issue tracks research into alternative terminal rendering architectures.

Architecture Comparison

Current: xterm.js

Pipeline: PTY bytes → JS VT parser (DFA) → CircularList grid → DOM/WebGL renderer

  • Pros: most mature web terminal, huge ecosystem, VS Code uses it
  • Cons: JS parsing bottleneck, no native Kitty protocol, scroll-jump bug
  • Rendering: DOM (default), WebGL addon, Canvas 2D (deprecated)

Option A: ghostty-web (Ghostty VT → WASM)

Pipeline: PTY bytes → WASM VT parser (Ghostty/Zig SIMD) → Canvas 2D renderer

Source: coder/ghostty-web

Option B: alacritty_terminal (Rust backend + WebView rendering)

Pipeline: PTY bytes → Rust VT parser → Grid model + damage tracking → IPC → WebGL/Canvas in WebView

Source: alacritty_terminal crate + egui_term embedding example

  • Pros: battle-tested VT parser, damage tracking reduces IPC overhead, full control
  • Cons:
    • No existing WebView integration — GitHub search "alacritty_terminal webview" returns 0 results
    • All Tauri terminal projects use xterm.js (hermes-ide, kerminal, Terminal-64)
    • IPC overhead: incremental updates 1-5KB/frame OK, full redraws 46-384KB/frame problematic with JSON
    • Estimated 2000-4000 lines of bridge code
    • Need to build WebGL renderer from scratch
  • Status: Technically feasible but high effort, no precedent

Option C: libghostty (Zig/C library)

Pipeline: PTY bytes → libghostty (SIMD VT parser + grid + damage tracking) → C API → Rust FFI → IPC → WebView

Source: libghostty announcement, awesome-libghostty

  • Pros: fastest VT parser (SIMD), native Kitty protocol, growing ecosystem (browstty, obsidian-ghostty-terminal, vscode-bootty)
  • Cons:
    • Zig → C → Rust FFI chain
    • Still alpha, official WASM distribution not published
    • Same WebView rendering challenge as Option B
  • Status: Most promising long-term, too early now
  • Notable: xterm.js itself considering adopting libghostty — but no consensus among maintainers

Option D: Stay on xterm.js, upgrade to 7.0

Pipeline: Same as current, but with upstream fixes

Not viable

  • termwiz: Not a terminal emulator. Surface/Change model is for building TUI apps, cannot process bash/vim escape sequences.
  • Kitty rendering code: Tightly coupled to window management, no library form, no API.
  • Warp terminal code: WarpUI not independently published, AGPL-3.0 license.
  • Tauri native terminal view: Tauri 2 doesn't support embedding non-WebView native components without per-platform plugin work.

How Other Terminals Handle AI CLI Tools

Terminal Architecture AI CLI scroll issue? Solution
Warp Block model + Metal/wgpu No Each command is isolated block
Kitty OpenGL + C parser No GPU rendering, no DOM scroll
Ghostty Metal/GL + Zig SIMD parser No Same as Kitty
VS Code xterm.js Yes Same issue, no fix yet
Tabby xterm.js Yes → Fixed pinnedToBottom flag (PR #11102)
Hyper xterm.js Yes Unfixed since 2023 (#7065)
iTerm2 Native Cocoa Partial Native rendering helps, but Ink layer still flickers
WezTerm termwiz + wgpu Has issues #7531, limited info

Recommendation

Short-term (now): Stay on xterm.js. Inject Claude Code env vars + implement Tabby-style scroll fix.

Medium-term (xterm.js 7.0): Upgrade when 7.0 releases with PR #5770 (DEC 2026 viewport fix).

Long-term (watch):

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions