From 7c339e629d7f391ca8175fab6592f9353dd1cbd9 Mon Sep 17 00:00:00 2001 From: Angel-Mario Savin Date: Fri, 20 Nov 2026 15:06:28 +0200 Subject: [PATCH] Reopen the last closed session with Ctrl+Z (Cmd+Z on macOS) --- README.md | 2 +- src/app/headless.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/app/input.rs | 10 +++++++++ src/app/mod.rs | 3 +++ src/app/sessions.rs | 14 ++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8728017..ea8c466 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Claudiu is a native desktop app, written in Rust with [Rune](https://github.com/ ## What it does -Each session is your own `claude` process in a real terminal, and sign-in stays with Claude Code. Around it, Claudiu adds a sidebar of running and recent sessions, notifications when a background session finishes or asks something, an editor mode (Ctrl+Shift+E), usage meters, a GitHub pane, cards Claude draws inline, sessions that move between git worktrees, extra accounts that share one configuration, and Codex, OpenCode and Google Antigravity subagents (Settings → Custom subagents). Codex subagents need Node and a `codex login`, OpenCode subagents need `opencode` on PATH, Antigravity subagents need the Antigravity CLI (`agy`) installed and signed in, and with Allow edits on, each acts without Claude Code's permission rules. Read-only Antigravity runs from its own folder in Claudiu's data, whose hook refuses every tool but reading and searching, so your own Antigravity rules, skills and MCP servers don't load there. Google's [Antigravity terms](https://antigravity.google/terms) and [FAQ](https://antigravity.google/docs/faq) forbid using another company's agent, such as Claude Code, with a personal Google sign-in. That covers the Free, AI Plus, Pro and Ultra plans. Google can suspend or terminate the Antigravity and Gemini CLI accounts of anyone who does, so turn Antigravity subagents on at your own risk. With Codex subagents on, the sidebar also shows Codex's 5-hour and 7-day limits, which Claudiu reads from the session logs in `~/.codex`; with Antigravity subagents on, it shows Antigravity's limits for each group of models, from `agy`'s own `/usage`, asked every five minutes at no token cost. Their last saved readings show at launch and refresh in the background. Settings lists the rest. +Each session is your own `claude` process in a real terminal, and sign-in stays with Claude Code. Around it, Claudiu adds a sidebar of running and recent sessions (Ctrl+Z, or Cmd+Z on macOS, reopens the last one you closed), notifications when a background session finishes or asks something, an editor mode (Ctrl+Shift+E), usage meters, a GitHub pane, cards Claude draws inline, sessions that move between git worktrees, extra accounts that share one configuration, and Codex, OpenCode and Google Antigravity subagents (Settings → Custom subagents). Codex subagents need Node and a `codex login`, OpenCode subagents need `opencode` on PATH, Antigravity subagents need the Antigravity CLI (`agy`) installed and signed in, and with Allow edits on, each acts without Claude Code's permission rules. Read-only Antigravity runs from its own folder in Claudiu's data, whose hook refuses every tool but reading and searching, so your own Antigravity rules, skills and MCP servers don't load there. Google's [Antigravity terms](https://antigravity.google/terms) and [FAQ](https://antigravity.google/docs/faq) forbid using another company's agent, such as Claude Code, with a personal Google sign-in. That covers the Free, AI Plus, Pro and Ultra plans. Google can suspend or terminate the Antigravity and Gemini CLI accounts of anyone who does, so turn Antigravity subagents on at your own risk. With Codex subagents on, the sidebar also shows Codex's 5-hour and 7-day limits, which Claudiu reads from the session logs in `~/.codex`; with Antigravity subagents on, it shows Antigravity's limits for each group of models, from `agy`'s own `/usage`, asked every five minutes at no token cost. Their last saved readings show at launch and refresh in the background. Settings lists the rest. While a custom subagent works, its own view in Claude Code's tasks list streams its messages, reasoning, plan and tool steps and command output. The main conversation stays as it is until the subagent hands back its report. The first Codex run takes longer while npm downloads the adapter. Claude can choose a Codex subagent's effort when it starts one (`max` runs as Codex's `xhigh`); otherwise Codex uses the effort in `~/.codex/config.toml`. diff --git a/src/app/headless.rs b/src/app/headless.rs index 3e4b703..286929f 100644 --- a/src/app/headless.rs +++ b/src/app/headless.rs @@ -1056,6 +1056,58 @@ fn quitting_asks_first_only_while_a_session_is_working() { assert!(h.ws().modal.is_none()); } +/// Ctrl+Z (Cmd+Z on macOS) resumes the sessions closed since Claudiu started, the last closed first. The editor keeps +/// the key for undo, and off macOS a shell keeps it to suspend its job. +#[test] +fn the_undo_key_reopens_closed_sessions_the_last_closed_first() { + let mut h = Harness::new(|_| vec![]); + let cwd = h.work.join("project"); + std::fs::create_dir_all(&cwd).unwrap(); + std::fs::write(cwd.join("code.rs"), "fn a() {}\n").unwrap(); + let exe = h.ws().claude_exe.clone().unwrap(); + let first = h.start_one("First", &cwd, claude::resume_spec(&exe, &cwd, "first")); + let second = h.start_one("Second", &cwd, claude::resume_spec(&exe, &cwd, "second")); + let third = h.start_one("Third", &cwd, claude::resume_spec(&exe, &cwd, "third")); + h.wait("the sessions starting", |ws| [&first, &second, &third].iter().all(|id| ws.is_running(id))); + h.step(|ws| ws.close_live(&first)); + h.step(|ws| ws.close_live(&second)); + let undo = |h: &mut Harness| h.press(rune::Key::Command('z'), secondary); + + // The shell under the shown session has the keyboard. + h.step(|ws| ws.show_session(&third)); + h.step(|ws| ws.toggle_shell_here()); + assert_eq!(h.ws().keys_to, Some(shell_key(&third))); + undo(&mut h); + assert_eq!(h.ws().is_running(&second), cfg!(target_os = "macos"), "off macOS the shell keeps Ctrl+Z"); + if h.ws().is_running(&second) { + h.step(|ws| ws.close_live(&second)); + } + + // The editor has the keyboard. + h.step(|ws| ws.show_session(&third)); + h.step(|ws| ws.toggle_editor()); + h.wait("listing", |ws| !ws.panes[&third].root.as_os_str().is_empty()); + let root = h.editor_pane(&third).root.clone(); + h.step(|ws| ws.open_file(&third, root.join("code.rs"), None)); + h.wait("opening", |ws| ws.panes[&third].shown().is_some()); + h.step(|ws| ws.focus_pane()); + assert!(h.ws().keys_in_pane()); + undo(&mut h); + assert!(!h.ws().is_running(&second), "the editor keeps the key for undo"); + h.step(|ws| ws.toggle_editor()); + + // Claude has the keyboard. + h.step(|ws| ws.show_session(&third)); + assert_eq!(h.ws().keys_to.as_deref(), Some(third.as_str())); + undo(&mut h); + h.wait("the second to come back", |ws| ws.is_running(&second)); + assert!(!h.ws().is_running(&first), "one press brings back one session"); + undo(&mut h); + h.wait("the first to come back", |ws| ws.is_running(&first)); + undo(&mut h); + assert_eq!(h.ws().running_count(), 3, "with nothing left to reopen the key does nothing"); +} + /// Hundreds of recent sessions: the RECENT list at the bottom opens to part of the window, scrolls under the wheel and /// keeps drawing rows where it brings them; its header closes it. #[test] diff --git a/src/app/input.rs b/src/app/input.rs index fad9f22..8a21472 100644 --- a/src/app/input.rs +++ b/src/app/input.rs @@ -219,6 +219,9 @@ impl Workspace { self.pane_command(c); return true; } + if commands::is_chord(ks, "secondary-z") && self.undo_key_reopens() && self.reopen_closed() { + return true; + } let Some(key) = self.keys_to.clone() else { return false }; if let Some(e) = self.editor_mut(&key) { return e.on_key(ks, tx); @@ -229,6 +232,13 @@ impl Workspace { } } + /// Whether Ctrl+Z (Cmd+Z) is free to reopen a closed session: the editor keeps it for undo, and off macOS a shell + /// keeps Ctrl+Z to suspend the job it runs. + fn undo_key_reopens(&self) -> bool { + let in_shell = self.keys_to.as_deref().is_some_and(|k| k.starts_with("shell:")); + !self.keys_in_pane() && !(in_shell && !cfg!(target_os = "macos")) + } + /// A paste that reached no text field: the terminal with the keyboard takes it. pub fn on_paste(&mut self, content: &rune::ClipboardContent, tx: &mut Tx) { if self.search.focused || self.modal.is_some() { diff --git a/src/app/mod.rs b/src/app/mod.rs index 99bc6dd..2bdb30d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -469,6 +469,8 @@ pub struct Workspace { pub window_size: (f32, f32), /// Open sessions in the order they were last shown (most recent last); closing one goes back to the previous. recent: Vec, + /// Sessions the user closed since Claudiu started, the last closed last; Ctrl+Z (Cmd+Z) resumes them in turn. + closed: Vec, pub main: Main, pub selected: Option, pub search: TextEdit, @@ -569,6 +571,7 @@ impl Workspace { window_active: true, window_size: (1280.0, 800.0), recent: vec![], + closed: vec![], main: Main::Home, selected: store.data.layout.selected_session.clone(), search: TextEdit::new(""), diff --git a/src/app/sessions.rs b/src/app/sessions.rs index 644a165..5c89997 100644 --- a/src/app/sessions.rs +++ b/src/app/sessions.rs @@ -400,11 +400,25 @@ impl Workspace { pub(super) fn close_live(&mut self, id: &str) { let was_in = self.store.session(id).map(|s| (s.cwd.clone(), s.project_id.clone())); self.end_live(id); + self.closed.retain(|c| c != id); + self.closed.push(id.to_string()); if let Some((cwd, project)) = was_in { self.offer_worktree_removal(&cwd, project.as_deref()); } } + /// Resume the last closed session that can come back: one still in the history, with a Claude conversation, and + /// not running again. Whether there was one. + pub fn reopen_closed(&mut self) -> bool { + while let Some(id) = self.closed.pop() { + if !self.is_running(&id) && self.store.session(&id).is_some_and(|r| r.claude.is_some()) { + self.resume(&id); + return true; + } + } + false + } + pub(super) fn end_live(&mut self, id: &str) { if self.logins.remove(id) { self.refresh_accounts();