From cee2c7ff4cbef066ce11614a3c404e27a4839780 Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Fri, 9 Jan 2026 10:18:54 -0800 Subject: [PATCH] feat: add PLANNOTATOR_BROWSER for browser selection (#48) Allow users to specify which browser opens plan files via environment variable. Default behavior unchanged - only activates when env var is set. - macOS: Set to app name ("Google Chrome") or path - Linux/Windows: Set to executable path Closes #42 --- CLAUDE.md | 1 + apps/hook/README.md | 8 ++++++++ apps/opencode-plugin/README.md | 10 +++++++++- packages/server/browser.ts | 29 +++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 14cb5d8..4db1d79 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -53,6 +53,7 @@ claude --plugin-dir ./apps/hook |----------|-------------| | `PLANNOTATOR_REMOTE` | Set to `1` or `true` for remote mode (devcontainer, SSH). Uses fixed port and skips browser open. | | `PLANNOTATOR_PORT` | Fixed port to use. Default: random locally, `19432` for remote sessions. | +| `PLANNOTATOR_BROWSER` | Custom browser to open plans in. macOS: app name or path. Linux/Windows: executable path. | **Legacy:** `SSH_TTY` and `SSH_CONNECTION` are still detected. Prefer `PLANNOTATOR_REMOTE=1` for explicit control. diff --git a/apps/hook/README.md b/apps/hook/README.md index 6c419b8..0202025 100644 --- a/apps/hook/README.md +++ b/apps/hook/README.md @@ -70,6 +70,14 @@ When Claude Code calls `ExitPlanMode`, this hook intercepts and: 3. Approve → Claude proceeds with implementation 4. Request changes → Your annotations are sent back to Claude +## Environment Variables + +| Variable | Description | +|----------|-------------| +| `PLANNOTATOR_REMOTE` | Set to `1` for remote mode (devcontainer, SSH). Uses fixed port and skips browser open. | +| `PLANNOTATOR_PORT` | Fixed port to use. Default: random locally, `19432` for remote sessions. | +| `PLANNOTATOR_BROWSER` | Custom browser to open plans in. macOS: app name or path. Linux/Windows: executable path. | + ## Remote / Devcontainer Usage When running Claude Code in a remote environment (SSH, devcontainer, WSL), set these environment variables: diff --git a/apps/opencode-plugin/README.md b/apps/opencode-plugin/README.md index b93afe1..dde9c45 100644 --- a/apps/opencode-plugin/README.md +++ b/apps/opencode-plugin/README.md @@ -49,9 +49,17 @@ Restart OpenCode. The `submit_plan` tool is now available. - **Private sharing**: Plans and annotations compress into the URL itself—share a link, no accounts or backend required - **Obsidian integration**: Auto-save approved plans to your vault with frontmatter and tags +## Environment Variables + +| Variable | Description | +|----------|-------------| +| `PLANNOTATOR_REMOTE` | Set to `1` for remote mode (devcontainer, SSH). Uses fixed port and skips browser open. | +| `PLANNOTATOR_PORT` | Fixed port to use. Default: random locally, `19432` for remote sessions. | +| `PLANNOTATOR_BROWSER` | Custom browser to open plans in. macOS: app name or path. Linux/Windows: executable path. | + ## Devcontainer / Docker -Works in containerized environments. Set two env vars and forward the port: +Works in containerized environments. Set the env vars and forward the port: ```json { diff --git a/packages/server/browser.ts b/packages/server/browser.ts index f655725..4f44a3c 100644 --- a/packages/server/browser.ts +++ b/packages/server/browser.ts @@ -5,18 +5,35 @@ import { $ } from "bun"; /** - * Open a URL in the default browser + * Open a URL in the browser + * + * Uses PLANNOTATOR_BROWSER env var if set, otherwise uses system default. + * - macOS: Set to app name ("Google Chrome") or path ("/Applications/Firefox.app") + * - Linux/Windows: Set to executable path ("/usr/bin/firefox") + * * Fails silently if browser can't be opened */ export async function openBrowser(url: string): Promise { try { + const browser = process.env.PLANNOTATOR_BROWSER; const platform = process.platform; - if (platform === "win32") { - await $`cmd /c start ${url}`.quiet(); - } else if (platform === "darwin") { - await $`open ${url}`.quiet(); + + if (browser) { + // Custom browser specified + if (platform === "darwin") { + await $`open -a ${browser} ${url}`.quiet(); + } else { + await $`${browser} ${url}`.quiet(); + } } else { - await $`xdg-open ${url}`.quiet(); + // Default system browser + if (platform === "win32") { + await $`cmd /c start ${url}`.quiet(); + } else if (platform === "darwin") { + await $`open ${url}`.quiet(); + } else { + await $`xdg-open ${url}`.quiet(); + } } return true; } catch { -- knotmirror 0.0.1