Ctrl+V clipboard paste fails on macOS - sandbox-exec blocks hiservices XPC service
Description:
Pressing Ctrl+V to paste an image from clipboard fails with "No image found in clipboard" even when an image is present. The issue is that Claude Code's sandbox-exec profile blocks access to com.apple.hiservices-xpcservice, which is required for clipboard operations.
Environment:
- macOS 26.2 (25C56, tested on multiple terminals: WezTerm, Terminal.app)
- Claude Code version: 2.1.2
claude doctorreports all checks pass
Reproduction steps:
- Take a screenshot with Cmd+Shift+4 (or Cmd+Ctrl+Shift+4)
- Verify clipboard has image:
osascript -e 'clipboard info'shows«class PNGf» - In Claude Code, press Ctrl+V
- Error: "No image found in clipboard"
Root cause analysis:
Running osascript -e 'clipboard info' from within Claude Code fails with:
Connection Invalid error for service com.apple.hiservices-xpcservice
Error received in message reply handler: Connection invalid
The same command works perfectly in a regular terminal outside Claude Code.
Investigation revealed:
- Claude Code sets
SANDBOX_RUNTIME=1environment variable for all child processes - Commands are wrapped with
sandbox-exec -p <profile> bash -c <command> - The sandbox profile does not allow mach-lookup for
com.apple.hiservices-xpcservice - This blocks all clipboard access via osascript from sandboxed processes
Relevant code found in binary strings:
let A=["SANDBOX_RUNTIME=1","TMPDIR=/tmp/claude"];
// ...
let z=h9_.default.quote(["env",...Z,"sandbox-exec","-p",Q,F,"-c",R]);
Claude Code uses these osascript commands for clipboard access (from binary strings):
osascript -e 'the clipboard as «class PNGf»'
osascript -e 'set png_data to (the clipboard as «class PNGf»)'
Manually verified:
osascript -e 'clipboard info'returns valid PNG data («class PNGf», 109696, ...) when run outside Claude Code- The same command fails with the XPC connection error when run from within Claude Code
- Clipboard paste worked briefly after switching from npm to brew installation, then stopped working (subsequent brew reinstalls did not fix it)
What doesn't help:
- Setting
"sandbox": { "enabled": false }in~/.claude/settings.json- the sandbox-exec wrapping is hardcoded - Granting terminal apps Accessibility/Automation permissions in System Settings
- Reinstalling Claude Code via brew
- Different terminal emulators
Suggested fix:
Add clipboard XPC service access to the sandbox profile:
(allow mach-lookup (global-name "com.apple.hiservices-xpcservice"))
Or exclude clipboard-related osascript commands from sandboxing.
Workaround:
Use an MCP server or skill that accesses the clipboard outside of Claude Code's sandboxed bash context (e.g., pngpaste via a custom tool).
---
Note: This bug report was created with assistance from Claude Code itself. The root cause analysis (sandbox-exec blocking XPC services, binary string extraction, tracing the SANDBOX_RUNTIME=1 environment variable) was performed by Claude Code. The osascript command results and the intermittent behavior after switching package managers were manually verified by the reporter.
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
The issue seems not (or at least not only) related to my local environment since both, opencode and codex can get images pasted via ctrl v.
<img width="592" height="248" alt="Image" src="https://github.com/user-attachments/assets/e610833e-5e9f-4600-9504-682b7db4726a" />
Interesting thing is, that disabling sandbox via command or settings file does _not_ restore ctrl v image pasting capability.
Still struggling :(
I noticed, we are able to paste images from clipboard to vscode terminals but not to iterm2 or terminal.app
I found a solution. Just open a new Claude Code session and quickly paste the image into the session you originally intended to paste it into.
https://github.com/anthropics/claude-code/issues/26901#issuecomment-4072356843
For anyone still hitting this: I built clipaste as a workaround that bypasses the sandbox issue entirely.
clipaste is a macOS background daemon that runs outside Claude Code's sandbox. It watches the clipboard and when it detects a screenshot (image data without a file URL), it saves it as a temp PNG and registers the file path on the clipboard via
NSPasteboard.writeObjects([url as NSURL]).This means:
PNGftype, so even if the sandbox blocks osascript, the data is already in the right formatSince clipaste runs as a LaunchAgent (not inside Claude Code's sandbox), it has full clipboard access and avoids the
com.apple.hiservices-xpcserviceXPC issue.I also used a workaround with pngpaste for this, but it's annoying. Btw when running Claude in a docker container with Mac OS clipboard synced using XQuartz on host, pasting images does not work as well. Other agent harnesses don't have this problem-- neither in Mac OS host nor on this docker setup. It's a pitty that Anthropic just banned pi coding agent from their subs. It is sooo much better than Claude code bloatware. I just canceled my Max subscription for that reason.
Thanks for the feedback! The pngpaste workaround is indeed annoying — clipaste automates that entirely so you never think about it.
For the Docker + XQuartz case: clipaste v2.1+ includes an HTTP server mode that might help. If you can forward port 18340 into the container (like SSH RemoteForward), the same xclip shim approach works —
clipaste ssh-setupconfigures this automatically for SSH, and the same pattern applies to Docker with port mapping.Would be curious to hear if that works in your XQuartz setup.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.