Chrome extension fails to connect when Claude Code runs in nix-shell due to TMPDIR mismatch

Resolved 💬 3 comments Opened Jan 26, 2026 by solomon23 Closed Jan 30, 2026

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

  1. Use a development environment that uses nix-shell (e.g., via direnv)
  2. Run claude --chrome from within the nix-shell
  3. Try to use any mcp__claude-in-chrome__* tool
  4. 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.

View original on GitHub ↗

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