WSL(Windows Subsystem for Linux)上の Ubuntu で Claude Code を使うとき、画像ペーストと Typeless(音声入力)のテキストペーストが Ctrl+V を奪い合って共存できない問題がある。この記事ではその解決方法をまとめる。
問題
Claude Code は画像ペーストに Ctrl+V を使う。内部的には xclip コマンドでクリップボードを読みに行くが、WSL の xclip は Windows 側のクリップボードの画像を読めない。
さらに Typeless(音声入力ツール)もテキストのペーストに Ctrl+V を送信するため、キーが衝突する。
解決の方針
-
Claude Code の画像ペースト →
Alt+Vに変更 -
Typeless のテキストペースト →
Ctrl+V(Windows Terminal のペースト) - xclip ラッパー → PowerShell 経由で Windows 側のクリップボード画像を取得
手順
1. xclip をインストール
sudo apt install xclip
本物の xclip を入れておく。ラッパーから委譲先として使う。
2. xclip ラッパーを作成
~/.local/bin/xclip に以下のスクリプトを作成する。
Claude Code が内部で叩く xclip の呼び出しをフックして、Windows 側のクリップボードから画像を取得する仕組み。
mkdir -p ~/.local/bin
cat << 'EOF' > ~/.local/bin/xclip
#!/bin/bash
# TARGETS チェック(Claude Code が画像の有無を確認する)
if [[ "$*" == *"-t TARGETS"* && "$*" == *"-o"* ]]; then
result=$(/usr/bin/xclip "$@" 2>/dev/null)
if echo "$result" | grep -q "image/"; then
echo "$result"
else
# Windows 側のクリップボードを確認
has_image=$(powershell.exe -NoProfile -Command '
Add-Type -AssemblyName System.Windows.Forms
if ([System.Windows.Forms.Clipboard]::ContainsImage()) { Write-Output "yes" }
' 2>/dev/null | tr -d '\r')
if [ "$has_image" = "yes" ]; then
echo -e "image/png\nTARGETS"
else
/usr/bin/xclip "$@" 2>/dev/null
fi
fi
# 画像データ取得
elif [[ "$*" == *"-t image/"* && "$*" == *"-o"* ]]; then
powershell.exe -NoProfile -Command '
Add-Type -AssemblyName System.Windows.Forms
$img = [System.Windows.Forms.Clipboard]::GetImage()
if ($img) {
$ms = New-Object System.IO.MemoryStream
$img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
[Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length)
}' 2>/dev/null
# それ以外は本物の xclip に委譲
else
/usr/bin/xclip "$@"
fi
EOF
chmod +x ~/.local/bin/xclip
3. PATH を設定
.bashrc でラッパーが /usr/bin/xclip より先に見つかるようにする。
export PATH="$HOME/.local/bin:$PATH"
確認:
which xclip
# → /home/<user>/.local/bin/xclip ならOK
4. Claude Code のキーバインドを変更
画像ペーストを Alt+V に変更して、Ctrl+V を Typeless に譲る。
~/.claude/keybindings.json を作成:
{
"$schema": "https://www.schemastore.org/claude-code-keybindings.json",
"bindings": [
{
"context": "Chat",
"bindings": {
"ctrl+v": null,
"alt+v": "chat:pasteImage"
}
}
]
}
5. Windows Terminal のキーバインドを設定
Typeless が Ctrl+V でテキストをペーストできるように、Windows Terminal に Ctrl+V のペーストバインドを追加する。
Windows Terminal の settings.json に以下を追加:
"keybindings": [
{
"id": "User.paste",
"keys": "ctrl+v"
}
]
6. 動作確認
Windows 側でスクリーンショットをクリップボードにコピーしてから:
# TARGETS 確認
xclip -selection clipboard -t TARGETS -o
# → image/png が出ればOK
# 画像データ取得確認
xclip -selection clipboard -t image/png -o > /tmp/test.png
file /tmp/test.png
# → PNG image data... ならOK
# Claude Code で Alt+V → 画像が添付されれば成功
まとめ
| キー | 動作 |
|---|---|
Alt+V |
Claude Code の画像ペースト |
Ctrl+V |
Typeless のテキストペースト(Windows Terminal 経由) |
Ctrl+Shift+V |
ターミナルのテキストペースト |
本質は「WSL の xclip は Windows 側クリップボードの画像を読めない」という問題を PowerShell ブリッジで解決しているだけ。Typeless との共存はキーバインドの棲み分けで対処する。