Chrome extension fails to connect when Claude Code runs in nix-shell due to TMPDIR mismatch
Description
When Claude Code is run from within a nix-shell environment, the Chrome browser extension fails to connect with the error "Browser extension is not connected". This occurs even when all prerequisites are met (correct extension version, correct Claude Code version, Chrome restarted, etc.).
Root Cause
The MCP server (--claude-in-chrome-mcp) and the native messaging host (--chrome-native-host) use TMPDIR to determine the socket path for claude-mcp-browser-bridge-$USER.
- When Claude Code runs in nix-shell, it uses a nix-shell-specific TMPDIR like
/var/folders/.../T/nix-shell.xxx/ - When Chrome spawns the native messaging host, it runs outside nix-shell with the regular TMPDIR like
/var/folders/.../T/
This causes the MCP server to listen on one socket path while the native host creates a socket at a different path. They never find each other.
Environment
- macOS Darwin 25.2.0
- Claude Code 2.1.19
- Chrome extension 1.0.40
- Running Claude Code from within nix-shell (direnv)
Steps to Reproduce
- Use a development environment that uses nix-shell (e.g., via direnv)
- Run
claude --chromefrom within the nix-shell - Try to use any
mcp__claude-in-chrome__*tool - Observe "Browser extension is not connected" error
Workaround
Modify the native host wrapper script at ~/.claude/chrome/chrome-native-host to explicitly set TMPDIR to match the nix-shell TMPDIR:
#!/bin/sh
export TMPDIR=/var/folders/.../T/nix-shell.xxx # Use actual nix-shell TMPDIR
exec "/path/to/claude" --chrome-native-host
This workaround breaks when starting a new nix-shell session (different TMPDIR path).
Suggested Fix
Use a consistent, TMPDIR-independent socket path for the browser bridge, such as:
~/.claude/chrome/browser-bridge.sock- Or a path derived from a stable identifier rather than TMPDIR
This would ensure the MCP server and native host always agree on the socket location regardless of shell environment.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗