Skip to content

feat(paste): opt-in Cmd+V image passthrough (macOS)#332

Open
roba-adnew wants to merge 3 commits into
forketyfork:mainfrom
roba-adnew:feat/cmdv-image-paste
Open

feat(paste): opt-in Cmd+V image passthrough (macOS)#332
roba-adnew wants to merge 3 commits into
forketyfork:mainfrom
roba-adnew:feat/cmdv-image-paste

Conversation

@roba-adnew

Copy link
Copy Markdown

Adds an opt-in [paste] config section with image_passthrough (default false).

When enabled and the macOS clipboard holds an image, Cmd+V forwards Ctrl+V (0x16) to the focused terminal instead of pasting text — so a CLI running there that supports Ctrl+V image paste inlines the image, matching the Cmd+V behavior people expect from editors. Plain text paste is unchanged, and the feature is off by default.

How: macos_clipboard.zig detects clipboard images via NSPasteboard (objc interop, same pattern as macos_input_source.zig); terminal_actions.tryPasteImagePassthrough sends 0x16; the Cmd+V handler is gated on the flag.

Scope: macOS only · 4 files, +124/−3 · build / test / zig fmt / zig build lint all green. Clipboard detection unit-tested; manually verified end-to-end (screenshot → Cmd+V → inline image).

Add a [paste] config section with image_passthrough (default false). When
enabled and the macOS clipboard holds an image, Cmd+V forwards Ctrl+V (0x16)
to the focused terminal instead of pasting text, so a CLI running there
performs its own inline image paste. Plain text paste is unaffected.

- config.zig: PasteConfig + default-config template + tests
- platform/macos_clipboard.zig: NSPasteboard image detection via objc interop
- app/terminal_actions.zig: tryPasteImagePassthrough sends 0x16
- app/runtime.zig: gate the Cmd+V handler on the flag
Replace +[NSImage canInitWithPasteboard:] with
-[NSPasteboard canReadObjectForClasses:@[NSImage] options:nil] for clipboard
image detection. canInitWithPasteboard: only matches the legacy NeXT pasteboard
type set: it missed images declaring only modern UTIs (some Universal Clipboard
/ iPhone screenshots) and false-positived on any file URL. The modern UTI-aware
API matches public.image-conforming types (incl. Universal Clipboard) and image
file URLs while rejecting non-image file URLs, and is metadata-only so it does
not pull promised bytes.
Forwarding Ctrl+V relied on the CLI's own clipboard read, which is unreliable:
Claude Code reads via a synchronous osascript call that fails on Universal
Clipboard promised data and large images, inserting an empty placeholder. Now
Architect reads the clipboard image as PNG bytes itself, writes a temp file, and
pastes that path as text — CLIs like Claude Code attach image file paths
reliably. macos_clipboard gains readClipboardImagePng (reads public.png, or
converts the TIFF representation via NSBitmapImageRep as a fallback).
@forketyfork

Copy link
Copy Markdown
Owner

Hey, thank you for this PR. I think being able to paste images with Cmd+V instead of relying on the agent implementation would be a nice addition to Architect's feature set. If it works well, we can later make it the default behavior.

Could you please fix the build (looks like the linting fails) and update the docs/configuration.md file with the new configuration parameter?

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.

2 participants