Skip to content

fix: respect BROWSE_PARENT_PID=0 from environment#959

Open
garrett-fox wants to merge 1 commit intogarrytan:mainfrom
garrett-fox:fix/respect-browse-parent-pid-env
Open

fix: respect BROWSE_PARENT_PID=0 from environment#959
garrett-fox wants to merge 1 commit intogarrytan:mainfrom
garrett-fox:fix/respect-browse-parent-pid-env

Conversation

@garrett-fox
Copy link
Copy Markdown

Problem

startServer() always overrides BROWSE_PARENT_PID with process.pid, ignoring the environment. The parent-PID watchdog then kills the daemon 15 seconds after the spawning CLI process exits.

This is correct for interactive use (one long-lived CLI session), but breaks tools like Claude Code where each bash command is a separate short-lived process. The daemon starts, the CLI exits, and 15 seconds later the daemon self-terminates — losing browser state, cookies, and navigation context.

Fix

Check for BROWSE_PARENT_PID=0 in the environment before overriding with process.pid. When set to 0, the watchdog is skipped (the server already handles this case). The 30-minute idle timeout still cleans up orphaned daemons.

This is a 3-line change — extract a parentPid variable and use it in both the Windows and macOS/Linux spawn paths.

Prior art

The pair-agent command already uses BROWSE_PARENT_PID=0 via extraEnv (cli.ts:988) for the same reason — the server needs to outlive the spawning process. This PR extends the same pattern to the general spawn path via an environment variable.

Usage

export BROWSE_PARENT_PID=0  # in ~/.bashrc or equivalent
browse goto "https://example.com"
# daemon survives after this process exits

🤖 Generated with Claude Code

When `BROWSE_PARENT_PID=0` is set in the environment, `startServer()`
now passes `0` instead of overriding it with `process.pid`. This lets
callers like Claude Code disable the parent-PID watchdog so the daemon
survives across short-lived bash invocations.

The server already handles this correctly (skips the watchdog when
PID is 0), and `pair-agent` already uses this pattern via `extraEnv`.
This change extends the same behavior to the general spawn path via
an environment variable.

The 30-minute idle timeout still handles cleanup for orphaned daemons.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant