Verlaire f99c53f4f6 Restore the last session when Zed is started by opening a path (#65463)
Closes #4848
Closes #57305

## Summary

On Windows and Linux, starting Zed by opening a file or folder (Explorer
"Open with Zed", a file manager, `zed <path>`) skipped session
restoration.
The new session then replaced the old one, so its windows, tabs and
unsaved buffers were lost.
macOS does not have that bug: there the request arrives after the
restore has started.

Now such a start first restores the local windows of the last session,
for at most 5 seconds, then handles the request with the same code as
before.
The request's window is created last, so it ends up in front.

- **A file opened without a CLI environment** (Explorer, a file manager,
the desktop entry) becomes a tab in its project's window, or in the
front window, as when Zed is already running.
  A file that has a saved window of its own reopens that window instead.
- **Any other path request** (a file from a terminal, a folder, `-n`,
`-a`, `-r`, `--diff`, `--dev-container`) opens in its own window, as
before.
A saved window with the same folders (a folder inside another one is
folded into it), or of the same repository, is left to the request and
kept out of the sidebar of the other restored windows.
- Remote requests, `zed://` links, channel links and `--wait` requests
are handled as before, without restoring.

Two changes in `workspace` come with it:

- A window restored by such a start can still be loading its tabs while
the user works in it or quits.
Until it has finished, saving it writes the layout it is restoring plus
a pane with what was opened in it meanwhile, and tabs opened in it are
kept when the saved tabs arrive.
  Every other restore takes the same code path as before.
- `Workspace::open_paths` returned the opened items sorted by path, not
in the order the paths were given, so several file links with positions
opened into one existing window could each get another file's line.
  Such a start now reaches that code, so it is fixed here.

Known limits:

- The requested path appears after the session's windows, at most 5
seconds later, and requests that arrive during startup wait for it.
- A saved window that has not opened within the 5 seconds is not
restored by this start; a bare `zed` in the same run restores it.
- A path start does not restore remote windows.
- A window still loading after the 5 seconds finishes behind the
request's window.
Until then its saved state wins over what is done in it: a saved unsaved
draft replaces newer text of the same file (typed, or saved to disk), a
bookmark or breakpoint removed from a saved row comes back, dock changes
are not saved, and `--wait` on a file among its saved tabs returns when
the saved tab takes its place.
A new tab whose id equals a saved tab's id replaces that tab in the
saved layout.

## Testing

50 new tests.
The startup tests run each kind of request against a saved session:
files joining a restored window (also file links with positions), files
and folders getting their own window with the CLI environment, `-n` and
`-r`, saved windows and sidebar projects left to the request (also
through a symlink, with a nested folder, and for a linked worktree),
remote windows, bare CLI, link and `--wait` requests, and the 5-second
limit ending in each phase.
The restore tests cover a window that is still loading: quitting keeps
its saved tabs, docks, bookmarks and breakpoints together with what was
added meanwhile; a tab opened in it survives, a file among the saved
tabs gets one tab, pinned tabs stay in place, the tab in use stays
selected; an ordinary start is unchanged.

Manual check:

1. Set `"restore_on_startup": "last_session"`.
2. Open a folder with two tabs and an untitled buffer with text, then
quit.
3. With Zed closed, open a file inside that folder from the file
manager: the folder window comes back with its tabs and the untitled
text, and the file is a new tab.
4. Quit and run `zed /another/folder` in a terminal: that folder is in
front and the first window is restored behind it.

## Self-review

- [ ] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist). (No UI
changes.)
- [x] Tests cover the new or changed behavior.

Release Notes:

- Fixed opening a file or folder while Zed is closed not restoring the
last session on Windows and Linux, which caused previously open windows,
tabs and unsaved buffers to be lost.

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
2026-11-12 00:02:18 +00:00
…
…
…
…
…
…
2026-10-26 10:10:32 +00:00
…
…
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.6 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%