[BUG] preview_start fails on macOS — sandbox blocks os.getcwd(), launch.json ignored

Resolved 💬 5 comments Opened Apr 3, 2026 by brossow Closed May 19, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Per Claude:
preview_start always fails on macOS when Xcode is installed. The tool ignores launch.json entirely and hardcodes python3 -m http.server via a disclaimer sandbox wrapper. That sandbox blocks os.getcwd() at Python startup, crashing the server before it can start.

What Should Happen?

The preview server should start and serve the configured project directory.

Error Messages/Logs

Failed to start preview server: Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/server.py", line 1274, in <module>
    parser.add_argument('--directory', '-d', default=os.getcwd(),
PermissionError: [Errno 1] Operation not permitted

Steps to Reproduce

  1. Have Xcode installed on macOS
  2. Open any project in the Claude Code desktop app
  3. Trigger preview_start (manually or via a stop hook)
  4. Server fails immediately with the PermissionError above

Additional findings from extensive debugging:

  • The actual process spawned is always: disclaimer /usr/bin/python3 -m http.server <port> --directory <project-name> — regardless of what is in .claude/launch.json
  • All launch.json fields tested and ignored: runtimeExecutable, runtimeArgs, command, cwd, rootDir
  • The error message says "Check the command in .claude/launch.json and try again" but the file is never actually read
  • Homebrew Python at /usr/local/bin/python3 does NOT have this restriction — only the Xcode Python at /usr/bin/python3 does
  • Even when os.getcwd() is monkey-patched via usercustomize.py to work around the crash, the disclaimer sandbox also blocks the Python process from reading files in the project directory, so the server starts but returns 404 for all requests

Workaround: cd /path/to/project && ruby -run -e httpd . -p 8080 in Terminal before using preview tools.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.90

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Suggested fixes: (1) respect launch.json — if command or runtimeExecutable is configured, use it; (2) prefer /usr/local/bin/python3 over /usr/bin/python3 when available, as the latter inherits Xcode sandbox restrictions; (3) ensure the disclaimer wrapper sets the process CWD before Python initializes, or grants the subprocess read access to the project directory.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗