Repository navigation
Description
Problem
Selecting text in the jcode TUI shows the “Copied selection” toast, but the system clipboard remains unchanged. Previous clipboard contents
are preserved.
Environment
• OS: Kali Linux Rolling 2026.3 (also reproduced on Ubuntu-based X11)
• jcode: v0.64.2 (6c6fbba)
• Display server: X11 (DISPLAY=:0, WAYLAND_DISPLAY unset, XDG_SESSION_TYPE=x11)
• Terminal: GNOME Terminal 3.52.0 (VTE 0.76.0)
• Installed clipboard tools: xclip 0.13, xsel 1.2.1, wl-clipboard 2.2.1
Root cause analysis
The Linux clipboard path in crates/jcode-tui/src/tui/app/helpers.rs tries wl-copy, then arboard, then OSC 52.
- wl-copy — fails fast in ~11ms (no Wayland display). Falls through correctly.
- arboard — Clipboard::new() opens a new X11 connection, sets the selection via set_text(), returns Ok, then the Clipboard object is dropped.
The X11 connection closes. The clipboard data is immediately lost because no X client is holding the selection. - OSC 52 — gnome-terminal supports it, but by this point the function already returned true from step 2.
The core issue: arboard on X11 does not fork a background process to keep the X11 selection owner alive (unlike xsel which does fork() +
setsid() to stay alive). When the Clipboard handle is dropped, the selection vanishes before anything can paste it.
Verification
┌─ [Alt] [⇧] [S]
│ $ echo "test" | xsel --clipboard --input # works, stays alive
│ $ xclip -selection clipboard -o # returns "test"
│ $ python3 -c "import arboard; ..." # arboard sets then drops
│ $ xclip -selection clipboard -o # returns empty / old content
└─
xsel and xclip work correctly on this system. The issue is specifically how arboard manages the X11 selection lifetime inside the TUI.
Comparison with opencode
OpenCode (Go) calls xclip -selection clipboard directly via child process, which keeps the process alive until paste. This works correctly on
the same system.
╷
Suggested fix │
On Linux X11, after arboard sets the clipboard, keep the X11 connection alive until a paste occurs, or fork a background process (like xsel │
does) to serve selection requests. Alternatively, consider calling xclip/xsel as a subprocess on Linux (like OpenCode does) instead of relying │
on arboard’s in-process X11 implementation. ╵
Activity
iwanro commentedon Jul 31, 2026
### fix(tui): add xclip/xsel clipboard fallback on Linux X11
Problem
│
│ Selecting text in the jcode TUI on Linux X11 shows "Copied selection" toast,
│ but the system clipboard remains empty. Issues #497 (Windows), #504 (Linux),
│ and #505 (macOS) all describe variants of this. The macOS and Windows fixes
│ use arboard as authoritative, but on Linux the fallback chain is:
│
│ 1. wl-copy -- fails fast on X11 (correct)
│ 2. arboard -- sets text, drops X11 connection immediately, clipboard lost
│ 3. OSC 52 -- too late
│
│ arboard does not fork a background process to keep the X11 selection owner
│ alive. When the
Clipboardhandle is dropped, the X11 connection closes│ and the selection vanishes before anything can paste it.
│
│ ## Fix
│
│ Insert
xclipandxselas subprocess calls between wl-copy and arboard.│ Both tools fork a background process that serves paste requests, matching
│ how opencode (Go) handles clipboard on Linux.
│
│ New Linux clipboard order:
│ wl-copy (Wayland) -> xclip (X11) -> xsel (X11) -> arboard -> OSC 52
│
│ Uses the same subprocess+poll pattern already established for wl-copy:
│ spawn with piped stdin, write text, poll 150ms for early failure, treat
│ a still-running child as success and reap in background.
│
│ ## Verified
│
│ - Kali Linux Rolling 2026.3, X11, GNOME Terminal 3.52.0
│ - xclip 0.13, xsel 1.2.1, wl-clipboard 2.2.1
│ -
cargo build --releasesucceeds│ - Python simulation of exact code path: clipboard content verified
matthewhua commentedon Jul 31, 2026
I ran into this bug before too
1jehuang commentedon Jul 31, 2026
Confirmed and fixed in
5b092b582onmaster. Your root-cause analysis was exactly right.jcode now tries
xclipthenxselbeforearboardon non-Wayland Linux, for the reason you gave: both fork a process that keeps owning the X11 selection until a paste, whereas arboard's selection dies with theClipboardhandle. The spawn logic (shared withwl-copy) moved into its own module with tests covering success, nonzero exit, missing binary, and the non-blocking contract, so a long-lived clipboard owner cannot stall the UI thread.OSC 52 remains the final fallback for genuinely headless/remote sessions. Thanks for the clear verification steps and the opencode comparison.
— Jcode agent (automated triage), on behalf of @1jehuang
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the #684/#687/#689 fixes through their real integration …
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…
fix(tui): use xclip/xsel for X11 copy so the selection survives (fixes …
test: verify the 1jehuang#684/1jehuang#687/1jehuang#689 fixes through…