Ctrl+V clipboard paste fails on macOS - sandbox-exec blocks hiservices XPC service

Status Closed — not planned
Reported on v2.1.2
Maintainer reply None cached
Activity 11 comments · opened Jan 9, 2026 · closed May 24, 2026

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 doctor reports all checks pass

Reproduction steps:

  1. Take a screenshot with Cmd+Shift+4 (or Cmd+Ctrl+Shift+4)
  2. Verify clipboard has image: osascript -e 'clipboard info' shows «class PNGf»
  3. In Claude Code, press Ctrl+V
  4. 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:

  1. Claude Code sets SANDBOX_RUNTIME=1 environment variable for all child processes
  2. Commands are wrapped with sandbox-exec -p <profile> bash -c <command>
  3. The sandbox profile does not allow mach-lookup for com.apple.hiservices-xpcservice
  4. 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.

View original on GitHub ↗

11 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16753
  2. https://github.com/anthropics/claude-code/issues/16610
  3. https://github.com/anthropics/claude-code/issues/7975

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

silasg · 7 months ago

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.

silasg · 7 months ago

<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.

jucor · 6 months ago

Still struggling :(

krishnamrao · 6 months ago

I noticed, we are able to paste images from clipboard to vscode terminals but not to iterm2 or terminal.app

dbsdud · 5 months ago

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

hqhq1025 · 4 months ago

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:

  • Cmd+V works — Ghostty/iTerm2 paste the file path, Claude Code loads the image
  • Ctrl+V works — clipaste also adds the legacy PNGf type, so even if the sandbox blocks osascript, the data is already in the right format
brew install hqhq1025/clipaste/clipaste
brew services start clipaste

Since clipaste runs as a LaunchAgent (not inside Claude Code's sandbox), it has full clipboard access and avoids the com.apple.hiservices-xpcservice XPC issue.

silasg · 4 months ago

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.

hqhq1025 · 4 months ago

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-setup configures 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.

github-actions[bot] · 3 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 1 month ago

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.