Skip to content

cli: Defer app activation until after open-behavior prompt#53915

Merged
eholk merged 1 commit intomainfrom
cli-raise-glitch
Apr 14, 2026
Merged

cli: Defer app activation until after open-behavior prompt#53915
eholk merged 1 commit intomainfrom
cli-raise-glitch

Conversation

@eholk
Copy link
Copy Markdown
Contributor

@eholk eholk commented Apr 14, 2026

On macOS, the CLI uses LSOpenFromURLSpec to deliver the zed-cli:// URL to the running Zed app. With kLSLaunchDefaults, Launch Services activates (brings to foreground) the Zed app as a side effect of URL delivery. This happens before the IPC handshake completes and before the user can answer the terminal prompt asking whether to open in a new window or existing workspace, forcing them to manually switch back to the terminal.

Fix

CLI side (crates/cli/src/main.rs): Add kLSLaunchDontSwitch to the launch flags so macOS delivers the URL without activating the app.

App side (crates/zed/src/zed/open_listener.rs): Add cx.activate(true) in handle_cli_connection after the prompt resolves (or immediately for the URL-only path), so the app comes to the foreground at the right time.

Linux and Windows are unaffected — they use Unix sockets and named pipes respectively, which don't have activation side effects.

Release Notes:

  • Fixed the Zed CLI activating the app window before the user answers the open-behavior prompt in the terminal.

On macOS, the CLI uses LSOpenFromURLSpec to deliver the zed-cli:// URL
to the running Zed app. With kLSLaunchDefaults, Launch Services
activates (brings to foreground) the Zed app as a side effect of URL
delivery. This happens before the IPC handshake completes and before
the user can answer the terminal prompt asking whether to open in a
new window or existing workspace, forcing them to manually switch back
to the terminal.

Fix this by adding kLSLaunchDontSwitch to the launch flags so macOS
delivers the URL without activating the app. Then add cx.activate(true)
in handle_cli_connection after the prompt resolves (or immediately for
the URL-only path), so the app comes to the foreground at the right
time.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 14, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Apr 14, 2026
@eholk eholk enabled auto-merge (squash) April 14, 2026 16:46
@eholk eholk merged commit 11edacf into main Apr 14, 2026
42 checks passed
@eholk eholk deleted the cli-raise-glitch branch April 14, 2026 16:56
@mikayla-maki
Copy link
Copy Markdown
Member

@zed-zippy approve

loadingalias pushed a commit to loadingalias/zed that referenced this pull request Apr 14, 2026
…tries#53915)

On macOS, the CLI uses `LSOpenFromURLSpec` to deliver the `zed-cli://`
URL to the running Zed app. With `kLSLaunchDefaults`, Launch Services
activates (brings to foreground) the Zed app as a side effect of URL
delivery. This happens before the IPC handshake completes and before the
user can answer the terminal prompt asking whether to open in a new
window or existing workspace, forcing them to manually switch back to
the terminal.

## Fix

**CLI side** (`crates/cli/src/main.rs`): Add `kLSLaunchDontSwitch` to
the launch flags so macOS delivers the URL without activating the app.

**App side** (`crates/zed/src/zed/open_listener.rs`): Add
`cx.activate(true)` in `handle_cli_connection` after the prompt resolves
(or immediately for the URL-only path), so the app comes to the
foreground at the right time.

Linux and Windows are unaffected — they use Unix sockets and named pipes
respectively, which don't have activation side effects.

Release Notes:

- Fixed the Zed CLI activating the app window before the user answers
the open-behavior prompt in the terminal.
eholk added a commit that referenced this pull request Apr 14, 2026
On macOS, the CLI uses `LSOpenFromURLSpec` to deliver the `zed-cli://`
URL to the running Zed app. With `kLSLaunchDefaults`, Launch Services
activates (brings to foreground) the Zed app as a side effect of URL
delivery. This happens before the IPC handshake completes and before the
user can answer the terminal prompt asking whether to open in a new
window or existing workspace, forcing them to manually switch back to
the terminal.

## Fix

**CLI side** (`crates/cli/src/main.rs`): Add `kLSLaunchDontSwitch` to
the launch flags so macOS delivers the URL without activating the app.

**App side** (`crates/zed/src/zed/open_listener.rs`): Add
`cx.activate(true)` in `handle_cli_connection` after the prompt resolves
(or immediately for the URL-only path), so the app comes to the
foreground at the right time.

Linux and Windows are unaffected — they use Unix sockets and named pipes
respectively, which don't have activation side effects.

Release Notes:

- Fixed the Zed CLI activating the app window before the user answers
the open-behavior prompt in the terminal.
eholk added a commit that referenced this pull request Apr 14, 2026
Cherry-picks three PRs that add the CLI first-run open behavior prompt
to the v0.232.x release branch:

1. #53663 — cli: Add first-run prompt for default open behavior and
abstract IPC transport
2. #53839 — Guard CLI first-run prompt with agents-v2 flag
3. #53915 — cli: Defer app activation until after open-behavior prompt

The fourth commit is a fixup that:
- Adds `AgentV2FeatureFlag` to `feature_flags`, since it was added to
main after the v0.232.x branch point
- Bumps storybook's `dialoguer` dep from a pinned 0.11.0 to the
workspace version (0.12), unifying the duplicate `dialoguer` and
`console` crate versions in Cargo.lock

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <[email protected]>
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
…tries#53915)

On macOS, the CLI uses `LSOpenFromURLSpec` to deliver the `zed-cli://`
URL to the running Zed app. With `kLSLaunchDefaults`, Launch Services
activates (brings to foreground) the Zed app as a side effect of URL
delivery. This happens before the IPC handshake completes and before the
user can answer the terminal prompt asking whether to open in a new
window or existing workspace, forcing them to manually switch back to
the terminal.

## Fix

**CLI side** (`crates/cli/src/main.rs`): Add `kLSLaunchDontSwitch` to
the launch flags so macOS delivers the URL without activating the app.

**App side** (`crates/zed/src/zed/open_listener.rs`): Add
`cx.activate(true)` in `handle_cli_connection` after the prompt resolves
(or immediately for the URL-only path), so the app comes to the
foreground at the right time.

Linux and Windows are unaffected — they use Unix sockets and named pipes
respectively, which don't have activation side effects.

Release Notes:

- Fixed the Zed CLI activating the app window before the user answers
the open-behavior prompt in the terminal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants