Skip to content

fix(terminal): copy from pi on a remote host reaches the viewer's clipboard - #34102

Merged
nwparker merged 3 commits into
mainfrom
fix-33937-remote-tui-selection
Oct 27, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix-33937-remote-tui-selection

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119 $\color{#cf222e}{\Huge{\mathbf{−}}}$​60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

When you watch an Orca terminal on another machine and copy text inside pi's full-screen view, pi put the text on the clipboard of the machine pi runs on, not the one you're sitting at. Now Orca tells pi that the viewer is somewhere else, so pi also sends the copy to your terminal and it lands on your clipboard.

What Changed

  • Before: in a terminal on a paired Orca server, or on a managed SSH host, selecting text in pi's full-screen mode looked like it worked, but nothing reached your clipboard. That's because pi handles the mouse itself while it's full screen. On a local terminal it worked, since the host clipboard is your clipboard.
  • After: every terminal that a remote viewer is watching gets PI_CLIPBOARD_OSC52=1. This is pi's own documented switch: it keeps pi's normal host clipboard write and also sends the text as OSC 52. Orca's terminal already writes OSC 52 to the viewer's clipboard.
  • How: the existing Codex-only remote-viewer clipboard hook (fix(codex): copy in remote Orca Server Codex sessions reaches your clipboard #27605) became applyRemoteViewerClipboardEnv. It covers both remote paths: headless/SSH-managed hosts (buildPtyHostEnv) and terminals a remote client creates on a desktop host (applyRemoteViewerLaunchEnv). The pi variable is set in every shell because people start pi by hand, and nothing else reads it. The fake SSH_CONNECTION marker is still only for Orca-launched Codex, so bare-shell prompts don't change. WSL panes forward the variable through WSLENV. If you already set PI_CLIPBOARD_OSC52 yourself, your value wins.

Why

The reporter's pi case matches pi's copy routing: pi only sends OSC 52 when it sees SSH variables or PI_CLIPBOARD_OSC52=1, and an Orca server pane has neither. Claude Code already sends OSC 52 on every copy, and Orca-launched Codex was fixed in #27605, so this change doesn't explain or address their failures. For pi, Orca's own drag selection (Shift-drag, or Option-drag on macOS) behaves the same on local and remote panes: one renderer and the same xterm options. So for pi, the difference is where its copy goes, not mouse handling. Setting the agent's own opt-in is host-side only: no new wire fields, and it works with any client version.

Linked Issue

Refs #33937

This covers only the pi part of the report. Claude Code already sends OSC 52 on every copy, and Codex started by hand is unchanged, so the reporter's Claude Code and Codex failures are still unexplained. That part of the issue stays open.

Thanks to @henjuese for the report and the clear repro steps.

Visual Proof

N/A: this only changes the environment of remote terminals, with no UI change. It's covered by unit tests on both remote launch paths.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New cases in remote-viewer-clipboard-env.test.ts, remote-viewer-launch-env.test.ts and pty-spawn-env-terminal-basics.test.ts: a plain shell on a headless host and a remote caller's plain shell both get PI_CLIPBOARD_OSC52=1, local viewers don't, and an explicit user value is kept. These fail on main.

  • Existing Codex marker tests still pass.

  • pnpm tc (including the CI bun compiler), changed-code quality gate, oxfmt, and the static-analysis steps pass. The root oxlint errors are pre-existing max-lines errors in untouched files.

  • Not done: a live run of pi against a paired server.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security: no new clipboard capability. OSC 52 writes still go through the existing terminalAllowOsc52Clipboard gate, and queries stay blocked.
  • Known gap: a terminal created on a desktop host's own window and later watched from another machine isn't marked, because the viewer isn't known when it spawns. Codex or other TUIs that you start by hand and that only send OSC 52 under real SSH variables are also unchanged, on purpose.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cac425fa-8488-404c-b5b2-714e559b3a57
Commits

Reviewing files that changed from the base of the PR and between b189e55 and 6b19e5c.

Files selected for processing: 1
  • src/main/runtime/agent-terminal-startup-prompt.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Walkthrough

A shared helper now configures the Pi OSC 52 clipboard variable for remote viewers and retains the Codex SSH fallback. PTY host assembly and runtime launch processing use the helper. The WSL PTY environment passes through the Pi clipboard variable. Tests cover these environment settings and their existing-value conditions.

Priority: Normal

Merge Risk: Minimal · up to 6b19e

The reviewed clipboard environment changes are ready to merge with no established blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: making pi clipboard copies from remote hosts reach the viewer's clipboard.
Description check Passed The description is detailed and covers the required ELI5, change summary, rationale, issue reference, visual proof, testing, compatibility notes, and checklist sections. It uses "Refs #33937" instead …
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the required ELI5, change summary, rationale, issue reference, visual proof, testing, compatibility notes, and checklist sections. It uses "Refs #33937" instead of the template's requested issue-link format, and the full lint/typecheck/test/build checklist remains unchecked, but the description is otherwise complete and relevant.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…pboard

Remote viewers get PI_CLIPBOARD_OSC52=1 in every pane so pi's in-app
selection also sends OSC 52 instead of only the host's clipboard. The
Codex SSH_CONNECTION marker stays limited to Orca-launched Codex.

Refs #33937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant