Migrating from xterm.js
ghostty-webgpu exposes its own native API rather than an xterm.js compatibility layer. Most of the migration is mechanical once you adjust to four core design differences.
Four mental-model shifts
Section titled “Four mental-model shifts”- Creation and opening are async.
await Terminal.create(opts)loads WebAssembly and builds the native session;await terminal.open(host)measures the container, fits the initial grid, and starts the renderer. - I/O stays in raw bytes.
onDatadelivers{ bytes: Uint8Array, origin }instead of UTF-16 strings. Pass incoming PTYUint8Arraychunks straight toterminal.write(bytes). - Fitting and GPU rendering are built in. You no longer install separate fit, WebGL, Unicode, or web-links addons.
open()fits synchronously andResizeObservertracks future container or DPR changes automatically. - Colors are RGB objects, not CSS strings.
TerminalThemetakes{ r, g, b }integers and a 256-entrypalettearray, withminimumContrastbuilt right into the theme.
Side-by-side quick start
Section titled “Side-by-side quick start”Every snippet on the right is type-checked against the built package declarations in CI (opts is GhosttyWebGpuTerminalOptions, host is a sized container, send forwards Uint8Array bytes to your PTY, and grid holds { columns, rows }).
| xterm.js | ghostty-webgpu |
|---|---|
| |
| |
| |
| |
| |
Instance API mapping
Section titled “Instance API mapping”Generated from a type-checked registry: every method in the middle column is verified against Terminal.
| xterm.js | ghostty-webgpu | Behavior |
|---|---|---|
new Terminal(options) | await Terminal.create(options) | Creation loads wasm asynchronously. |
open(host) | open | Await opening; the host must have a size. |
write(data, callback) | write | Synchronous result on the main entry; promise in the worker. |
writeln(data) | writeln | Write a line through native parsing. |
onData / onBinary | onData | The listener receives { bytes, origin }. |
onResize | onResize | The event has cols and rows. |
onTitleChange / onBell | on | Subscribe to title and bell events. |
onRender | onFrame | Observe submitted rows. |
FitAddon.fit() | setAppearance | Automatic fit; set appearance.grid for explicit geometry. |
options.theme | setTheme | RGB objects and a 256-entry palette. |
options.fontFamily / fontSize | setFont | A partial native font object. |
options.cursorStyle / cursorBlink | setCursor | A partial native cursor object. |
buffer.active.length | lineCount | Counts retained history and active visible rows. |
buffer.getLine(i) | readLines | Half-open ranges, capped at 1,024 rows. |
getSelection() | getSelection | Choose plain, VT or HTML formatting. |
select / selectAll | selectRange | Native coordinates; selectAll is also available. |
scrollLines | scrollBy | Scroll by a row delta. |
scrollToLine | scrollToRow | Scroll to a retained row. |
loadAddon(addon) | use | Install a native extension. |
registerLinkProvider | registerLinkProvider | URL and OSC 8 detection are built in. |
attachCustomKeyEventHandler | connectInput | Synchronous claim/pass ownership on the main entry. |
focus / blur / dispose | dispose | Focus and blur stay synchronous; dispose returns a promise in the worker. |
For programmatic input, use sendInput() for raw bytes or text, paste() for bracketed paste, and key() for synthesized keystrokes. Subscribe to title, bell, selection, scroll, appearance, error, and outputTiming via terminal.on(type, listener).
Addon replacements
Section titled “Addon replacements”| xterm.js addon | ghostty-webgpu equivalent | Status |
|---|---|---|
@xterm/addon-fit | Built-in ResizeObserver fitter; await term.open(host) fits synchronously | Built in |
@xterm/addon-webgl | rendererMode: 'auto' selects WebGPU or WebGL2 with Canvas-first startup and automatic fallback | Built in |
@xterm/addon-unicode11 / grapheme | Native libghostty-vt widths and DEC mode 2027 grapheme clustering | Built in |
@xterm/addon-web-links | Built-in URL detection, OSC 8 hyperlinks, and registerLinkProvider (main and worker) | Built in |
@xterm/addon-clipboard | Host clipboardWrite policy for OSC 52 writes (denied by default); OSC 52 reads get no reply | Write policy |
@xterm/addon-attach | Binary WebSocket recipe in Wire a PTY | Guide |
@xterm/addon-ligatures | ligatures option reading the font’s GSUB table | Opt in |
@xterm/addon-serialize | readLines(), getSelection() (plain, vt, html), and captureViewport() | Partial |
@xterm/addon-search | Retained-buffer search | Planned |
@xterm/addon-image | Sixel and Kitty graphics protocols | Planned |
registerMarker, registerDecoration, and custom xterm parser hooks do not have public equivalents; custom OSC observation is available on TerminalSession. See status and limits for current scope.
Performance and bundle tradeoffs
Section titled “Performance and bundle tradeoffs”Compare matching renderer classes in Benchmarks. ghostty-webgpu uses significantly less CPU under heavy streaming and multi-terminal workloads (median 0.71x on Linux PC, 0.77x on M1 Mac across the November 2026 five-way suite), while xterm.js ships a smaller initial download (84.1 KiB brotli vs. 269.2 KiB brotli).