Chrome extension: first native messaging connection always fails
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
- Start a new Claude Code session
- Call any
mcp__claude-in-chrome__*tool (e.g.,tabs_context_mcp) - First call fails: "Browser extension is not connected"
- 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
pingvia pipe (stdin closes immediately) → no pong response (native host exits before processing) - Sending
pingwithsubprocess.PIPE(stdin stays open) and 0ms delay → pong received ✅ - Sending
pingwith 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:
- Add an automatic retry with short delay in the MCP tool handler when the first connection attempt fails
- Pre-warm the browser bridge connection during Claude Code startup (when native host sockets are detected)
- Increase the initial connection polling frequency in
ensureConnected()
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗