Skip to content

Add image/bmp to Linux clipboard check for WSL2 image paste #25935

@LBranigan

Description

@LBranigan

Summary

Claude Code's Linux checkImage command excludes image/bmp from its grep pattern. This silently breaks image paste for all WSL2 users, because Windows copies images as BMP by default and WSLg forwards that format unchanged via Wayland.

A one-line fix would resolve this for every WSL2 user.

Root Cause

In cli.js, the Linux clipboard detection command is:

xclip -selection clipboard -t TARGETS -o 2>/dev/null \
  | grep -E "image/(png|jpeg|jpg|gif|webp)" \
  || wl-paste -l 2>/dev/null \
  | grep -E "image/(png|jpeg|jpg|gif|webp)"

image/bmp is missing from the pattern. When the clipboard contains BMP (the Windows default), checkImage returns exit code 1 and SD1() silently returns null — no error, no feedback.

Proposed Fix

Add bmp to the grep pattern:

- grep -E "image/(png|jpeg|jpg|gif|webp)"
+ grep -E "image/(png|jpeg|jpg|gif|webp|bmp)"

And add a BMP conversion path in saveImage (since the rest of the pipeline expects PNG):

wl-paste --type image/bmp 2>/dev/null | convert bmp:- png:"${TMPFILE}" 2>/dev/null

Or simply add BMP to the check and let ImageMagick/Sharp handle the conversion downstream.

Evidence

Tested on WSL2 (Ubuntu), Windows Terminal, Claude Code 2.1.42, Node v22.22.0:

Command Result
wl-paste -l image/bmp (Windows default)
wl-paste --type image/bmp | file - Valid BMP image data
checkImage (as-is) Exit 1 — grep misses image/bmp
checkImage (with bmp added) Exit 0
Manual BMP→PNG + Alt+V Works perfectly

The full checkImagesaveImage → base64 pipeline works once BMP is converted to PNG. The only failure point is the grep pattern.

Impact

This affects every WSL2 user who tries to paste images. WSL2 is a common developer environment, and this is the #1 reported image paste issue:

Current Workaround

A background daemon (clip2png --watch) that polls the Wayland clipboard every 2 seconds and converts BMP→PNG via ImageMagick. Combined with a custom keybinding (alt+vchat:imagePaste since Windows Terminal intercepts the default ctrl+v), this makes image paste work on WSL2. But it requires ImageMagick, a watcher script, Claude Code hooks, and custom keybindings — all to work around a missing format in a grep pattern.

Environment

  • Platform: WSL2 (Ubuntu) on Windows 11
  • Terminal: Windows Terminal
  • Claude Code: 2.1.42
  • Node: v22.22.0
  • Clipboard: WSLg Wayland (wl-paste/wl-copy)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestplatform:wslIssue specifically occurs on WSL

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions