Clipboard & export
AgentMux routes all clipboard interaction through one path: a thin frontend wrapper that calls into the host process via CEF IPC. CEF’s Chromium blocks navigator.clipboard.readText() without a Permissions-Policy header, and writeText() works today but is fragile — the wrapper exists so every pane in the app behaves the same way regardless.
This page documents how the wiring goes together and how to add clipboard support to a new pane type.
The wrapper
Section titled “The wrapper”import { writeText, readText } from "@/util/clipboard";
await writeText("hello");const text = await readText();Both functions invoke CEF IPC commands implemented in crates/cef/src/commands/clipboard.rs:
- Windows — Win32
OpenClipboard/SetClipboardData(CF_UNICODETEXT). - macOS —
pbcopy/pbpaste. - Linux —
wl-copy(Wayland) withxclip/xselfallback (X11).
Errors propagate: writeText and readText reject when the underlying CEF IPC call fails (e.g. missing clipboard helpers on Linux, IPC token expired). Callers that don’t want to surface the failure to the user should .catch() and log — see the reference implementation in termwrap.ts which logs to console.log so the failure shows up in the dev [fe] tail without blocking the UI.
Rule: never call navigator.clipboard.* directly
Section titled “Rule: never call navigator.clipboard.* directly”All code goes through the wrapper. If you need clipboard from a pane, the wrapper is your only API.
Surfaces: keyboard and context menu
Section titled “Surfaces: keyboard and context menu”A copy action is reached from the keyboard (Ctrl+C in general, Ctrl+Shift+C in terminals) and from a right-click menu with Copy items. Each pane wires its own, as described below.
What is selectable
Section titled “What is selectable”There is no shared selection registry. The unified clipboard spec (SPEC_UNIFIED_CLIPBOARD_2026_05_18.md) proposed a SelectionProvider that each pane would register, but it was never built. Each pane wires its own copy actions: the terminal as described below, and the install log view (frontend/app/element/install/LogView.tsx) with its own Copy All menu item.
xterm.js terminals
Section titled “xterm.js terminals”The terminal pane (termwrap.ts) wires three things (the agent install modal’s terminal, which wired the same three, has since been removed):
onSelectionChange— read theterm:copyonselectsetting; if true, copy the current xterm selection on every change.attachCustomKeyEventHandler— interceptCtrl+Shift+Cand write the selection to clipboard. Returnfalseto stop xterm from also routing the keystroke as terminal input.onContextMenuon the container — show Copy / Copy All viaContextMenuModel.showContextMenu.
Selection within xterm is managed by xterm.js itself, not by the browser — xterm.css sets user-select: none on the canvas. Use terminal.getSelection() to read it; never window.getSelection() on a terminal pane.
Adding clipboard to a new pane
Section titled “Adding clipboard to a new pane”- Import the wrapper:
import { writeText } from "@/util/clipboard". - If the pane has selectable content, wire its copy actions in the pane itself, as the terminal and the install log view do.
- For xterm-based panes, wire all three xterm hooks (selection-change, key-handler, container context menu) as above.
- Add Copy / Copy All to the pane’s right-click menu via
ContextMenuModel.showContextMenu. - Do not call
navigator.clipboard.*directly.
See also
Section titled “See also”- Spec:
SPEC_UNIFIED_CLIPBOARD_2026_05_18.md— the unified architecture + phased rollout. - Source:
frontend/util/clipboard.ts— the wrapper.crates/cef/src/commands/clipboard.rs— host-side impl.frontend/app/store/contextmenu.ts—ContextMenuModel.frontend/app/view/term/termwrap.ts— reference xterm wiring.