Chrome extension: first native messaging connection always fails

Resolved 💬 2 comments Opened Apr 1, 2026 by map-c Closed May 6, 2026

Bug Description

When using the Claude in Chrome browser extension with Claude Code's MCP tools, the first connection attempt always fails with "Browser extension is not connected." The second attempt immediately succeeds.

Steps to Reproduce

  1. Start a new Claude Code session
  2. Call any mcp__claude-in-chrome__* tool (e.g., tabs_context_mcp)
  3. First call fails: "Browser extension is not connected"
  4. Call the same tool again immediately — succeeds

Root Cause Analysis

Through debugging, I found a timing issue in the native host initialization:

The native host binary needs time to initialize (create socket listener at /tmp/claude-mcp-browser-bridge-<user>/<pid>.sock, set permissions, etc.) before it can process Chrome native messaging ping messages.

Evidence from testing:

  • Sending ping via pipe (stdin closes immediately) → no pong response (native host exits before processing)
  • Sending ping with subprocess.PIPE (stdin stays open) and 0ms delaypong received
  • Sending ping with 1s delay → pong received

The ensureConnected() method in Claude Code's MultiSocketClient calls refreshClients() then tries to connect all sockets. On the first tool call, the socket pool has no connected clients, and the connection attempt either times out or the socket isn't ready yet. By the second call, the connection has been established via the reconnect logic.

Environment

  • macOS 14.4.1 (Darwin 23.4.0)
  • Claude Code: 2.1.87 (also reproduced on 2.1.89)
  • Chrome Extension: Claude v1.0.64
  • Native host: ~/.claude/chrome/chrome-native-host → Claude Code binary with --chrome-native-host
  • Desktop app native host: /Applications/Claude.app/Contents/Helpers/chrome-native-host

Expected Behavior

The first MCP tool call should succeed, or the MCP layer should automatically retry the connection before returning an error.

Suggested Fix

Either:

  1. Add an automatic retry with short delay in the MCP tool handler when the first connection attempt fails
  2. Pre-warm the browser bridge connection during Claude Code startup (when native host sockets are detected)
  3. Increase the initial connection polling frequency in ensureConnected()

View original on GitHub ↗

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