You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Clipboard image paste fails with AI_DownloadError due to binary corruption and encoding mismatch #3816
When pasting images from clipboard on Linux, the application fails with an AI_DownloadError when attempting to process the image data URL. This is caused by two bugs in the clipboard handling code:
Bug #1: Binary Data Corruption
The Linux clipboard code (Wayland and X11) uses .text() to read binary PNG data, which attempts to decode the binary image bytes as UTF-8 text. This completely corrupts the image data.
Bug #2: Encoding Mismatch
The clipboard code uses base64url encoding (URL-safe variant with - and _ characters) instead of standard base64 encoding (with + and / characters) required by the data URL specification (RFC 2397).
Environment: Opencode v1.0.15, Ubuntu 25.04 (Omabub), in an Alacritty/Zellij terminal session
Take a screenshot using the system shortcut, saving the image (approx. 800KB - 1.5MB PNG) to the clipboard
In the opencode editor (e.g., in a ~sticky session), paste the image using the terminal's paste command/shortcut (e.g., Ctrl+V)
Resulting Error:
AI_DownloadError: Failed to download data:image/png;base64,77-9UE5HDQoaCgAAAA1JSERSAAAB77-9AAABDggGAAAAUe-_ve-_vWcAAAAEc0JJVAgICAh8CGTvv70AAAAZdEVYdFNvZnR3YXJlAGdub21lLXNjcmVlbnNob3Tvv70D77-9PgAAAC10RVh0Q3JlYXRpb24gVGltZQBNb24gMDMgTm92IDIwMjUgMTE6MzE6MTIgQU0gQ0VU77-9SC8eAAAgAElFTkTvv71CYO-_vQ: Error: failed to fetch the data URL
3. What's the expected vs actual behavior?
Expected Behavior:
When an image is pasted from clipboard, it should be:
Read as binary data (not decoded as text)
Encoded using standard base64 (not base64url)
Embedded in a proper data URL format: data:image/png;base64,<standard-base64-data>
Successfully processed by the AI SDK
Actual Behavior:
The application corrupts the binary image data by decoding it as UTF-8 text, then encodes it with base64url instead of standard base64, resulting in an invalid data URL that the AI SDK cannot process.
4. What's the proposed fix?
In packages/opencode/src/cli/cmd/tui/util/clipboard.ts:
For Linux (Wayland, lines 33-35):
Change .text() to .arrayBuffer() to preserve binary data
Change toString('base64url') to toString('base64')
Add validation: if (wayland && wayland.byteLength > 0)
For Linux (X11, lines 37-39):
Change .text() to .arrayBuffer() to preserve binary data
Change toString('base64url') to toString('base64')
Add validation: if (x11 && x11.byteLength > 0)
For Windows (line 50):
Change toString('base64url') to toString('base64')
This aligns with how macOS correctly handles clipboard images (line 25) and ensures data URLs comply with RFC 2397.
However, your issue provides much more technical detail about the specific binary corruption and encoding mismatch problems in the Linux clipboard handling code, which makes it a valuable technical deep-dive that the other issues don't provide. The specific fixes you've identified for the .text()/.arrayBuffer() and base64url/base64 encoding issues are not covered in the other reports.
Feel free to ignore if none of these address your specific case - your detailed technical analysis appears to be unique among the existing issues.
Activity
fix: correct clipboard image encoding and binary handling (anomalyco#…
github-actions commentedon Nov 3, 2025
This issue might be a duplicate of existing issues. Please check:
However, your issue provides much more technical detail about the specific binary corruption and encoding mismatch problems in the Linux clipboard handling code, which makes it a valuable technical deep-dive that the other issues don't provide. The specific fixes you've identified for the .text()/.arrayBuffer() and base64url/base64 encoding issues are not covered in the other reports.
Feel free to ignore if none of these address your specific case - your detailed technical analysis appears to be unique among the existing issues.