claude-in-chrome-troubleshooting by trailofbits/skills
npx skills add https://github.com/trailofbits/skills --skill claude-in-chrome-troubleshooting当 Chrome 中的 Claude MCP 工具连接失败或工作不可靠时,请使用此技能。
mcp__claude-in-chrome__* 工具失败并提示“浏览器扩展未连接”~/Library/Application Support/, osascript)背景: 当 Claude.app 添加 Cowork 支持(从桌面应用进行浏览器自动化)时,它引入了一个与原 Claude Code CLI 冲突的竞争性原生消息传递主机。
| 组件 | 原生主机二进制文件 | 套接字位置 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| Claude.app (Cowork) | /Applications/Claude.app/Contents/Helpers/chrome-native-host | /tmp/claude-mcp-browser-bridge-$USER/<PID>.sock |
| Claude Code CLI | ~/.local/share/claude/versions/<version> --chrome-native-host | $TMPDIR/claude-mcp-browser-bridge-$USER (单个文件) |
com.anthropic.claude_browser_extension.json → Claude.app 助手com.anthropic.claude_code_browser_extension.json → Claude Code 包装器如果您使用 Claude Code CLI 进行浏览器自动化(而非 Cowork):
# 禁用 Claude.app 的原生消息传递配置
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled
# 确保 Claude Code 配置存在并指向包装器
cat ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json
如果您使用 Cowork (Claude.app) 进行浏览器自动化:
# 禁用 Claude Code 的原生消息传递配置
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json.disabled
您不能同时使用两者。 选择一个并禁用另一个。
将此添加到 ~/.zshrc 或直接运行:
chrome-mcp-toggle() {
local CONFIG_DIR=~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts
local CLAUDE_APP="$CONFIG_DIR/com.anthropic.claude_browser_extension.json"
local CLAUDE_CODE="$CONFIG_DIR/com.anthropic.claude_code_browser_extension.json"
if [[ -f "$CLAUDE_APP" && ! -f "$CLAUDE_APP.disabled" ]]; then
# 当前使用 Claude.app,切换到 Claude Code
mv "$CLAUDE_APP" "$CLAUDE_APP.disabled"
[[ -f "$CLAUDE_CODE.disabled" ]] && mv "$CLAUDE_CODE.disabled" "$CLAUDE_CODE"
echo "已切换到 Claude Code CLI"
echo "重启 Chrome 和 Claude Code 以应用更改"
elif [[ -f "$CLAUDE_CODE" && ! -f "$CLAUDE_CODE.disabled" ]]; then
# 当前使用 Claude Code,切换到 Claude.app
mv "$CLAUDE_CODE" "$CLAUDE_CODE.disabled"
[[ -f "$CLAUDE_APP.disabled" ]] && mv "$CLAUDE_APP.disabled" "$CLAUDE_APP"
echo "已切换到 Claude.app (Cowork)"
echo "重启 Chrome 以应用更改"
else
echo "当前状态不明确。请检查配置:"
ls -la "$CONFIG_DIR"/com.anthropic*.json* 2>/dev/null
fi
}
用法:运行 chrome-mcp-toggle,然后重启 Chrome(如果切换到 CLI,还需重启 Claude Code)。
# 1. 正在运行哪个原生主机二进制文件?
ps aux | grep chrome-native-host | grep -v grep
# Claude.app: /Applications/Claude.app/Contents/Helpers/chrome-native-host
# Claude Code: ~/.local/share/claude/versions/X.X.X --chrome-native-host
# 2. 套接字在哪里?
# 对于 Claude Code (TMPDIR 中的单个文件):
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1
# 对于 Claude.app (包含 PID 文件的目录):
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1
# 3. 原生主机连接到了什么?
lsof -U 2>&1 | grep claude-mcp-browser-bridge
# 4. 哪些配置是激活的?
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json
MCP 在启动时连接。 如果浏览器桥在 Claude Code 启动时尚未就绪,整个会话的连接都会失败。修复方法通常是:确保 Chrome + 扩展正在运行且配置正确,然后重启 Claude Code。
# 1. 确保正确的配置已激活
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled 2>/dev/null
# 2. 更新包装器以使用最新的 Claude Code 版本
cat > ~/.claude/chrome/chrome-native-host << 'EOF'
#!/bin/bash
LATEST=$(ls -t ~/.local/share/claude/versions/ 2>/dev/null | head -1)
exec "$HOME/.local/share/claude/versions/$LATEST" --chrome-native-host
EOF
chmod +x ~/.claude/chrome/chrome-native-host
# 3. 终止现有的原生主机并清理套接字
pkill -f chrome-native-host
rm -rf /tmp/claude-mcp-browser-bridge-$USER/
rm -f "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"
# 4. 重启 Chrome
osascript -e 'quit app "Google Chrome"' && sleep 2 && open -a "Google Chrome"
# 5. 等待 Chrome 启动,点击 Claude 扩展图标
# 6. 验证正确的原生主机正在运行
ps aux | grep chrome-native-host | grep -v grep
# 应显示: ~/.local/share/claude/versions/X.X.X --chrome-native-host
# 7. 验证套接字存在
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"
# 8. 重启 Claude Code
如果您在多个 Chrome 配置文件中安装了 Claude 扩展,每个配置文件都会生成自己的原生主机和套接字。这可能导致混淆。
修复: 仅在一个 Chrome 配置文件中启用 Claude 扩展。
运行多个 Claude Code 实例可能导致套接字冲突。
修复: 一次只运行一个 Claude Code 会话,或者在关闭其他会话后使用 /mcp 重新连接。
位于 ~/.claude/chrome/chrome-native-host 的包装器可能包含一个在更新后变得过时的硬编码版本。
诊断:
cat ~/.claude/chrome/chrome-native-host
# 错误示例: exec "/Users/.../.local/share/claude/versions/2.0.76" --chrome-native-host
# 正确示例: 使用 $(ls -t ...) 查找最新版本
修复: 使用上面“完全重置步骤”中所示的动态版本包装器。
Claude Code 期望设置 TMPDIR 来查找套接字。
# 检查
echo $TMPDIR
# 应显示: /var/folders/XX/.../T/
# 修复: 添加到 ~/.zshrc
export TMPDIR="${TMPDIR:-$(getconf DARWIN_USER_TEMP_DIR)}"
echo "=== Native Host Binary ==="
ps aux | grep chrome-native-host | grep -v grep
echo -e "\n=== Socket (Claude Code location) ==="
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1
echo -e "\n=== Socket (Claude.app location) ==="
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1
echo -e "\n=== Native Host Open Files ==="
pgrep -f chrome-native-host | xargs -I {} lsof -p {} 2>/dev/null | grep -E "(sock|claude-mcp)"
echo -e "\n=== Active Native Messaging Configs ==="
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json 2>/dev/null
echo -e "\n=== Custom Wrapper Contents ==="
cat ~/.claude/chrome/chrome-native-host 2>/dev/null || echo "No custom wrapper"
echo -e "\n=== TMPDIR ==="
echo "TMPDIR=$TMPDIR"
echo "Expected: $(getconf DARWIN_USER_TEMP_DIR)"
| 文件 | 用途 |
|---|---|
~/.claude/chrome/chrome-native-host | Claude Code 的自定义包装器脚本 |
/Applications/Claude.app/Contents/Helpers/chrome-native-host | Claude.app (Cowork) 原生主机 |
~/.local/share/claude/versions/<version> | Claude Code 二进制文件 (使用 --chrome-native-host 运行) |
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json | Claude.app 原生主机的配置 |
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json | Claude Code 原生主机的配置 |
$TMPDIR/claude-mcp-browser-bridge-$USER | 套接字文件 (Claude Code) |
/tmp/claude-mcp-browser-bridge-$USER/<PID>.sock | 套接字文件 (Claude.app) |
原始技能由 @jeffzwang 来自 @ExaAILabs 创建。针对当前版本的 Claude Desktop 和 Claude Code 进行了增强和更新。
每周安装次数
815
代码仓库
GitHub 星标数
3.9K
首次出现
2026年1月26日
安全审计
安装于
claude-code726
opencode717
codex708
gemini-cli702
cursor693
github-copilot689
Use this skill when Claude in Chrome MCP tools fail to connect or work unreliably.
mcp__claude-in-chrome__* tools fail with "Browser extension is not connected"~/Library/Application Support/, osascript)Background: When Claude.app added Cowork support (browser automation from the desktop app), it introduced a competing native messaging host that conflicts with Claude Code CLI.
| Component | Native Host Binary | Socket Location |
|---|---|---|
| Claude.app (Cowork) | /Applications/Claude.app/Contents/Helpers/chrome-native-host | /tmp/claude-mcp-browser-bridge-$USER/<PID>.sock |
| Claude Code CLI | ~/.local/share/claude/versions/<version> --chrome-native-host | $TMPDIR/claude-mcp-browser-bridge-$USER (single file) |
Both register native messaging configs in Chrome:
com.anthropic.claude_browser_extension.json → Claude.app helpercom.anthropic.claude_code_browser_extension.json → Claude Code wrapperChrome extension requests a native host by name
If the wrong config is active, the wrong binary runs
The wrong binary creates sockets in a format/location the MCP client doesn't expect
Result: "Browser extension is not connected" even though everything appears to be running
If you use Claude Code CLI for browser automation (not Cowork):
# Disable the Claude.app native messaging config
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled
# Ensure the Claude Code config exists and points to the wrapper
cat ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json
If you use Cowork (Claude.app) for browser automation:
# Disable the Claude Code native messaging config
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json.disabled
You cannot use both simultaneously. Pick one and disable the other.
Add this to ~/.zshrc or run directly:
chrome-mcp-toggle() {
local CONFIG_DIR=~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts
local CLAUDE_APP="$CONFIG_DIR/com.anthropic.claude_browser_extension.json"
local CLAUDE_CODE="$CONFIG_DIR/com.anthropic.claude_code_browser_extension.json"
if [[ -f "$CLAUDE_APP" && ! -f "$CLAUDE_APP.disabled" ]]; then
# Currently using Claude.app, switch to Claude Code
mv "$CLAUDE_APP" "$CLAUDE_APP.disabled"
[[ -f "$CLAUDE_CODE.disabled" ]] && mv "$CLAUDE_CODE.disabled" "$CLAUDE_CODE"
echo "Switched to Claude Code CLI"
echo "Restart Chrome and Claude Code to apply"
elif [[ -f "$CLAUDE_CODE" && ! -f "$CLAUDE_CODE.disabled" ]]; then
# Currently using Claude Code, switch to Claude.app
mv "$CLAUDE_CODE" "$CLAUDE_CODE.disabled"
[[ -f "$CLAUDE_APP.disabled" ]] && mv "$CLAUDE_APP.disabled" "$CLAUDE_APP"
echo "Switched to Claude.app (Cowork)"
echo "Restart Chrome to apply"
else
echo "Current state unclear. Check configs:"
ls -la "$CONFIG_DIR"/com.anthropic*.json* 2>/dev/null
fi
}
Usage: chrome-mcp-toggle then restart Chrome (and Claude Code if switching to CLI).
# 1. Which native host binary is running?
ps aux | grep chrome-native-host | grep -v grep
# Claude.app: /Applications/Claude.app/Contents/Helpers/chrome-native-host
# Claude Code: ~/.local/share/claude/versions/X.X.X --chrome-native-host
# 2. Where is the socket?
# For Claude Code (single file in TMPDIR):
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1
# For Claude.app (directory with PID files):
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1
# 3. What's the native host connected to?
lsof -U 2>&1 | grep claude-mcp-browser-bridge
# 4. Which configs are active?
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json
MCP connects at startup. If the browser bridge wasn't ready when Claude Code started, the connection will fail for the entire session. The fix is usually: ensure Chrome + extension are running with correct config, THEN restart Claude Code.
# 1. Ensure correct config is active
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled 2>/dev/null
# 2. Update the wrapper to use latest Claude Code version
cat > ~/.claude/chrome/chrome-native-host << 'EOF'
#!/bin/bash
LATEST=$(ls -t ~/.local/share/claude/versions/ 2>/dev/null | head -1)
exec "$HOME/.local/share/claude/versions/$LATEST" --chrome-native-host
EOF
chmod +x ~/.claude/chrome/chrome-native-host
# 3. Kill existing native host and clean sockets
pkill -f chrome-native-host
rm -rf /tmp/claude-mcp-browser-bridge-$USER/
rm -f "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"
# 4. Restart Chrome
osascript -e 'quit app "Google Chrome"' && sleep 2 && open -a "Google Chrome"
# 5. Wait for Chrome, click Claude extension icon
# 6. Verify correct native host is running
ps aux | grep chrome-native-host | grep -v grep
# Should show: ~/.local/share/claude/versions/X.X.X --chrome-native-host
# 7. Verify socket exists
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"
# 8. Restart Claude Code
If you have the Claude extension installed in multiple Chrome profiles, each spawns its own native host and socket. This can cause confusion.
Fix: Only enable the Claude extension in ONE Chrome profile.
Running multiple Claude Code instances can cause socket conflicts.
Fix: Only run one Claude Code session at a time, or use /mcp to reconnect after closing other sessions.
The wrapper at ~/.claude/chrome/chrome-native-host may have a hardcoded version that becomes stale after updates.
Diagnosis:
cat ~/.claude/chrome/chrome-native-host
# Bad: exec "/Users/.../.local/share/claude/versions/2.0.76" --chrome-native-host
# Good: Uses $(ls -t ...) to find latest
Fix: Use the dynamic version wrapper shown in the Full Reset Procedure above.
Claude Code expects TMPDIR to be set to find the socket.
# Check
echo $TMPDIR
# Should show: /var/folders/XX/.../T/
# Fix: Add to ~/.zshrc
export TMPDIR="${TMPDIR:-$(getconf DARWIN_USER_TEMP_DIR)}"
echo "=== Native Host Binary ==="
ps aux | grep chrome-native-host | grep -v grep
echo -e "\n=== Socket (Claude Code location) ==="
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1
echo -e "\n=== Socket (Claude.app location) ==="
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1
echo -e "\n=== Native Host Open Files ==="
pgrep -f chrome-native-host | xargs -I {} lsof -p {} 2>/dev/null | grep -E "(sock|claude-mcp)"
echo -e "\n=== Active Native Messaging Configs ==="
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json 2>/dev/null
echo -e "\n=== Custom Wrapper Contents ==="
cat ~/.claude/chrome/chrome-native-host 2>/dev/null || echo "No custom wrapper"
echo -e "\n=== TMPDIR ==="
echo "TMPDIR=$TMPDIR"
echo "Expected: $(getconf DARWIN_USER_TEMP_DIR)"
| File | Purpose |
|---|---|
~/.claude/chrome/chrome-native-host | Custom wrapper script for Claude Code |
/Applications/Claude.app/Contents/Helpers/chrome-native-host | Claude.app (Cowork) native host |
~/.local/share/claude/versions/<version> | Claude Code binary (run with --chrome-native-host) |
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json | Config for Claude.app native host |
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json |
Original skill by@jeffzwang from @ExaAILabs. Enhanced and updated for current versions of Claude Desktop and Claude Code.
Weekly Installs
815
Repository
GitHub Stars
3.9K
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code726
opencode717
codex708
gemini-cli702
cursor693
github-copilot689
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
136,300 周安装
| Config for Claude Code native host |
$TMPDIR/claude-mcp-browser-bridge-$USER | Socket file (Claude Code) |
/tmp/claude-mcp-browser-bridge-$USER/<PID>.sock | Socket files (Claude.app) |