-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
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/nullOr 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 checkImage → saveImage → 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:
- [BUG] Bug/Feature: Clipboard image paste not working in WSL #13738 — Clipboard image paste not working in WSL (open, 13+ reports)
- [BUG] Can't paste image from clipboard #1361 — Can't paste image from clipboard (open, 40+ comments)
- [BUG] Cannot copy screenshots to Claude Code chat when running from WSL terminal in Windows #3150 — Cannot copy screenshots from WSL (closed, redirected)
- Clipboard Access Error in WSL2 - xclip/wl-paste fail without X11 #14635 — Clipboard Access Error in WSL2 (open)
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+v → chat: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)