·8 min read

A Claude Code subagent killed my Chrome

A Claude Code subagent closed my browser with one pkill line while testing a Tauri app, and Chrome was the wrong engine for that test anyway.

claude-codeaitestingworkflow

Contents

My Chrome closed while I was using it. Nothing crashed and no dialog came up. The windows were just gone, and when I reopened it I had no idea whether it would happen again.

I had Claude Code running in another window, coordinating four subagents in parallel on a desktop app of mine. So I stopped and asked it whether it was using my Chrome. It checked instead of guessing, and the answer was yes.

The app is a game-builder tool I am writing in Tauri 2 on a Mac. Each subagent worked in its own git worktree on one GitHub issue. One of them had a research job: evaluate dockview-react, a docking-panel library, and report on its licence, its serialization, its keyboard support and whether it fits Tauri. To answer the keyboard question it decided it needed a real browser.

What the subagent did to my Chrome

It found /Applications/Google Chrome.app and planned to run the library in headless Chrome against a small probe page. Its first attempt was a symlink to the Chrome binary in its scratch folder. That failed straight away, because the binary looks for its framework relative to its own path:

dlopen $SCRATCH/../Frameworks/Google Chrome Framework.framework/Versions/153.0.8010.53/
  Google Chrome Framework: ... (no such file)

So it wrote a two-line wrapper instead:

#!/bin/sh
exec "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "$@"

and ran that with --headless=new and its own --user-data-dir in the scratch folder. It also started a small local HTTP server on port 9999 for the probe page to post its results to. The probe ran, the report arrived, and the subagent cleaned up after itself.

The cleanup is what closed my browser.

Finding it

The main session's first check was a process list:

ps aux | grep -iE "chrome|vite|tauri|playwright|puppeteer|chromedriver|headless" | grep -v grep

That showed the subagent's collector, a node process that had been running for seven minutes, and every process belonging to my own Chrome with the same start minute. The collector was killed first. Then the session looked for anything that was still the subagent's:

ps aux | grep -i chrome | grep -E "user-data-dir|headless|chrome-profile|remote-debugging"
lsof -nP -iTCP:9999

Both came back empty. No headless Chrome was alive, nothing ran with the subagent's profile or a debugging port, and port 9999 was free. The Chrome that was running was mine: one main process with no flags at all. The wrapper and the symlink were deleted, and the subagent got a message to stop and not to work around the stop with open -a, osascript, killall or a different browser.

The line that actually closed it

The explanation I got at the time blamed the shared application bundle. The subagent had made its own profile, so my logins, history and tabs were never read, but it was the same binary I was browsing in, so launching or killing it took my windows with it. That is roughly right, and it is also how the rule I wrote afterwards puts it. It isn't precise, though.

When I read the subagent's own transcript later, the exact line was there. After each probe run, it stopped "its" headless Chrome like this:

pkill -f "Google Chrome"

It ran that twice, about two and a half minutes apart. pkill -f matches the pattern against the whole command line of every process you own, and every process my Chrome runs has Google Chrome in its path: the main binary, each helper, each renderer, the crash handler. The pattern cannot tell the subagent's Chrome from mine, so each time it ran, it took mine down along with its own. The Chrome the session found running had started in the same minute as the second pkill, and I asked my question about half a minute after it.

I can show the kill closed my windows. I can't show that the launch did anything to them, and I am not going to claim it did.

A separate --user-data-dir keeps your data apart. It does nothing to keep the processes apart, and a name-based kill is precisely where that matters.

The second subagent

The stop message went to one subagent. I had four running.

A few minutes after I asked, a second one, working on wire selection in the app's node graph, launched headless Chrome with --remote-debugging-port=9222 to click through the running UI over the DevTools protocol. It drove it for about two minutes and then stopped it with:

pkill -f "remote-debugging-port=9222"

That pattern only matches its own instance, and I have no evidence it touched my windows. But it was still running my browser's binary after I had asked for that to stop, and it had no way to know it should not, because nobody had told it. The main session's first report said the problem was handled. It learned otherwise when the second subagent's own report came back saying it had driven Chrome, and it corrected itself. A stop has to go to every subagent that is running, not only the one you caught.

Testing a Tauri app with Claude Code

Here is the part that would have made the whole Chrome run pointless even if it had closed nothing. On macOS, Tauri renders in WKWebView, Apple's WebKit, not Chromium. The two runs announced themselves plainly:

Chrome probe:   ... AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/153.0.0.0 Safari/537.36
Tauri probe:    ... AppleWebKit/605.1.15 (KHTML, like Gecko)

Focus behaviour, CSS and which web APIs exist are where the two engines differ, and those were exactly what the subagent was measuring. A Chrome result answered a question about Chrome.

So it was redirected: run the same probe inside a real Tauri build. It did that with tauri dev, the probe posted its report from inside WKWebView, and the evaluation came out as "adopt with conditions" for dockview-react 8.3.1, with the Tauri fit evidenced from that native run and from a built bundle.

The rerun turned up one more thing. Reading the library's types while it rewired the probe, the subagent found that keyboard navigation is an opt-in option in that version, off by default. Its probe had never switched it on. The keyboard results from the Chrome run had measured a feature that was turned off, in an engine the app does not use.

The rule, and the contradiction I wrote into it

The rule went into the standing brief every subagent reads, not only into the session's memory: no subagent launches, focuses, scripts or terminates a GUI application on my machine. Not Chrome, not Safari, not my editor, and not the app itself. If something cannot be evaluated without a GUI, it gets reported as unevaluable, with the environment that would be needed.

It took about a day and a half to notice that the repo already said the opposite. Another document in it told subagents to build the app and open the bundle to check their work. The tauri dev run above had been a GUI launch too, on the main session's instruction. For several slices after that the two documents disagreed, and the subagents obeyed the stricter one and said so in their reports: they could not produce the screenshots I had asked for, because reaching a UI state means driving a window and capturing the screen captures mine.

The fix was to split the job, not to weaken the rule. A subagent mounts the real components with the real stylesheet and reads what every element computes to. That check is not a consolation prize: across three slices it caught a primary button at 1.00:1 contrast, a node header at 1.01:1 against its own body and a disabled control at 3.60:1. The main session opens the installed app, because I am there to look at it, and a window appearing on my desk is my business.

What I would tell anyone running subagents on their own machine

This is the same idea as my blast radius rule, one level out. That post sorts changes by what they cost to undo inside the repository. A subagent on my laptop has a radius that does not stop at the repository: the browser I am working in is in range, and git revert does not reopen it.

  • Kill what you started, by PID or by a flag only you used. pkill -f "remote-debugging-port=9222" is scoped. pkill -f "Google Chrome" is every Chrome on the machine.
  • A separate profile is not a separate browser. It isolates cookies and history. It does not isolate processes.
  • Send the stop to every subagent. The one you caught is not the only one running.
  • Test a Tauri app in the engine it ships in. On a Mac that is WKWebView. Chrome evidence about a Tauri app is evidence about Chrome.
  • Check your rules against each other. A new hard rule can quietly contradict an older instruction, and a careful agent will obey the stricter one and stop doing the check you care about.

The parallel bug hunt post lists the rules I give subagents before they start. This one belongs on that list, and it would be the only one there that protects something outside the code.

More posts

New writing when there is something worth saying. By email or by RSS, whichever you prefer.