Repository navigation
fix(web): programs can copy to the clipboard from the terminal (OSC 52) - #22470
Open
SunkenInTime wants to merge 1 commit into
Open
SunkenInTime wants to merge 1 commit into
SunkenInTime wants to merge 1 commit into
Conversation
Contributor
ApprovabilityVerdict: Needs Human Approval Macroscope's review found this PR requires human approval — This PR adds automatic OSC 52 clipboard writes to the focused terminal, including a new streaming parser and system clipboard side effect. It also introduces a line-level lint suppression, so the behavior and static-analysis exception warrant human review. You can add or adjust custom eligibility rules. Learn more. |
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A program in the terminal copies "osc52 works" with OSC 52, then Ctrl+V in the composer. Isolated dev build, Edge, Windows 11, PowerShell terminal.
Problem
Programs inside a terminal copy with the OSC 52 escape sequence. That covers Claude Code's
/copyand copy-on-select, tmux withset-clipboard, Vim and Neovim, andprintf '\033]52;c;…\a'over SSH. T3's terminal ignored the sequence, so the program reported a copy and the clipboard kept its old contents. #8361 has reports from Windows desktop with a remote SSH environment, macOS and iPad. A Windows user replied to us on Twitter: "Copy/paste never behaves as expected, and it doesn't seem to play nicely with tmux when the remote machine is Ubuntu."Change
The pinned libghostty-vt C API has no clipboard callback, so
osc52.tsadds a small streaming scanner that watches live output next to Ghostty. Ghostty still gets every byte unchanged. The scanner:c,pandsselections, or none, to the one browser clipboard, and decodes the payload as UTF-8?), since a reply would hand this client's clipboard to whatever process askedThe surface reports a copy only while its terminal is focused and visible, so a background terminal can't overwrite the clipboard. History replay goes through
resetAndWrite, which resets the scanner, so reattaching never copies old output again. Only the thread terminal drawer is wired up. The provider sign-in terminal sends reconnect catch-up through the live path, so it is left out.Clients: web and desktop share this code. Mobile has its own native terminal and isn't covered here.
Scope and approval
A fix for #8361, a triaged bug. The policy choices that come with OSC 52 (write-only, focused terminal only) are the conservative ones, and docs/user/terminal.md says so in one paragraph.
Verification
osc52 worksonly with the PR.vp test run apps/web/src/terminal/ghostty/osc52.test.ts apps/web/src/terminal/ghostty/surface.test.ts apps/web/src/terminal/ghostty/core.test.ts: 115 passed. The scanner tests feed the stream whole and one character at a time, with both terminators, a title sequence and a read request mixed in, and an oversized payload followed by a normal copy. The surface test checks that an unfocused terminal, replayed history and a copy split across a replay don't write, and that a read gets no reply. Removing the focus check or the replay reset fails it.vp linton the touched files andvp run typecheckin apps/web are clean.Not covered:
/copywhose window loses focus before the sequence arrives is ignored by design./copyor tmux themselves. They emit the same sequence as the printf test.Made with Claude Opus 5.5 in T3 Code (Claude Code harness), reviewed by GPT-6 Astra (Codex).
Fixes #8361