Repository navigation
Description
Summary
The patch-playwright-mcp script ships in the claude-code image to rewrite cached @playwright/mcp .mcp.json files so the MCP launches system chromium (/usr/bin/chromium) instead of the chrome channel (default /opt/google/chrome/chrome, which isn't installed in this image). It is correctly wired to postCreateCommand (via init-plugins.sh) and postStartCommand. However, that wiring only covers the boot-time state of the plugin cache.
When Claude Code's playwright plugin auto-updates during a session — extracting a fresh cache dir for the new version hash — the new .mcp.json is unpatched. The first MCP invocation in that session then fails with:
Error: async initializeServer: Chromium distribution 'chrome' is not found at /opt/google/chrome/chrome
Run "npx playwright install chrome"
The MCP server caches .mcp.json in memory at launch, so running patch-playwright-mcp mid-session only fixes the next session — it doesn't unblock the current one.
This is the structural follow-up the script's own comment foreshadows:
"Plugin auto-updates extract into fresh cache dirs (one per version hash), each with an unpatched .mcp.json. Patching only the first match (#64) left newer cache dirs broken until container rebuild."
The fix landed in #64/#85/#87/#91 made the script idempotent and loop over all matches, but it can only patch what exists at the moment it runs. There's no mid-session retrigger.
Reproduction
- Start a fresh devcontainer based on
ghcr.io/gatezh/devcontainers/claude-code:latest. - Open Claude Code; let the playwright plugin auto-update (or wait until any cache materialization that happens after
postStartfires). - In the same session, invoke any playwright MCP tool — e.g.
mcp__plugin_playwright_playwright__browser_navigatetohttp://localhost:<port>/. - Observe the chrome-path error above.
- Manually run
/usr/local/bin/patch-playwright-mcp— it patches multiple cache dirs thatpostStartdidn't reach. The current MCP session is still broken (config is cached in memory); a new session works.
Verification
Real session evidence:
# Container start (proxy: docker-init / first process)
$ stat -c '%y' /proc/1
2026-05-12 09:17:13
# Playwright plugin cache .mcp.json mtimes
$ stat -c '%y %n' ~/.claude/plugins/cache/claude-plugins-official/playwright/*/.mcp.json
2026-05-12 11:50:38 …/playwright/ac45fdae4b7a/.mcp.json
2026-05-12 11:50:38 …/playwright/45896c8f2fe6/.mcp.json
2026-05-12 11:50:38 …/playwright/84d2d12cd9d1/.mcp.json
2026-05-12 11:50:38 …/playwright/480a410cc0dd/.mcp.json
2026-05-12 11:50:38 …/playwright/b392f5189934/.mcp.json
2026-05-12 11:50:38 …/playwright/0742692199b4/.mcp.json
2026-05-12 11:50:38 …/playwright/00679aef889e/.mcp.json
All 7 mtimes match the manual patch run, not postStart at 09:17. Either postStart ran when the playwright cache dir was empty (dirs created later by plugin auto-update), or postStart ran but the cache was subsequently overwritten by a plugin auto-update. Same observable outcome: the patch script can only fix what exists at the moment it runs.
The .mcp.json content after manual patching (target state for all cache dirs):
{
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest",
"--browser", "chromium",
"--executable-path", "/usr/bin/chromium",
"--no-sandbox",
"--headless"
]
}
}Suggested fix
The patch script is idempotent and fast (~20ms for 7 dirs). The natural fix is to run it once per Claude Code session start, after plugin auto-update settles, before any MCP launches. Two viable options, in order of preference:
-
Claude Code
SessionStarthook (recommended). Register/usr/local/bin/patch-playwright-mcpas aSessionStarthook in the image-baked.claude/settings.json. Hooks fire on every session, so a freshly-auto-updated plugin cache gets patched before the user invokes a tool. Lowest blast radius; the existingpostStartCommandentry can stay for defense-in-depth.Example shape (subject to Claude Code hook schema):
{ "hooks": { "SessionStart": [ { "command": "/usr/local/bin/patch-playwright-mcp" } ] } } -
Wrap the MCP command in
~/.claude/settings.json(or the image-bakedmcp_serversdefinition) so the playwright MCP launches as:bash -c '/usr/local/bin/patch-playwright-mcp >/dev/null && exec npx @playwright/mcp@latest …'Belt-and-suspenders: patches whatever Claude is about to read, every time. Marginally heavier on cold-start since the patch runs on every MCP boot.
Option 1 is the structurally cleaner answer because the patch only needs to happen once per session, not once per MCP launch.
Affected files in this repo (gatezh/devcontainers)
claude-code/scripts/patch-playwright-mcp(or wherever the script lives in the image build) — no change needed; the script itself is correct.- The image-baked
.claude/settings.json— add theSessionStarthook entry. claude-code/.devcontainer/*/devcontainer.json— the existingpostStartCommandandinit-plugins.shwiring can stay for defense-in-depth.
Environment
- Image:
ghcr.io/gatezh/devcontainers/claude-code:latest(pull_policy: always) - OS: Debian GNU/Linux 13 (trixie)
- chromium:
147.0.7727.137-1~deb13u1 PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium@playwright/mcpcache dirs found at time of failure: 7, all unpatched until manual run
Related
- Playwright MCP plugin can't launch a browser in
claude-code-sandbox, and the existing ARM64 patch is broken inclaude-codetoo #85, Bakepatch-playwright-mcp.shinto the image so consumer projects don't carry a copy #87, Playwright Strategy section: enumerate every consumer that needsexecutablePathwiring #91 — prior fixes that landed the patch script andpostStartwiring, referenced in thesandbox-playwrightskill. - fix(claude-code): Playwright MCP plugin fails on ARM64 — chrome not found #64 — the initial fix that only patched the first match; superseded by the loop-over-all-matches version still shipping today.
@playwright/mcp— upstream MCP server whose default--browser chromechannel is the root cause of the chromium-path mismatch.- Playwright
launchOptions.executablePath— the underlying knob the patch threads through--executable-path.
Activity
fix(claude-code): patch playwright MCP on every session start (#98) (#99