Archive terminals on close instead of killing them (keep the session, restore it later) #61190
isaachorowitz
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
1. Why this matters
Problem. Closing a terminal tab in Zed kills the process running inside it. If that terminal holds a long-lived session (a dev server, a language REPL, an SSH connection, a
tmuxsession, or an AI coding agent such as Claude Code / Codex), an accidental close destroys the session with no way to get it back. The only current mitigation people ask for is a confirmation dialog, which nags on every close and still throws the session away if you dismiss it wrong.Evidence (existing demand in this repo):
Prior art:
terminal.integrated.confirmOnExit: "hasChildProcesses"guards against losing a terminal with a running process; VS Code also persists/reconnects terminal sessions across reloads.Framing. Every request so far asks for a confirmation dialog. Archiving is a strictly stronger answer to the same 33-👍 pain: don't nag, and don't lose it. Closing hides the terminal and keeps its session alive; you restore it when you want it back, or force-delete it when you actually mean to kill it.
2. What is it
Feature: an opt-in "archive on close" mode for terminals.
Purpose: when enabled, closing a terminal archives it (hidden, but its PTY and child process keep running) instead of killing it. Archived terminals appear in a collapsible "Archived" section in the terminal panel. Restoring one drops you straight back into the live session; a separate "Force delete" truly kills it (the current behavior). Archived entries are labeled by what is running in them (this composes with the separate
terminal.tab_title_from_programchange in #61188, so a shelf of archivedclaude/codex/ssh prodsessions is legible at a glance).Mechanism (grounded in the current code):
Zed's terminal process runs on a detached
alacrittyEventLoopIO thread that owns the PTY and child (crates/terminal/src/alacritty.rs). The process is killed only when theTerminalGPUI entity is dropped: itsDropimpl (crates/terminal/src/terminal.rs) sends the PTY shutdown and thenSIGTERM/SIGKILL. On the normal close path (Pane::_remove_itemincrates/workspace/src/pane.rs), the last strongEntity<TerminalView>handle is dropped, which cascades to dropping theTerminaland killing the child.So "keep alive" requires no change to the kill logic at all — it is achieved by retaining the strong
Entity<TerminalView>in a panel-ownedarchivedcollection instead of dropping it on close. Restore = re-insert that handle into the pane viaPane::add_item. Force-delete = drop it (or call the existing explicit kill), which runsTerminal::dropexactly as today. This keeps the change surgical and localized toterminal_panelplus a setting.Decision to confirm with the team: whether "close archives" should be opt-in behind a setting (default = today's kill behavior, no surprise for existing users) or become the default with force-delete as the escape hatch. This proposal assumes opt-in, default off.
3. What else does this affect
terminal.close_action: "kill" | "archive", default"kill"), added to the Settings UI. Not per-project.Drop/kill path.4. Open questions for maintainers
I have the terminal lifecycle, panel, and persistence paths mapped and am happy to bring a working prototype / PR quickly once there's agreement on direction (per the contributing guide's "open a PR early once we agree on the change").
Beta Was this translation helpful? Give feedback.
All reactions