feat: image paste (Ctrl+V) and drag-and-drop into terminal#84
Open
aakhter wants to merge 1 commit into
Open
Conversation
Clipboard paste (Ctrl+V) and drag-and-drop of image files into the
terminal. Images are saved to {workdir}/.claude-images/ and the
absolute path is inserted into the terminal input for Claude to read.
- POST /api/sessions/:id/paste-image endpoint (hand-parsed multipart)
- image-input.js mixin with paste trap technique (works on HTTP)
- Ctrl+V intercepted at xterm keyboard level, routes through hidden
contenteditable div to capture both image and text clipboard data
- Drag-and-drop on terminal container with visual overlay
- Session cleanup deletes .claude-images/ on destroy
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets users paste or drop images into the terminal. The image is saved to
${workdir}/.claude-images/and the absolute file path is inserted at the cursor — Claude (or any other CLI that reads file paths from stdin) can then process the image without the user having to manually save and@-mention it.Two entry points:
Mixed-content paste (image + text together) works — both the image is saved as a file and the text is forwarded to the terminal.
Implementation
POST /api/sessions/:id/paste-image— hand-parsed multipart endpoint (no@fastify/multipartdependency). Saves under${session.workingDir}/.claude-images/img-${ts}.${ext}and returns the absolute path.src/web/public/image-input.js— new mixin that wires both paste and drop into the existing terminal:contenteditablediv which receives thepasteevent (this is the only reliable way to capture clipboard image data over plain HTTP, where the async Clipboard API requires a secure context). Both image bytes and text data from the same paste are extracted, then focus returns to xterm.image/*file on drop.src/web/routes/session-routes.ts— multipart parser (~100 lines) and the route handler. Body length is bounded to 10 MB and the image MIME type is validated against an allowlist (PNG/JPEG/WebP/GIF).src/web/server.ts— wiresimage-input.jsinto the static asset list and adds session-cleanup so.claude-images/is removed on session destroy (no orphan disk usage).src/web/public/{index.html,styles.css}— script tag + drop-overlay styling.The
.claude-images/directory is created lazily on first paste and is the only file the feature writes — no DB rows, no global state.Test plan
${workdir}/.claude-images/and its absolute path is typed into the terminal.text/plainmasquerading as image): rejected with 415..claude-images/directory removed.🤖 Generated with Claude Code