Open each worktree in its own Zed window#417
Conversation
NSWorkspace.open hands the worktree directory to Zed as an "open document" event, so every worktree collapses into Zed's most-recent window. Launch the bundled Zed CLI (Zed.app/Contents/MacOS/cli) with the bare worktree path instead: with Zed's `cli_default_open_behavior` set to `new_window`, that opens one window per worktree and focuses the existing window when the worktree is already open. Falls back to NSWorkspace.open when the CLI helper is absent. The `-n` flag is deliberately not used: it forces a brand-new window even for an already-open worktree, producing duplicates.
|
Nice 💪 only thing, could we have this a bit more "generic"? So it's not just "Zed" and we ideally can reuse this for any arbitrary app requiring/enhanced by a command line? |
|
📚 Companion docs PR: supabitapp/docs.supacode.sh#1 — documents the required |
Replace the Zed-specific launcher with a generic seam: an optional CLILauncher descriptor on OpenWorktreeAction (relative path to the app's bundled CLI helper plus any flags) and an AppLauncher that prefers a CLI launch when an app advertises one, otherwise falls back to NSWorkspace.open. Adding another CLI-capable app is now just returning a CLILauncher from `cliLauncher`. Only Zed is wired up for now; enabling other apps (VS Code, Cursor, …) needs per-app verification of their new-window semantics.
|
@sbertix good call — generalized it 👍 Opening now goes through a small generic seam instead of a Zed-specific path:
Adding another CLI-capable app is now just returning a |
|
I guess the previous comment slipped through 😅 this indeed ended up being a superset of #423, so I guess I'm merging that. Thanks and sorry for the back and forth |
Sorry for that, didn't see your comment on time! Got the PR ready after your comment 🥷 |
Fixes #399
What
Opening a worktree in Zed now gives one Zed window per worktree instead of collapsing every worktree into a single shared window — matching how VS Code already behaves.
This relies on Zed's
cli_default_open_behaviorbeing set tonew_window(Zed's own default isexisting_window, which is what causes the collapse). Set it via:zed://settings/cli_default_open_behavior, orsettings.json):With the default
existing_window, worktrees keep collapsing into one window.How (briefly)
Previously the worktree was opened with
NSWorkspace.open(...), which sends macOS an "open document" event — Zed treats that as "add this folder to my most-recent window", hence the collapse.This switches the Zed path to launch Zed's bundled CLI (
Zed.app/Contents/MacOS/cli) with just the worktree path. Withcli_default_open_behavior: new_window, the CLI opens a fresh window per worktree and focuses the existing one when the worktree is already open.Note: the
-n/--newflag is intentionally not used — it forces a brand-new window every time, so re-opening an already-open worktree would spawn duplicates. The bare-path + setting combination is the only one that gives "new window, or focus if already open". If the CLI helper is ever missing, it falls back to the previousNSWorkspace.openbehavior.Tests
Added
ZedLaunchTestscovering the launch decision: CLI path resolution, CLI invocation with the bare worktree path (guards against a-nregression), and theNSWorkspace.openfallback when the CLI is absent.Screen recording
Screen.Recording.2026-06-19.at.09.42.27.mp4