Skip to content

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.

  1. 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.
  2. I/O stays in raw bytes. onData delivers { bytes: Uint8Array, origin } instead of UTF-16 strings. Pass incoming PTY Uint8Array chunks straight to terminal.write(bytes).
  3. Fitting and GPU rendering are built in. You no longer install separate fit, WebGL, Unicode, or web-links addons. open() fits synchronously and ResizeObserver tracks future container or DPR changes automatically.
  4. Colors are RGB objects, not CSS strings. TerminalTheme takes { r, g, b } integers and a 256-entry palette array, with minimumContrast built right into the theme.

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.jsghostty-webgpu
new Terminal(opts)
await Terminal.create(opts)
term.onData(str => send(str))
term.onData(({ bytes }) => send(bytes))
term.open(host)
await term.open(host)
term.resize(cols, rows)
term.setAppearance({ grid })
@xterm/headless
await GhosttyRuntime.create()

Generated from a type-checked registry: every method in the middle column is verified against Terminal.

xterm.jsghostty-webgpuBehavior
new Terminal(options)await Terminal.create(options)Creation loads wasm asynchronously.
open(host)openAwait opening; the host must have a size.
write(data, callback)writeSynchronous result on the main entry; promise in the worker.
writeln(data)writelnWrite a line through native parsing.
onData / onBinaryonDataThe listener receives { bytes, origin }.
onResizeonResizeThe event has cols and rows.
onTitleChange / onBellonSubscribe to title and bell events.
onRenderonFrameObserve submitted rows.
FitAddon.fit()setAppearanceAutomatic fit; set appearance.grid for explicit geometry.
options.themesetThemeRGB objects and a 256-entry palette.
options.fontFamily / fontSizesetFontA partial native font object.
options.cursorStyle / cursorBlinksetCursorA partial native cursor object.
buffer.active.lengthlineCountCounts retained history and active visible rows.
buffer.getLine(i)readLinesHalf-open ranges, capped at 1,024 rows.
getSelection()getSelectionChoose plain, VT or HTML formatting.
select / selectAllselectRangeNative coordinates; selectAll is also available.
scrollLinesscrollByScroll by a row delta.
scrollToLinescrollToRowScroll to a retained row.
loadAddon(addon)useInstall a native extension.
registerLinkProviderregisterLinkProviderURL and OSC 8 detection are built in.
attachCustomKeyEventHandlerconnectInputSynchronous claim/pass ownership on the main entry.
focus / blur / disposedisposeFocus 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).

xterm.js addonghostty-webgpu equivalentStatus
@xterm/addon-fitBuilt-in ResizeObserver fitter; await term.open(host) fits synchronouslyBuilt in
@xterm/addon-webglrendererMode: 'auto' selects WebGPU or WebGL2 with Canvas-first startup and automatic fallbackBuilt in
@xterm/addon-unicode11 / graphemeNative libghostty-vt widths and DEC mode 2027 grapheme clusteringBuilt in
@xterm/addon-web-linksBuilt-in URL detection, OSC 8 hyperlinks, and registerLinkProvider (main and worker)Built in
@xterm/addon-clipboardHost clipboardWrite policy for OSC 52 writes (denied by default); OSC 52 reads get no replyWrite policy
@xterm/addon-attachBinary WebSocket recipe in Wire a PTYGuide
@xterm/addon-ligaturesligatures option reading the font’s GSUB tableOpt in
@xterm/addon-serializereadLines(), getSelection() (plain, vt, html), and captureViewport()Partial
@xterm/addon-searchRetained-buffer searchPlanned
@xterm/addon-imageSixel and Kitty graphics protocolsPlanned

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.

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).