Open
Conversation
On Emacs 29 and later, register a `yank-media-handler' for `image/.*' in every Claude buffer. When the user pastes an image from the system clipboard the handler writes the bytes to a temp file and injects `@<path> ' into the terminal via `claude-code--term-send-string' — Claude's CLI reads `@path' references natively and attaches the image to the next message. Temp files are tracked per-buffer and cleaned up on kill-buffer when `claude-code-image-paste-cleanup-on-kill' is non-nil. Works transparently across all three terminal backends (eat, vterm, ghostel) because the abstraction already dispatches send-string per backend. Two new defcustoms control the feature and cleanup behavior. Documents the feature in README and adds a Features bullet.
Wrap yank-media in an interactive command that targets the Claude buffer via claude-code--with-buffer, so the user can invoke it from anywhere — command map prefix on p, or the Send group of the transient menu. README updated to mention the binding.
The default temp dir on macOS is nested deep under /var/folders/... which makes the @<path> reference inserted at the prompt unreadable. New defcustom claude-code-image-paste-directory defaults to /tmp on systems that have it and falls back to temporary-file-directory on others. Users can override to e.g. ~/.claude/pastes/ for a project directory.
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
M-x yank-media. The handler writes the image to a temp file and injects@<path>at the prompt; Claude's CLI reads@pathreferences natively and attaches the image to the next message.claude-code--term-send-stringabstraction.claude-code-enable-image-paste(defaultt) andclaude-code-image-paste-cleanup-on-kill(defaultt). Requires Emacs 29+ (yank-media-handler); no-op on older versions.Motivation
This is a long-standing request (issue #127). Terminal emulators don't forward OS-level clipboard image data or drag events to the CLI on their own, but the Claude CLI does accept file path references via
@path. Bridging those two viayank-media-handleris a small, uncomplicated glue.Implementation notes
coding-system-for-write 'binaryso PNG/JPEG bytes are preserved verbatim.temporary-file-directorywith aclaude-image-prefix and a type-appropriate extension (.png,.jpg,.gif,.webp,.bmp; falls back to.pngfor unrecognized image/* types).claude-code-image-paste-cleanup-on-killis non-nil.(fboundp 'yank-media-handler)so it's a no-op on Emacs < 29.Test plan
M-x claude-code,M-x yank-media— verify the prompt shows@/tmp/claude-image-XXXX.pngand sending the message works..jpgextension.claude-code-image-paste-cleanup-on-killat its defaultt).claude-code-image-paste-cleanup-on-killto nil, kill buffer, verify the file stays.claude-code-enable-image-pasteto nil, open a fresh Claude buffer, verifyyank-mediadoes nothing.eat,vterm,ghostel); feature should work identically in each.