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.
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗