GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): clipboard copy on Linux without external binaries by fQwQf · Pull Request #44394 · anomalyco/opencode

Conversation

@fQwQf

@fQwQf fQwQf commented Aug 23, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #29834
Closes #24713
Closes #41470

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Linux, copy silently fails when no external tool (wl-copy/xclip/xsel) is installed and the terminal ignores OSC 52 (e.g. GNOME Terminal/VTE). The toast says "Copied to clipboard" but nothing is copied, because clipboardy's bundled xsel fallback doesn't exist inside the compiled binary and every failure is swallowed by .catch(() => undefined).

Changes:

  • New pure-JS X11 selection owner (src/clipboard/x11.ts, via the x11 package, no native code). It claims the CLIPBOARD selection and serves paste requests for the TUI's lifetime. On Wayland this works through XWayland, and the compositor keeps the content after exit.
  • write() now picks backends by environment instead of trying everything: SSH sessions only use tmux/OSC 52 (native clipboard on the remote host is useless); local Linux tries the X11 owner, then any installed tools, then OSC 52. If every backend fails, the error is thrown so the UI shows a real error instead of a false success.
  • OSC 52 now writes to /dev/tty when stdout isn't a TTY and caps payloads at 100 KB.
  • read() gets the same pure-JS X11 fallback for text.

How did you verify your code works?

  • bun test packages/tui/test/clipboard.test.ts (6 backend-routing cases) and the full tui suite pass; monorepo typecheck passes (pre-push hook).
  • Manually on Debian 13, GNOME Terminal , Wayland, with no clipboard tools installed: copied text pastes into other apps. Verified with a standalone bun --compile binary, the setup where it previously failed.
  • Reviewer repro: on a similar machine, build with ./packages/opencode/script/build.ts --single, copy a message in the TUI, paste elsewhere.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
fQwQf added 5 commits August 19, 2026 10:24
@fQwQf
feat(tui): add pure-JS X11 clipboard owner
4d31e3d
Implements an ICCCM selection owner over the X11 protocol using the
pure-JS x11 package, requiring no external binaries (wl-copy/xclip/xsel)
and surviving bundling into the compiled binary. Works on native X11 and
on Wayland via XWayland, where the compositor bridges the CLIPBOARD
selection to the Wayland clipboard and persists it after process exit.

The connection is kept alive for the TUI lifetime (same ownership
semantics as codex's ClipboardLease) so paste requests can be served.
Large payloads are written with chunked ChangeProperty appends.
@fQwQf
fix(tui): route clipboard writes through environment-aware backend chain
46f4c87
Model the copy path after codex's clipboard_copy.rs:

- SSH sessions only use terminal-mediated copy (tmux load-buffer -w, or
  OSC 52), since a native clipboard on the remote host is unreachable.
- Local Linux sessions prefer the pure-JS X11 selection owner, then any
  installed external tools, then OSC 52.
- Backend failures are collected and thrown instead of being swallowed,
  so the UI shows an error instead of a false 'Copied to clipboard'
  toast (fixes silent failures like anomalyco#29834, anomalyco#24713, anomalyco#41470).
- OSC 52 writes to /dev/tty when stdout is not a TTY and caps payloads
  at 100KB, matching codex.
- read() gains a pure-JS X11 text fallback instead of relying on
  clipboardy's bundled xsel binary, which is absent from the compiled
  binary.
@fQwQf
test(tui): cover clipboard backend routing plan
6925ed3
@fQwQf
refactor(tui): type the x11 module declaration to satisfy lint
bdfe0fb
@fQwQf
fix(tui): reference x11 type declarations for cross-package typecheck
c66d186
@github-actions github-actions Bot mentioned this pull request Aug 23, 2026
fix(tui): enable copy on select by default #44393
Closed
3 of 6 tasks
@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs that address clipboard functionality on Linux:

Related PRs:

  1. fix(tui): surface clipboard write failures instead of false success #41924 - fix(tui): surface clipboard write failures instead of false success

    • Directly related: addresses surfacing clipboard failures instead of silently failing (same root problem as PR fix(tui): clipboard copy on Linux without external binaries #44394)
  2. fix: enable primary clipboard copy for Wayland/X11 to fix Linux middle-click paste #6370 - fix: enable primary clipboard copy for Wayland/X11 to fix Linux middle-click paste

    • Related to X11/Wayland clipboard handling on Linux
  3. feat(tui): add linux_clipboard_selection config for primary buffer support #32370 - feat(tui): add linux_clipboard_selection config for primary buffer support

    • Related to Linux clipboard selection configuration
  4. fix(clipboard): write OSC52 to /dev/tty instead of stdout #12129 - fix(clipboard): write OSC52 to /dev/tty instead of stdout

    • Directly related: addresses OSC 52 clipboard handling (mentioned in PR fix(tui): clipboard copy on Linux without external binaries #44394 description)

The most relevant is #41924 which appears to address the same issue of surfacing clipboard failures. You should verify if #44394 builds on or replaces that work, or if they address different aspects of the same problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Enough1122

Enough1122 commented Aug 23, 2026

Copy link
Copy Markdown

AI code review — automated review for reference, author can ignore or act on any point.

Diff too large for automated batch review (6 changed files, +3591/-3276) — recommending manual human review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@simonklee

simonklee commented Aug 24, 2026

Copy link
Copy Markdown
Member

This has been fixed in the next version of OpenCode.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@simonklee simonklee closed this Aug 24, 2026
@WqxLoveCoding

WqxLoveCoding commented Aug 25, 2026

Copy link
Copy Markdown

This has been fixed in the next version of OpenCode.

Hello, could you let us know in which version this fix will be released? (I haven't seen it mentioned in the release notes for v1.18.22 or v1.18.23 yet.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@simonklee

simonklee commented Aug 25, 2026

Copy link
Copy Markdown
Member

This has been fixed in the next version of OpenCode.

Hello, could you let us know in which version this fix will be released? (I haven't seen it mentioned in the release notes for v1.18.22 or v1.18.23 yet.)

https://opencode.ai/v2/docs

fQwQf reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fQwQf
fQwQf deleted the fix/tui-linux-clipboard branch August 25, 2026 12:28
@WqxLoveCoding

WqxLoveCoding commented Aug 25, 2026

Copy link
Copy Markdown

This has been fixed in the next version of OpenCode.

Hello, could you let us know in which version this fix will be released? (I haven't seen it mentioned in the release notes for v1.18.22 or v1.18.23 yet.)

https://opencode.ai/v2/docs

I've already installed OpenCode2. How do I upgrade to the latest version?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OberdanBrito OberdanBrito mentioned this pull request Sep 17, 2026
“Copied to clipboard” doesn't work #41470
Closed
@OberdanBrito

OberdanBrito commented Sep 17, 2026

Copy link
Copy Markdown

Any chance of revisiting this? The issue (#41470) persists on Ubuntu without clipboard tools. Your X11 pure-JS approach would be the proper fix.

MarioNoll reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

“Copied to clipboard” doesn't work Clipboard copy not working on Ubuntu 24.04 (GNOME Terminal) Copy shows copied popup but clipboard remains unchanged on Linux terminal

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@fQwQf @Enough1122 @simonklee @WqxLoveCoding @OberdanBrito
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.