Skip to content

Open Zed in a new window per worktree#643

Merged
ittaiz merged 1 commit into
mainfrom
feat/dev3-zed-new-window-per-worktree
Jun 10, 2026
Merged

Open Zed in a new window per worktree#643
ittaiz merged 1 commit into
mainfrom
feat/dev3-zed-new-window-per-worktree

Conversation

@ittaiz

@ittaiz ittaiz commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

Using Open in → Zed on task A and then on task B swapped the project inside the single running Zed window — worktree B replaced worktree A instead of opening alongside it.

Root cause: openInApp launches every editor with open -a <App> <path> (src/bun/rpc-handlers/app-handlers.ts). For Zed, macOS hands the folder to the already-running instance, which opens it in the current window (Zed's default behavior).

Fix

Special-case Zed in openInApp: invoke the Zed CLI with -n (forces a new workspace window — confirmed in the Zed CLI reference). -n is a Zed-CLI flag that open -a can't pass, so we call the CLI directly:

  • Resolve the binary from PATH (/usr/local/bin/zed, ~/.local/bin/zed, /opt/homebrew/bin/zed) or the bundled Zed.app/Contents/MacOS/cli.
  • Fall back to open -a Zed <path> if no CLI is found.

open -n -a Zed was rejected — it spawns a whole second app instance (Zed is single-instance), which is not what we want.

Scope intentionally limited to Zed; other editors (VS Code, Cursor, IntelliJ, Finder) are unchanged.

Tests

7 new backend tests in rpc-handlers.test.ts covering: Finder, generic editor, Zed via bundled CLI, PATH-precedence, fallback to open -a, and path/app-name validation. bun run lint and full bun run test green.

Test instructions

  1. Ensure /Applications/Zed.app/Contents/MacOS/cli exists (no need to install zed on PATH).
  2. Open task A → Open in → Zed. Then task B → Open in → Zed.
  3. Expected: B opens in a new, separate Zed window; A's window stays open.
  4. Other editors still open via open -a as before.

🤖 Generated with Claude Code

Launching Zed via 'open -a Zed <path>' reuses the running window and swaps
its project, so opening worktree B replaced worktree A. Special-case Zed in
openInApp to invoke the Zed CLI with '-n' (forces a new workspace window),
resolving the binary from PATH or the bundled Zed.app/Contents/MacOS/cli, and
fall back to 'open -a Zed' when no CLI is found.
@ittaiz ittaiz enabled auto-merge (squash) June 10, 2026 05:53
@ittaiz ittaiz merged commit 1c4e270 into main Jun 10, 2026
4 checks passed
@ittaiz ittaiz deleted the feat/dev3-zed-new-window-per-worktree branch June 10, 2026 05:54
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