Orphaned xclip processes leak an open X selection grab, causing intermittent desktop freeze (Linux)
Environment: Claude Code 2.1.218, Linux Mint (Ubuntu 24.04 base), kernel 6.8.0-136, X11
Description
During normal Claude Code sessions, the CLI spawns xclip -selection clipboard and xclip -selection primary (likely for clipboard-sync on copy). These processes are left orphaned (PPID reparented to 1) with stdin attached to a live, never-closed Unix socket. They never exit, and hold the X PRIMARY/CLIPBOARD selection open indefinitely.
Effect
Any X client that queries/negotiates selection ownership blocks waiting on the unresponsive xclip, producing an intermittent full-desktop freeze — cursor becomes a crosshair, screen appears frozen, clears transiently on click, may recur several times before releasing. Reproduces across desktop environments (confirmed in both Cinnamon and Xfce) and even with the mouse physically disconnected, since it's an X-protocol-level stall, not an input-hardware issue.
Reproduction
Run several Claude Code shell commands in a session (e.g. repeated cargo build/clippy invocations); check ps aux | grep xclip — orphaned pairs accumulate over the session. Confirmed correlated with freeze reports 4/4 times by checking for live xclip processes at the moment of each freeze.
Workaround
pkill -9 xclip clears it instantly.
Suggested fix
Close xclip's stdin (or use a bounded write + explicit process wait/kill) after the clipboard write completes, rather than leaving the pipe open indefinitely.
3 Comments
Correction: further testing shows these orphaned xclip processes are present continuously in the background (spawned per Bash tool call) regardless of whether a freeze is occurring — this was a confound in my original correlation, not causal. The actual freeze cause is still unidentified. Apologies for the noise; leaving this open only as an FYI that Claude Code does leave xclip processes orphaned (which may be worth fixing on its own merits), but it is NOT the cause of the desktop freeze originally reported here.
Partially reproduced on 2.1.233 (Linux, X11).
After a single clipboard copy from the CLI, I can confirm two
xclipprocesses are left behind (xclip -selection primaryandxclip -selection clipboard), both reparented to PID 1 with stdin attached to a live, never-closed socket — exactly as described. They hold the PRIMARY and CLIPBOARD selections for the rest of the session (in my testing they did exit once the Claude Code process itself exited, and a subsequent copy replaced the previous pair rather than stacking, so accumulation likely comes from running several concurrent sessions — one lingering pair each).I could not verify the desktop-freeze effect itself in a headless X server (no desktop environment / clipboard manager present to do the selection negotiation that stalls), so that part is unconfirmed but consistent with the leaked processes above.
One note: any X11 clipboard write needs some process to stay alive to serve the selection (that's how X selections work), so a lingering owner isn't entirely avoidable — but the open-stdin orphaned processes reported here are real and reproducible.
🤖 Generated with Claude Code
Another data point for the freeze link, with a reproducible mechanism on the xclip side.
Environment: Claude Code 2.1.283,
"tui": "fullscreen"(copyOnSelect at its default), KDE Plasma 6.7.5 on X11, Alacritty, xclip 0.13 (Arch package, built from the 0.13 tag).What happened: The panel clock froze, plasmashell stopped answering D-Bus, and Dolphin got the "not responding" dialog (stack:
KFileItemClipboard::updateCutItems→QMimeData::data→QInternalMimeData::formats→ QXcbClipboard wait). The PRIMARY owner at that moment was a daemonizedxclip -selection primaryspawned by Claude Code (reparented to systemd --user, stdin a socket). Killing that single process made plasmashell respond again immediately.Why this takes down the whole desktop on KDE: Klipper runs inside plasmashell, reads PRIMARY on every change and owns CLIPBOARD itself. While plasmashell waits on an unresponsive PRIMARY owner (Qt waits 5 s per request, several requests per read), every other application that reads CLIPBOARD waits on plasmashell.
Mechanism in xclip 0.13 (reproduced on Xvfb with a Qt requestor):
formats()takes 5 s andtext()20 s, indefinitely.I could not reproduce a hang with small selections, and the size of the copy that triggered it is unknown, so the xclip bug may not be the whole story.
Claude Code side:
Workaround: install xclip from git (e.g.
xclip-giton the AUR).