A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
wezterm-gui: open one window for the local session host, not one per live thread
RoversXea5d2fe62b9a
diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rsindex 75ffa88f..c0f31174 100644--- a/wezterm-gui/src/frontend.rs+++ b/wezterm-gui/src/frontend.rs@@ -20,8 +20,23 @@ use wezterm_client::domain::{ClientDomain, FrontendRecoverySlot, ThinkTermFronteuse wezterm_term::{Alert, ClipboardSelection};use wezterm_toast_notification::*;-fn should_spawn_reconciled_gui_window(is_domain_owned: bool, workspace: &str) -> bool {- !is_domain_owned || crate::workspace_threads::is_thread_workspace_name(workspace)+/// Which mux windows in the active workspace get a GUI window of their+/// own. Local windows always; a remote domain's only in its thread+/// workspaces (its plain windows are background). A window of the local+/// session host is the other way round: its thread windows are the+/// threads of the local Spaces, opened by their Space window through the+/// thread store (making one here would open every live thread of every+/// Space), and only a startup window in a plain workspace opens on its own.+fn should_spawn_reconciled_gui_window(+ is_domain_owned: bool,+ is_host: bool,+ workspace: &str,+) -> bool {+ let thread_workspace = crate::workspace_threads::is_thread_workspace_name(workspace);+ if is_host {+ return !thread_workspace;+ }+ !is_domain_owned || thread_workspace}fn frontend_recovery_tab(@@ -606,7 +621,7 @@ impl GuiFrontEnd {}let mux = Mux::get();- let (is_domain_owned, window_workspace) = {+ let (is_domain_owned, is_host, window_workspace) = {let Some(mux_window) = mux.get_window(mux_window_id) else {continue;};@@ -616,6 +631,9 @@ impl GuiFrontEnd {mux_window.origin_domain().is_some_and(|id| !crate::local_sessions::is_host_domain_id(id)),+ mux_window+ .origin_domain()+ .is_some_and(crate::local_sessions::is_host_domain_id),mux_window.get_workspace().to_string(),)};@@ -632,7 +650,7 @@ impl GuiFrontEnd {// giving them a GUI window creates the stray "local Space with// a remote terminal" window and tangles its lifecycle with the// real thread window.- if !should_spawn_reconciled_gui_window(is_domain_owned, &window_workspace) {+ if !should_spawn_reconciled_gui_window(is_domain_owned, is_host, &window_workspace) {log::debug!("reconcile: leaving background domain window {} in workspace {:?} hidden",mux_window_id,@@ -1099,8 +1117,9 @@ mod tests {#[test]fn reconcile_keeps_local_windows_visible() {- assert!(should_spawn_reconciled_gui_window(false, "default"));+ assert!(should_spawn_reconciled_gui_window(false, false, "default"));assert!(should_spawn_reconciled_gui_window(+ false,false,"user-created-workspace"));@@ -1108,13 +1127,15 @@ mod tests {#[test]fn reconcile_hides_background_domain_windows() {- assert!(!should_spawn_reconciled_gui_window(true, "default"));+ assert!(!should_spawn_reconciled_gui_window(true, false, "default"));assert!(!should_spawn_reconciled_gui_window(true,+ false,"unmanaged-remote-workspace"));assert!(!should_spawn_reconciled_gui_window(true,+ false,"thinkterm:not-a-thread-workspace"));}@@ -1123,14 +1144,28 @@ mod tests {fn reconcile_shows_thinkterm_domain_thread_windows() {assert!(should_spawn_reconciled_gui_window(true,+ false,"thinkterm:muxdomain-host::space::space-1:thread-2"));assert!(should_spawn_reconciled_gui_window(true,+ false,"thinkterm:muxdomain-host::space::space-1:thread-2:remote-default"));}+ #[test]+ fn reconcile_opens_only_the_hosts_startup_window() {+ // The host's thread windows belong to the local Spaces and are+ // opened through the thread store, never one per live thread.+ assert!(should_spawn_reconciled_gui_window(false, true, "default"));+ assert!(!should_spawn_reconciled_gui_window(+ false,+ true,+ "thinkterm:project-1:thread-2"+ ));+ }+#[test]fn replacement_recovery_targets_the_stable_slot_in_the_current_generation() {let recovery_targets = [diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rsindex e1dfc66c..ac7847eb 100644--- a/wezterm-gui/src/main.rs+++ b/wezterm-gui/src/main.rs@@ -362,24 +362,17 @@ async fn spawn_tab_in_domain_if_mux_is_empty(let domain = domain.unwrap_or_else(|| mux.default_domain());- // The local session host was attached before this ran, but the local- // windows for its remote ones arrive with the topology sync, which can- // still be in flight; deciding before it lands spawns a startup tab- // into a server that already holds the threads. Sync first.+ // The local session host was attached before this ran and its windows+ // are mirrored already (the attach installs the topology before it+ // returns). Its threads live in thread workspaces, which reconcile+ // leaves hidden, so "the domain has panes" is not "a window will open".+ // Judge the startup workspace alone: a startup tab there gets a window,+ // whose restore then adopts the live thread and cleans the tab up -- as+ // it does in process.let mut workspace = workspace;if let Some(client) = domain.downcast_ref::<ClientDomain>() {- if client.is_local_session_host() && domain.state() == mux::domain::DomainState::Attached {- if let Err(err) = client.resync().await {- log::warn!("local sessions: syncing the session server at startup: {err:#}");- }- // Its threads live in thread workspaces, which reconcile leaves- // hidden, so "the domain has panes" is not "a window will- // open". Judge the startup workspace alone: a startup tab there- // gets a window, whose restore then adopts the live thread and- // cleans the tab up -- as it does in process.- if workspace.is_none() {- workspace = Some(mux.active_workspace());- }+ if client.is_local_session_host() && workspace.is_none() {+ workspace = Some(mux.active_workspace());}}