orca icon indicating copy to clipboard operation
orca copied to clipboard

[Bug]: Windows: TUI (e.g. OpenCode) copy shows "Copied" but clipboard is empty (works on macOS)

Open AmethystLiang opened this issue 4 months ago • 6 comments

Summary

On Windows, copying content from the Claude Code TUI (terminal mode) does not put text on the system clipboard. Orca still shows a Copied toast in the bottom-right corner, so the action looks successful, but paste into other apps (or back into Orca) gets nothing.

Reproduced on Windows; works on macOS.

Environment

  • OS: Windows 10
  • Platform comparison: works on macOS; fails on Windows
  • Surface: Claude Code in terminal / TUI mode

What happened

  1. Run Claude Code in Orca’s terminal on Windows.
  2. Try to copy TUI / message content (selection + copy / whatever Claude Code’s copy path uses).
  3. Bottom-right UI shows Copied.
  4. Clipboard is not updated — paste is empty / previous clipboard content remains.
  5. Changing settings does not help.
  6. Same flow works on Mac.

Expected behavior

  • After a successful copy, the selected Claude Code TUI / message text should be on the OS clipboard.
  • Paste into Notepad / browser / another Orca pane should insert that text.
  • If the clipboard write fails, Orca should not show a success Copied toast.

Actual behavior

  • Copied toast appears.
  • Clipboard is effectively unchanged / empty.
  • Terminal Claude Code remains usable otherwise; this is a copy/clipboard failure, not a general CC outage.

Notes

Reporter summary (translated from internal report):

Reproduced on Windows: Claude Code cannot copy TUI content; works on Mac.
In terminal mode, message content cannot be copied; settings don’t help. Bottom-right shows “copied” but it doesn’t actually work. Windows 10.

Likely related

Similar Windows “UI says copied, clipboard empty” reports in other surfaces:

  • #5611 — Copying selected Copilot conversation text shows success but clipboard is unchanged (Windows)
  • #6274 — Ctrl+C copy shortcuts not working (Windows, markdown source mode; closed)
  • #2840 — OSC52 remote copy issues (closed; macOS-oriented)

This report is specifically Claude Code TUI / terminal-mode message copy on Windows 10, with a Mac control that works.

Possible investigation areas (from prior clipboard bugs):

  • Terminal selection copy path: writeClipboardText / xterm selection handlers under src/renderer/src/components/terminal-pane/
  • Main clipboard IPC: src/main/window/clipboard-ipc-handlers.ts
  • OSC 52 clipboard handling for agent TUIs that emit copy sequences rather than relying only on host selection

Ask

Please investigate Windows clipboard write for Claude Code TUI copy (including cases where Orca shows Copied without a real clipboard update), and make success toast match actual clipboard state.

AmethystLiang avatar Jul 16 '26 06:07 AmethystLiang

Hi! I'd like to work on this issue.

I have a Windows environment and can reproduce and investigate the clipboard write path (likely writeClipboardText / terminal selection handlers, and src/main/window/clipboard-ipc-handlers.ts).

I'll start by reproducing the issue and adding a regression test that captures the "Copied toast shown but clipboard actually empty" behavior, then implement the fix.

Let me know if anyone's already working on this — happy to pick something else if so.

Chang-Jin-Lee avatar Jul 16 '26 08:07 Chang-Jin-Lee

Update: I dug into this pretty deep (real Windows repro of the OSC 52 clipboard path end-to-end) and couldn't pin down a concrete Orca-side bug — the OSC 52 write path itself works correctly on Windows when the terminal setting is enabled. Reproducing the actual reported behavior likely needs the real Claude Code/OpenCode binary to see exactly what it emits, which I don't have set up. Stepping back from this one so it's free for someone else — happy to share notes if useful.

Chang-Jin-Lee avatar Jul 16 '26 08:07 Chang-Jin-Lee

Reproduced — same root cause as #5611 (clipboard "success" is not gated on a confirmed write)

This is the OSC 52 / TUI variant of #5611. When a TUI (Claude Code, OpenCode) copies via an OSC 52 escape, Orca's handler reports the copy as handled and fires the host clipboard write fire-and-forget, so the "Copied" toast shows even when the OS clipboard write silently fails on Windows.

Root cause:

  • src/renderer/src/.../osc52-clipboard.ts:47 — handleOsc52ClipboardRequest returns true ("handled") and does void writeClipboardText(...).catch(() => {}); the write result is never checked.
  • The host handler clipboard:writeText (src/main/window/clipboard-ipc-handlers.ts:143) calls Electron clipboard.writeText and returns without reading back. On Windows, OpenClipboard fails under contention (clipboard managers, RDP, the TUI itself) and Electron's writeText returns void/does not throw — so the failure is invisible and stale clipboard content remains.

Works on macOS because that contention rarely occurs there.

Repro test (covers both the terminal path and the OSC 52 path — both pass, demonstrating success-while-clipboard-unchanged):

npx vitest run --config config/vitest.config.ts src/main/window/clipboard-write-success-lie-5611.repro.test.ts

Fix direction: read back the clipboard after writing and reject on mismatch, propagate that through the OSC 52 handler, and surface a write-failure toast instead of the false "Copied". A fix branch for #5611 (nwparker/fix-5611, commit e3f44dc2f) implements this but is not merged to main.

See #5611 and docs/bug-reproductions/5611-copilot-copy-success-empty-clipboard.md for the full trace.

🔁 Reproduced via automated Windows bug-reproduction pass (shared root cause with #5611).

OrcaWin avatar Jul 18 '26 08:07 OrcaWin

I can confirm same on linux, copy doesn't work

sadiki-o avatar Jul 24 '26 14:07 sadiki-o

Root cause found (and fix confirmed on Windows 11 / Orca 1.4.155): this is the default-off OSC 52 gate, not a broken write path — which is why @Chang-Jin-Lee's investigation correctly found the OSC 52 path itself works.

Mechanism:

  1. terminalAllowOsc52Clipboard defaults to false (src/shared/constants.ts), so OSC 52 clipboard writes from TUIs are blocked on a fresh install.
  2. The OSC 52 parser handler (src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts, the registerOscHandler(52, ...) block) deliberately returns true in both the allowed and blocked paths ("so xterm doesn't fall through") — meaning the TUI has no way to learn the write was rejected. Claude Code / OpenCode proceed to show their own "Copied" confirmation. This is the concrete form of @OrcaWin's "success is not gated on a confirmed write."
  3. The only signal is showOsc52ClipboardBlockedToast, which is easy to miss mid-flow — hence "changing settings does not help" reports when people change other settings.

Workaround that resolves it: Settings → Terminal → enable "Allow OSC 52 clipboard". Verified this immediately fixed Claude Code's "c to copy" (OAuth login URL) on Windows.

Why "works on macOS": TUIs typically use the native clipboard (pbcopy) locally on macOS and only fall back to OSC 52 on Windows terminals / SSH / WSL sessions — so the gate never engages on the working platforms.

Suggested fix (keeping the security default is reasonable — OSC 52 is a clipboard-hijack vector): make the blocked toast actionable (button that opens the Terminal setting), and consider having the handler surface blocked state more persistently (e.g., a status-bar hint after N blocked writes) so the TUI's "Copied" can't be the last word.

dcieslak19973 avatar Jul 25 '26 13:07 dcieslak19973

Status update — PR open for the remaining residual

Hi! Opened a focused fix for the residual path that still matches this report after #10588:

https://github.com/stablyai/orca/pull/10827

What already landed on main

#10588 made OSC 52 default on (with a one-time migration for older profiles). That covers the “TUI shows Copied / Orca blocked the write because the setting was off” class that several folks hit, including the workable Settings → Allow OSC 52 workaround.

What this issue still needed

On Windows especially, Electron can return from clipboard.writeText without updating the OS clipboard. Orca (and the TUI) could still treat the copy as successful — “Copied” toast / TUI confirmation — while paste stayed empty. Same false-success class as #5611.

What #10827 does

  1. Verify standard clipboard writes (write → read back → reject on mismatch)
  2. Surface OSC 52 host write failures with an error toast instead of swallowing them
  3. Route terminal selection copy through a shared helper that only clears selection after a confirmed write

Does not change the OSC 52 security gate (query stays blocked; payload size still capped). Primary selection (X11) is deliberately not read-back verified to avoid Linux false failures.

Relation to open PRs

  • #8997 — Windows PowerShell write path; helpful for write reliability maybe, but doesn’t address “success not gated on a confirmed write.”
  • #6579 / #5611 — same verify-write direction; #10827 is rebased on current main (post-#10588 OSC 52 rewrite) and scoped to close this issue cleanly.

Happy to adjust scope or fold into another PR if maintainers prefer a different packaging. Thanks for filing — Windows TUI copy false-success is a real trust breaker.

innocarpe avatar Jul 27 '26 02:07 innocarpe