{"record":{"id":"a4928bc6db4e2075","repo":"nikivdev/code","slug":"clipboard-command-exited-with-status","errorCode":null,"errorMessage":"clipboard command exited with status {}","messagePattern":"clipboard command exited with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ai.rs","lineNumber":14196,"sourceCode":"            .spawn();\n\n        let mut child = match result {\n            Ok(c) => c,\n            Err(_) => Command::new(\"xsel\")\n                .arg(\"--clipboard\")\n                .arg(\"--input\")\n                .stdin(Stdio::piped())\n                .spawn()\n                .context(\"failed to spawn xclip or xsel\")?,\n        };\n\n        if let Some(stdin) = child.stdin.as_mut() {\n            stdin.write_all(text.as_bytes())?;\n        }\n\n        let status = child.wait()?;\n        if !status.success() {\n            bail!(\"clipboard command exited with status {}\", status);\n        }\n    }\n\n    #[cfg(not(any(target_os = \"macos\", target_os = \"linux\")))]\n    {\n        bail!(\"clipboard not supported on this platform\");\n    }\n\n    Ok(())\n}\n\n/// Strip <thinking> blocks from content (internal Claude processing).\nfn strip_thinking_blocks(s: &str) -> String {\n    let mut remaining = s;\n    let mut out = String::new();\n\n    loop {\n        let Some(start) = remaining.find(\"<thinking>\") else {","sourceCodeStart":14178,"sourceCodeEnd":14214,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ai.rs#L14178-L14214","documentation":"On Linux the clipboard helper tries `xclip` first, then `xsel`, invoking whichever exists and writing text to its stdin. If the chosen command exits nonzero, the code bails with its exit status. Unlike the missing-binary cases, the command was found and executed but failed to place text on the X11/Wayland clipboard.","triggerScenarios":"xclip/xsel cannot connect to an X display (DISPLAY unset) — e.g. SSH, systemd service, Wayland-only session without XWayland; the binary exists but crashes or is denied clipboard access; sandboxed/CI environments without a clipboard server.","commonSituations":"Wayland desktops where xclip targets X11 via XWayland and fails; SSH sessions to a Linux desktop; cron/systemd units lacking DISPLAY/XAUTHORITY; containers with no X server.","solutions":["Ensure a display is available: check `echo $DISPLAY` and set DISPLAY/XAUTHORITY if running from SSH or a service","Install a working clipboard tool: `apt install xclip` or use `wl-copy` (wl-clipboard) on Wayland","Test directly: `echo test | xclip -selection clipboard` to reproduce the failure outside the tool","Run the command inside the graphical session (e.g. via the desktop terminal) instead of a headless context"],"exampleFix":"// before (SSH, no DISPLAY)\n$ echo hi | xclip -selection clipboard\nError: Can't open display: (null)\n$ myapp ai copy last\nError: clipboard command exited with status 1\n// after (inside desktop session or with wl-clipboard on Wayland)\n$ echo hi | wl-copy\n$ myapp ai copy last   # succeeds","handlingStrategy":"fallback","validationCode":"use std::process::Command;\nfn clipboard_cmd_available() -> bool {\n    [\"xclip\", \"xsel\", \"wl-copy\"].iter().any(|c| {\n        Command::new(c).arg(\"--version\").output().is_ok()\n            || Command::new(c).output().is_ok()\n    })\n}\nif !clipboard_cmd_available() { eprintln!(\"install xclip/wl-clipboard\"); }","typeGuard":null,"tryCatchPattern":"match copy_to_clipboard(text) {\n    Err(e) if e.to_string().starts_with(\"clipboard command exited\") => {\n        eprintln!(\"clipboard failed ({e}); ensure DISPLAY/XAUTHORITY are set or use wl-copy\");\n        println!(\"{text}\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Always run from an environment with DISPLAY set (desktop session) or use wl-clipboard on Wayland","For SSH/services, forward the clipboard or write to a temp file instead of the pasteboard","Test `echo t | xclip -selection clipboard` when configuring a new desktop/CI environment","Install xclip or wl-clipboard in environment bootstrap so the helper always finds a backend"],"tags":["clipboard","linux","x11","wayland","process-exit"],"backgroundTag":"clipboard-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}