Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Dec 22, 2025

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

On Windows, pressing Ctrl+V with an image in clipboard (e.g., from Greenshot)
didn't work because:
1. The terminal doesn't properly send image data through bracketed paste
2. Clipboard.read() was only called when paste text was empty

This fix adds explicit keybind handling in onKeyDown to:
- Intercept Ctrl+V before the terminal handles it
- Call Clipboard.read() directly to check for images
- If an image is found, paste it and prevent default
- If no image, let normal text paste flow continue
@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link
Contributor

lgtm

@rekram1-node rekram1-node merged commit 2062247 into sst:dev Dec 22, 2025
2 checks passed
@nielpattin
Copy link

nielpattin commented Dec 22, 2025

@zzzeian was something broken with the Greenshoot or with Windows Terminal that you can't paste image?

  • Which terminal you using?
  • Because right now(before this PR merged) in Wezterm or Alacritty can just default paste image just fine.
  • Windows Terminal need to disable "Remove trailing white-space when pasting" in the setting.
  • Are you using wsl?
  • I'm using ShareX to capture image, not sure what happened with your.

shuv1337 pushed a commit to Latitudes-Dev/shuvcode that referenced this pull request Dec 22, 2025
oneopane pushed a commit to oneopane/opencode that referenced this pull request Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants