fix(web): let focused terminal programs copy with OSC 52 #25243
Problem#
Terminal programs emit OSC 52 to copy text, but the web terminal ignores it and leaves the old clipboard contents unchanged.
Change#
Retain the original's bounded streaming scanner and wire clipboard writes into the thread terminal. Only focused, visible terminals in a focused browser window can copy; history replay resets the scanner without copying, and clipboard reads are never answered. Clipboard failures use the existing error toast. Four files, no dependencies or new test files.
Verification#
- Both regression tests fail on current main (
3de45c6254) before implementation. All 47 surface/core tests pass after it. - Blacksmith
vp run check:changedpasses format, lint, both dependency checks, affected typechecks, and all 34 adjacent tests. - System Google Chrome, repo Playwright, default
vp run dev, real PTY and clipboard: the same command pastesold clipboardon main andosc52 worksafter the fix. Unfocused live output and reload history preserve a sentinel clipboard. - GitHub CI passes on the current head
1eb74fcdf3, rebased on main. - Macroscope requests human review of the clipboard side effect. The inline lint suppression it flagged was removed.
- Unverified: Safari, Electron, native mobile, remote/tunnel connections, and emitting applications such as tmux and Vim. Web and desktop share this path; provider sign-in terminals and native mobile are unchanged. Browser clipboard permissions can reject writes. The existing 512 KiB display buffer can trim large copies before parsing; the scanner bounds buffered OSC bodies at 1 MiB.



Takeover#
Replaces #25051, with thanks to @maria-rcks for the original implementation.
Built with GPT-6.1-Sol in the Codex harness on T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Terminal programs can now write to the clipboard when their terminal and document are focused; clipboard reads remain disabled. Human review is required to confirm this default behavior, which allows program output to replace existing clipboard contents.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
Verified unchanged head
d7863610bad0275bd07c2c55d86a9ad081c84deaon a disposable Linux Boat VM. Reproduced the missing behavior ongithub/mainatf17c9d202bin/home/user/main, installed withvp i, and ran its real dev server. Stopped that server before starting the exact PR head with its own dev home andvp i.Used repository Playwright and
/usr/bin/google-chrome. Created a project pointing at the real/home/user/t3codegit repository and a thread through each running web app. Selected Codexgpt-6.1-soland completed a real provider turn through the local proxy on both versions. No mocks, fixtures, replay provider, or database seeding.Opened the thread terminal, ran the following through its real PTY, then pasted into the composer:
printf '\033]52;c;b3NjNTIgd29ya3M=\007'- Main: clipboard and composer remained
old clipboard. - PR: clicking the terminal and running the same command copied
osc52 works; normal Ctrl+V pasted it into the composer. - Nearby behavior: delayed OSC 52 output while the composer held focus preserved
background sentinel, withBACKGROUND_EMITTEDvisible in the terminal. Reloading the page and restoring terminal history preservedhistory sentinel. - Unicode and alternate termination:
printf '\033]52;;aMOpbGxvIPCfkYs=\033\\'copiedhéllo 👋. - Real Codex responses, ordinary terminal input, shell output, and composer paste remained usable.
Blacksmith checks on this head: all 47 surface/core tests passed.
vp run check:changedpassed format, lint, both knip checks, affected typechecks, and 34 adjacent tests. The runner's shallow boundary initially prevented merge-base discovery; after fetching the PR base and exposing the already-present parent in the task runner only, the check correctly inspected the four PR files since3de45c625434. No repository changes or pushes were needed. Hosted checks are complete: 22 successful, seven skipped, one neutral, with zero failing or pending.Before, main:

After, PR:


Inspected the full-size screenshots and exported recording. Verified uploaded image bytes and video playback and seeking, including T3's browser player.
Not verified#
Native iOS/Android, Electron, macOS/Windows, Safari/Firefox, remote/relay/tunnel connections, tmux/Vim passthrough, large clipboard payloads, clipboard-permission rejection, and browser-window focus loss were not exercised here. This pass verifies Linux Chrome's local web thread-terminal path. Malformed payloads and clipboard read suppression passed the existing automated tests; they were not separately driven through the real PTY in this pass.
- Main: clipboard and composer remained
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
Sign in to join this conversation.
No actionable comments were generated in the recent review.
Walkthrough
The terminal surface now detects valid OSC 52 clipboard writes in terminal output. It forwards decoded text to a clipboard callback only when the surface and document have focus and the surface is visible. The terminal drawer copies the text and shows an error toast if copying fails.
Changes: OSC 52 clipboard handling
apps/web/src/terminal/ghostty/osc52.tsapps/web/src/terminal/ghostty/surface.ts,apps/web/src/components/ThreadTerminalDrawer.tsx,apps/web/src/terminal/ghostty/surface.test.tsEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
Suggested reviewers:
t3dotggMerge Risk:
Minimal · up to
1eb74This change lets focused, visible web terminals copy text via OSC 52 and shows an error toast if the clipboard write fails. No concrete merge-blocking risk was found.
Pre-merge checks:
3 · 
1
Full details: Description check
Resolution
Add a Scope and approval section with a link to a triaged issue or discussion and the explicit maintainer approval comment. If this is a very small, focused fix of an obvious bug, explain why it qualifies without prior approval. Upload the screenshots and recording to GitHub and link or embed them in the description.
Finishing Touches
Generate docstrings
Generate unit tests (beta)
e5a1f41d-c90b-4ed9-ac61-29e1539b2ed4Reviewing files that changed from the base of the PR and between 94690956fd8f06ef302dd3fb9d4b1babba2a296c and 1eb74fcdf3e3f10df1db92294824fc13c8a025d2.
apps/web/src/components/ThreadTerminalDrawer.tsxapps/web/src/terminal/ghostty/osc52.tsapps/web/src/terminal/ghostty/surface.test.tsapps/web/src/terminal/ghostty/surface.tsLimit details: You’ve used all 10 included reviews currently available.