Skip to content

Conversation

@pascalwhoop
Copy link

@pascalwhoop pascalwhoop commented Jan 15, 2026

Problem

When sandbox is enabled, the Claude CLI's file watcher attempts to monitor macOS temp directories (/var/folders/...) and fails on:

  1. Socket files - EOPNOTSUPP errors on .sock files from VSCode, Docker, SSH-askpass
  2. Temp directories - EINTR errors on directories like python-test-discovery-*

These unhandled promise rejections cause the SDK to hang indefinitely instead of failing fast with a clear error.

Solution

This PR adds detection and handling for sandbox file watcher errors:

  1. New Error Class: SandboxFileWatcherError - Provides clear error messages with workaround suggestions
  2. Stderr Monitoring: When sandbox is enabled, stderr is always piped to detect file watcher errors
  3. Error Detection: Regex pattern matches EOPNOTSUPP and EINTR errors from CLI stderr
  4. Graceful Failure: When detected, the SDK terminates the CLI process and raises SandboxFileWatcherError instead of hanging

⚠️ The real fix would be in the nodejs code but I don't think that is open source? I couldn't find that repository anyways :-/

Changes

  • Added SandboxFileWatcherError exception class
  • Modified SubprocessCLITransport to detect file watcher errors from stderr
  • Always pipe stderr when sandbox is enabled (for error detection)
  • Added tests for error class and regex pattern detection

Testing

  • ✅ All existing SDK tests pass
  • ✅ Integration tests with sandbox enabled pass (6/6 tests)
  • ✅ Error detection pattern correctly matches error messages
  • ✅ Process terminates immediately when error detected (no hanging)

Example Error Message

SandboxFileWatcherError: Sandbox file watcher failed on '/var/folders/.../vscode-git-*.sock' (EOPNOTSUPP).
This is a known issue with the Claude CLI's sandbox on macOS.
Workarounds: 1) Disable sandbox (sandbox=None), 2) Run in a container with a clean /tmp directory.

Fixes the issue where sandbox-enabled SDK calls would hang forever when VSCode, Docker, or other apps have socket files in system temp directories.

When sandbox is enabled, the CLI's file watcher may fail on socket files
in /var/folders (macOS temp directory) with EOPNOTSUPP or EINTR errors.
These unhandled errors cause the process to hang indefinitely.

This change:
- Adds SandboxFileWatcherError for clear error reporting
- Detects file watcher errors from CLI stderr
- Terminates the process and raises the error instead of hanging
- Always pipes stderr when sandbox is enabled for error detection

Fixes the issue where sandbox-enabled SDK calls would hang forever
when VSCode, Docker, or other apps have socket files in /tmp.
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.

1 participant