nikivdev/code · error

clipboard not supported on this platform

Error message

clipboard not supported on this platform

What it means

The clipboard helper is explicitly platform-gated: macOS uses pbcopy, Linux uses xclip/xsel, and any other target (Windows, BSDs, etc.) hits a `#[cfg(not(any(target_os = "macos", target_os = "linux")))]` block that unconditionally bails with this message. The feature simply has no implementation for that platform.

Source

Thrown at src/ai.rs:14202

                .arg("--input")
                .stdin(Stdio::piped())
                .spawn()
                .context("failed to spawn xclip or xsel")?,
        };

        if let Some(stdin) = child.stdin.as_mut() {
            stdin.write_all(text.as_bytes())?;
        }

        let status = child.wait()?;
        if !status.success() {
            bail!("clipboard command exited with status {}", status);
        }
    }

    #[cfg(not(any(target_os = "macos", target_os = "linux")))]
    {
        bail!("clipboard not supported on this platform");
    }

    Ok(())
}

/// Strip <thinking> blocks from content (internal Claude processing).
fn strip_thinking_blocks(s: &str) -> String {
    let mut remaining = s;
    let mut out = String::new();

    loop {
        let Some(start) = remaining.find("<thinking>") else {
            out.push_str(remaining);
            break;
        };

        out.push_str(&remaining[..start]);
        let after_start = &remaining[start + "<thinking>".len()..];

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run the tool under WSL on Windows, where target_os is linux and the xclip/xsel path applies
  2. Add support: install a clipboard helper and patch the helper to shell out to `clip.exe` (Windows) or use the `arboard`/`cli-clipboard` crate for portable clipboard access
  3. Avoid the copy command on unsupported platforms and redirect output to a file/stdout instead

Example fix

// before (src/ai.rs)
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
{
    bail!("clipboard not supported on this platform");
}
// after
#[cfg(target_os = "windows")]
{
    let mut child = Command::new("clip")
        .stdin(Stdio::piped())
        .spawn()?;
    child.stdin.as_mut().unwrap().write_all(text.as_bytes())?;
    child.wait()?;
}
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
{
    bail!("clipboard not supported on this platform");
}
Defensive patterns

Strategy: fallback

Validate before calling

#[cfg(target_os = "unknown-platform")]
compile_error!("clipboard unsupported; build on macOS/Linux or use WSL on Windows");

// runtime guard
fn clipboard_supported() -> bool {
    cfg!(any(target_os = "macos", target_os = "linux"))
}
if !clipboard_supported() {
    eprintln!("no clipboard support; writing to file instead");
    std::fs::write("out.txt", text).unwrap();
    return;
}

Try / catch

match copy_to_clipboard(text) {
    Err(e) if e.to_string() == "clipboard not supported on this platform" => {
        eprintln!("platform unsupported; saved output to file instead");
        std::fs::write("clipboard-fallback.txt", text)?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling any clipboard-copy command on a non-macOS/non-Linux target — e.g. building/running on Windows natively; cross-compiling and running the binary on an unsupported OS.

Common situations: Windows users running the tool natively (works fine under WSL, which reports Linux); CI runners on Windows; contributors testing the clipboard path on an unusual platform.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/138f74709a69be02. Report an issue: GitHub.