KaosMaps  /  ghostmux

ghostmux — Ghostty + tmux, without the fight

How to make tmux invisible for everyday terminal UX while keeping its superpowers — by letting Ghostty own scroll, select, and copy natively.

ghostty Ghostty 1.3.1 / tmux 3.5a / verified 2026-06-11
01

The contract — who owns what

Every interaction is assigned to exactly one owner. Nothing is shared. The table below is the complete contract.

Interaction Owner How
Wheel / trackpad scrolling Ghostty Pane output streams into Ghostty's own scrollback; scrolling never reaches tmux
Text selection — drag, double-click word, triple-click line Ghostty Native macOS selection. Select is a state; copy is an act — selecting never touches the clipboard
Copy / Paste Ghostty / macOS Cmd+C / Cmd+V; bracketed paste remains intact
Line start / end Ghostty + zsh Cmd+Left / Cmd+Right send Ctrl+A / Ctrl+E (Ghostty defaults). The zsh/bindkeys.zsh file also binds them in the zsh vi-insert keymap — necessary because EDITOR=nvim puts zsh in vi mode where they would otherwise self-insert as literal ^A / ^E
Selection while a full-screen TUI owns the mouse Ghostty Shift+drag — guaranteed native selection even when vim or htop has captured mouse events (mouse-shift-capture = never)
Sessions, persistence, resurrect / continuum, statusline, multiline input tmux Unchanged — tmux's actual superpowers are untouched
Deep history — before a window attached, or after a reboot-restore tmux copy-mode Deliberate prefix [ — arrows / PgUp to navigate, / to search, y or Enter to copy via OSC 52, q or Esc to exit
02

The trick — tmux off the alternate screen

Normally tmux runs on the terminal's alternate screen: a second framebuffer with no scrollback. That is why terminals go scroll-dead under tmux, and why every scroll gesture used to become a tmux copy-mode invocation.

The native-ux mode sets mouse off plus one line:

set -as terminal-overrides ',xterm-ghostty:smcup@:rmcup@'

This tells tmux: "this terminal has no alternate screen." tmux then paints on the primary screen, every line that scrolls off the top lands in Ghostty's real scrollback buffer, and Ghostty's native scroll / select / copy machinery works without modification.

scrollback tmux pane $ seq 1 200 1 2 tmux statusline classic: alt screen no scrollback access smcup@ rmcup@ Ghostty scrollback $ seq 1 200 1 2 3 ... 200 $ _ tmux statusline ghostmux: primary screen full scrollback, Ghostty-native
Left: tmux on the alternate screen — scrollback inaccessible. Right: smcup@/rmcup@ suppressed — output flows into Ghostty's real scrollback.
Empirically decisive fact

Ghostty 1.3.1 saves region-scrolled lines (the area above the tmux statusline) into scrollback — user-verified on a live probe, scrolling natively through 1,500+ region-scrolled lines back to HISTORY-1. Many terminals do not, which is why this classic trick had a bad reputation. Ghostty does.

Consequences to know

  • Ghostty's buffer holds only what streamed through that window since it attached. An idle session has nothing to scroll — not a bug. Quick self-test: seq 1 200, then scroll. For pre-attach history, use prefix [.
  • Full-screen TUIs (vim, less) no longer use the outer alternate screen; their content remains in scrollback after exit. Cosmetic, not functional.
  • Pane splits: native selection is per-window, not per-pane — selections cross split borders. The recommended workflow (one session per Ghostty surface, single pane) makes this moot.
03

The three state layers — and when to run which command

This is the key mental model. Config changes propagate at different rates depending on which layer they live in. Knowing the layer tells you exactly which command to run — and why.

1 tmux server state options, key bindings, styles, history-limit Takes effect: IMMEDIATELY on config reload tmux source-file ~/.tmux.conf applies options instantly to running server re-attach required 2 client-negotiated state terminal-overrides (smcup@), focus reporting Takes effect: only when a client ATTACHES tmux detach-client -E "tmux attach" re-attaches window in place (brief flash) process restart required 3 application / process state Ghostty loaded config, shell loaded .zshrc Cmd+Shift+, reloads config (Ghostty) new shell picks up ~/.zshrc
Three layers — three delivery mechanisms. Applying a change to the wrong layer is the most common source of "why isn't this working?"
The mixed-UX symptom

If scrolling moves the prompt or input box instead of history, that window is layer-2 stale — it is still on the alternate screen, and wheel events are being degraded to arrow key presses. Fix: detach and re-attach the tmux client. The scrollback floor of each refreshed window resets to the moment of refresh.

04

Setup — paste-ready config blocks

Three files, all in the ghostmux repo. Copy each block into the target file. No build step, no package manager.

File in repo Paste target What it does
tmux/ghostty.conf ~/.tmux.conf Sets mouse off, suppresses alternate screen (smcup@:rmcup@), enables focus events and extended keys. After pasting: tmux source-file ~/.tmux.conf, then detach/re-attach each window to apply layer-2 changes.
ghostty/config ~/.config/ghostty/config Adds scrollback-limit = 100000000 (100 MB per surface — multi-day sessions) and mouse-shift-capture = never. Remove any copy-on-select = clipboard line — that violates "select is not copy." Reload Ghostty: Cmd+Shift+, (or restart the surface; scrollback-limit applies to new surfaces).
zsh/bindkeys.zsh ~/.zshrc (source or append) Binds Ctrl+A / Ctrl+E as self-insert in the zsh vi-insert keymap — needed when EDITOR=nvim puts zsh in vi mode. If you do not use vi mode, this is a no-op.

Verify the setup

bun harness/verify-ux.ts

23 assertions: alternate-screen suppression (ESC[?1049h absent at attach), CPR noise-immunity, paste integrity, hard-refresh cycle. All must be green before you rely on the config.

Important: extended-keys on, never always

The tmux config sets extended-keys on, never extended-keys always. The always value triggers tmux bug #4663 — it corrupts multiline paste by injecting CSI-u sequences ([13;...u artifacts). The on value activates extended keys only when the client declares support, which is safe.

05

Daily cheat sheet

All interactions you actually reach for. German-keyboard note: Cmd+Plus is Cmd+Shift+0 on a German layout — Cmd+Up / Cmd+Down / Cmd+0 are safer for font size.

Scroll history
trackpad / wheel  — anywhere
Select text
drag  |  double-click = word  |  triple-click = line
highlight only — clipboard untouched
Copy
Cmd+C
Paste
Cmd+V
Line start / end
Cmd+Left / Cmd+Right
Select while TUI owns mouse
Shift+drag
Deep history + search
prefix [ → arrows / PgUp, / search
y or Enter copies  |  q exits
Detach window
prefix d
Font size
Cmd+Up / Cmd+Down / Cmd+0
also Cmd+Plus / Cmd+Minus
Reload tmux config
tmux source-file ~/.tmux.conf
06

Troubleshooting

Symptom Cause Fix
No scrolling in a session at all Session is idle — Ghostty's buffer only holds output since attach; tmux history may also be near-empty Not a bug. Run seq 1 200 to verify. Use prefix [ for older content
Scrolling moves the input box / cycles shell history Window is layer-2 stale — still on alt screen, wheel events degraded to arrow-key emulation Detach and re-attach: tmux detach-client -E "tmux attach"
Scrolling stops at the moment of the last re-attach Expected — scrollback floor resets to attach time on re-attach prefix [ for older content
Selection vanishes or auto-copies copy-on-select=clipboard is in Ghostty config, or you are in tmux-mouse mode Remove copy-on-select=clipboard from ~/.config/ghostty/config and reload. Ensure mouse off in ~/.tmux.conf
Cmd+Left / Cmd+Right print ^A / ^E Shell predates the bindkeys block in ~/.zshrc Open a new shell, or source ~/.zshrc
Multiline paste garbled with [13;...u artifacts extended-keys always crept into ~/.tmux.conf — tmux bug #4663 Change to extended-keys on and reload: tmux source-file ~/.tmux.conf
Window shows stale screen after reboot tmux-resurrect restored the session; Ghostty buffer starts empty Normal — history is in tmux via prefix [
Verify harness fails T1.1 (1049h still seen) The terminal-override line is not active for the attached client Re-attach the client after sourcing: tmux source-file ~/.tmux.conf, then detach/re-attach
07

How this was built

Every load-bearing mechanism was probed on the live stack before the design was committed. This included nested-tmux byte injection, Ghostty CLI, and upstream research — in that order. Design came after proof, not before.

A first design ("fusion": tmux-owned mouse with type-to-exit copy-mode) shipped and was withdrawn the same day. Agent TUI terminal-reply bytes — CPR sequences \e[12;34R, DECRQM, kitty-protocol replies — arrive through the same key dispatcher as human input and are indistinguishable from it at the tmux layer. The result: every terminal round-trip while scrolled yanked the view to the bottom and leaked fragments into the agent's prompt. There is no tmux-layer signal separating human from machine bytes; the feature class is unsalvageable. The full post-mortem is in the repo.

The dream of "native drag + wheel delivering to tmux simultaneously" is protocol-impossible in Ghostty <= 1.3.x — the terminal has no per-mouse-event remapping capability; see Ghostty discussion #3848.

The acceptance harness (bun harness/verify-ux.ts) runs 23 assertions including a byte-level proof that the override suppresses ESC[?1049h at client attach, CPR noise-immunity, paste integrity, and a live hard-refresh cycle.

Repo:  github.com/kaosmaps/ghostmux  ·  docs/post-mortem.md

Verify:  bun harness/verify-ux.ts