Skip to content

Add screenshot/image paste to the terminal - #3

Open
benfrank241 wants to merge 1 commit into
nicoloboschi:mainfrom
benfrank241:screenshot-paste
Open

Add screenshot/image paste to the terminal#3
benfrank241 wants to merge 1 commit into
nicoloboschi:mainfrom
benfrank241:screenshot-paste

Conversation

@benfrank241

Copy link
Copy Markdown

What & why

Pasting an image (e.g. a macOS screenshot on the clipboard, Cmd+Ctrl+Shift+4 then Cmd+V) into a terminal pane currently does nothing. xterm only handles text paste and silently drops image blobs — and since the shell (Claude Code in particular) runs in a server-side PTY, there's no local clipboard for it to read from either.

How

ui/src/components/TerminalCell.tsx:

  • Add a capture-phase paste listener on the terminal container. It runs before xterm's hidden textarea sees the event, so image pastes can be handled and text pastes pass straight through untouched.
  • When the clipboard has image items, upload them to the session's cwd via the existing POST /api/fs/upload endpoint, then type the resulting on-disk path into the PTY ({type:'input', data: path}).
  • This is the same path-handoff the existing file-drop handler already uses — tools like Claude Code recognize an image path and attach it. The shared logic is factored out of handleDrop into a new uploadBlobsAndType helper.
  • A small "Attaching image…" badge provides feedback (drop has a drag overlay; paste has none).

Pasted screenshots are saved as pasted-<timestamp>.png in the session cwd.

Notes

  • Frontend-only, one file. No backend or dependency changes; reuses /api/fs/upload + /api/fs/:id/browse.
  • Text paste behavior is unchanged (the handler early-returns when there are no image items).
  • tsc typecheck and vite build both pass.

Test plan

  1. Copy a screenshot to the clipboard.
  2. Focus a terminal pane running Claude Code and press Cmd+V.
  3. The image uploads (badge shows briefly) and its path is typed into the prompt; Claude Code attaches it as [Image #N].
  4. Verify a plain-text paste still pastes text as before.

🤖 Generated with Claude Code

Pasting an image (e.g. a macOS screenshot sitting on the clipboard) into
a terminal pane did nothing: xterm only handles text paste and silently
drops image blobs. And because the shell — Claude Code in particular —
runs in a server-side PTY, there is no local clipboard for it to read
from either.

Intercept the paste in the capture phase on the terminal container,
upload any image items to the session cwd via the existing
/api/fs/upload endpoint, and type the resulting on-disk path into the
PTY. That is the same path-handoff the file-drop handler already relies
on, and tools like Claude Code recognize an image path and attach it.
Plain-text pastes are left untouched and flow through to xterm normally.

The upload logic is factored out of handleDrop into a shared
uploadBlobsAndType helper, and a small "Attaching image…" badge gives
paste feedback (drop has a drag overlay; paste has none). Pasted
screenshots are saved as pasted-<timestamp>.png in the session cwd.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant