[PR #5919] fix: support clipboard image paste (Ctrl+V) on Windows #11646

Closed
opened 2026-02-16 18:16:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5919

State: closed
Merged: Yes


Summary

Fixes clipboard image paste not working on Windows when using Ctrl+V (e.g., after capturing a screenshot with Greenshot).

Problem

On Windows, pressing Ctrl+V with an image in the clipboard didn't paste the image because:

  1. The terminal (ConPTY) doesn't properly send image data through bracketed paste events
  2. Clipboard.read() was only called when the paste event text was empty
  3. Windows terminals often send non-empty text or don't fire the paste event at all for clipboard images

Solution

Added explicit keybind handling in onKeyDown (in the prompt component) to:

  • Intercept Ctrl+V before the terminal handles it
  • Call Clipboard.read() directly to check for images in the clipboard
  • If an image is found, paste it using pasteImage() and prevent default
  • If no image is found, let the normal text paste flow continue

Testing

  1. Use Greenshot (or any screenshot tool) to capture a region to clipboard
  2. In OpenCode CLI, press Ctrl+V
  3. The image should now be pasted as [Image 1] in the prompt

Changes

  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx: Added keybind check for input_paste in onKeyDown handler
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5919 **State:** closed **Merged:** Yes --- ## Summary Fixes clipboard image paste not working on Windows when using Ctrl+V (e.g., after capturing a screenshot with Greenshot). ## Problem On Windows, pressing Ctrl+V with an image in the clipboard didn't paste the image because: 1. The terminal (ConPTY) doesn't properly send image data through bracketed paste events 2. `Clipboard.read()` was only called when the paste event text was empty 3. Windows terminals often send non-empty text or don't fire the paste event at all for clipboard images ## Solution Added explicit keybind handling in `onKeyDown` (in the prompt component) to: - Intercept Ctrl+V **before** the terminal handles it - Call `Clipboard.read()` directly to check for images in the clipboard - If an image is found, paste it using `pasteImage()` and prevent default - If no image is found, let the normal text paste flow continue ## Testing 1. Use Greenshot (or any screenshot tool) to capture a region to clipboard 2. In OpenCode CLI, press Ctrl+V 3. The image should now be pasted as `[Image 1]` in the prompt ## Changes - `packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx`: Added keybind check for `input_paste` in `onKeyDown` handler
yindo added the pull-request label 2026-02-16 18:16:32 -05:00
yindo closed this issue 2026-02-16 18:16:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11646