- Rust 100%
terminal_polyfill now runs on Windows through ConPTY: %COMSPEC% by default, the console in VT input and output modes on top of raw mode, the window size polled, and the pseudo-console closed when the program exits, as ConPTY keeps its output open until then. A configuration file, terminal_polyfill/config.toml under $XDG_CONFIG_HOME, else %APPDATA% on Windows and ~/.config elsewhere, turns either sequence off, so that one the terminal handles itself, as Windows Terminal does OSC 52, passes through to it. CI builds and tests on Windows amd64 and arm64 as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mv4cZ3LFVAJ9aG5SntwnAr |
||
|---|---|---|
| .github | ||
| src | ||
| .gitattributes | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| Cargo.lock | ||
| Cargo.toml | ||
| deny.toml | ||
| git-conventional-commits.yaml | ||
| LICENSE.md | ||
| README.md | ||
| rustfmt.toml | ||
terminal_polyfill
terminal_polyfill runs your shell on a pseudo-terminal of its own and passes everything through to your real terminal, except the escape sequences that terminal can't handle, which it carries out itself:
- OSC 52 (copy to the clipboard), so a copy from nvim, tmux, Claude Code or a remote host over SSH reaches your clipboard.
- OSC 777;notify (desktop notification), so a program, such as a Claude Code hook, can pop a notification from wherever it runs.
It's for terminals that lack them: macOS Terminal.app, VTE terminals such as Ptyxis and GNOME Terminal, and Windows Terminal before 1.26, which handles OSC 52 but not OSC 777. Terminals that handle both themselves, such as Ghostty, don't need it.
Usage
terminal_polyfill # runs $SHELL, or %COMSPEC% on Windows
terminal_polyfill zsh -l # runs any program
The program sees TERM_POLYFILL=1, so a shell's startup can wrap itself once and not again:
if [[ -o interactive && -t 0 && -z $TERM_POLYFILL ]] && (( $+commands[terminal_polyfill] )); then
exec terminal_polyfill zsh
fi
terminal_polyfill exits with the program's exit status.
Configuration
A terminal that handles one of the two sequences itself doesn't need terminal_polyfill for it: Windows Terminal handles OSC 52, for one. The configuration file turns either off, and a sequence turned off passes through to the terminal unchanged:
[osc52]
enabled = false
[osc777]
enabled = true
The file is terminal_polyfill/config.toml in the configuration directory: $XDG_CONFIG_HOME when that is set, on every platform, else %APPDATA% on Windows and ~/.config elsewhere. Without a file, both sequences are handled. A file that can't be read or parsed is reported on stderr and otherwise ignored, so your shell still starts.
Install
Rust's stable toolchain is required.
cargo install --locked --git https://github.com/regulad/terminal_polyfill
How it works
- Pass-through: the program runs on a pseudo-terminal (portable-pty: a Unix pseudo-terminal, or ConPTY on Windows). Your keystrokes go to it unchanged, with your terminal in raw mode, and window size changes follow it.
- Scanning: the program's output goes through a streaming scanner (
src/osc.rs) that recognizes OSC sequences ended by either BEL or ST, even split across reads. Anything that isn't one of the two sequences above reaches your terminal byte for byte, other OSCs included. - Clipboard: an OSC 52 copy is decoded and put on the clipboard with arboard: the general pasteboard on macOS, the clipboard over Wayland's data-control protocol or X11 on Linux, and the Windows clipboard. The selection the sequence names (clipboard, primary, ...) is ignored. A clipboard read (
?) is swallowed and not answered. - Notifications: an OSC 777 notification (
ESC ] 777 ; notify ; <title> ; <body>) is shown with notify-rust: through the desktop's notification server over D-Bus on Linux, as Terminal.app's own on macOS, and as a Windows toast, under Windows PowerShell's name, which notify-rust uses by default. Other OSC 777 forms pass through. - Both run on a worker thread, so a slow clipboard or notification server never holds up output.
- On Windows, the console is switched to VT input and output on top of raw mode, so keys reach ConPTY as escape sequences and its output is carried out; both modes are put back on exit. Window size is polled every 200 ms, as a console has no SIGWINCH. ConPTY keeps its output open after the program exits, so terminal_polyfill closes the pseudo-console then.
Limitations
- A program that has to read the clipboard through OSC 52 gets no answer.
- On macOS and Linux, output ends when the program and everything it started have closed the terminal, so a background job that keeps it open keeps terminal_polyfill running. On Windows it ends when the program exits.
- On Windows, a Ctrl+Z typed along with other keys in one read, as in a paste, is lost: Rust's console input drops a Ctrl+Z that ends a read. A Ctrl+Z on its own reaches the program.
Prior art
A search on 2026-11-25 found pseudo-terminal shims for OSC 52 only, none for OSC 777:
- roy2220/osc52pty (Go), for Terminal.app, and its forks, among them regulad/osc52pty, which this replaces. Its pattern matcher (
parser.go) recognized one fixed prefix ended by BEL, and it piped copies to the platform's clipboard tool. - casaroli/osc52pty (zsh and C), macOS only.
- A Python wrapper around
script(1), for VTE terminals. - Grok CLI's experimental
grok wrap, which wraps one command, not a shell.
VTE itself has declined OSC 52 (GNOME/vte#2495).
Licence
terminal_polyfill is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 or (at your option) any later version. See LICENSE.md.