From c4ae85de725cb027a34d8fca543c7ad8a9af4c41 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Wed, 7 Jan 2026 09:59:15 +1100 Subject: [PATCH] Add --new-session flag to skip session resumption in agent mode Adds a new CLI flag that allows users to force a new session when running in agent mode, bypassing the automatic detection and resumption of incomplete sessions. Usage: g3 --agent my-agent --new-session --- crates/g3-cli/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/g3-cli/src/lib.rs b/crates/g3-cli/src/lib.rs index 05d47c5..10251d4 100644 --- a/crates/g3-cli/src/lib.rs +++ b/crates/g3-cli/src/lib.rs @@ -392,6 +392,10 @@ pub struct Cli { /// Run as a specialized agent (loads prompt from agents/.md) #[arg(long, value_name = "NAME", conflicts_with_all = ["autonomous", "auto", "chat", "planning"])] pub agent: Option, + + /// Skip session resumption and force a new session (for agent mode) + #[arg(long)] + pub new_session: bool, } pub async fn run() -> Result<()> { @@ -437,6 +441,7 @@ pub async fn run() -> Result<()> { cli.workspace.clone(), cli.config.as_deref(), cli.quiet, + cli.new_session, ) .await; } @@ -448,6 +453,7 @@ pub async fn run() -> Result<()> { cli.workspace.clone(), cli.config.as_deref(), cli.quiet, + cli.new_session, ) .await; } @@ -655,6 +661,7 @@ async fn run_agent_mode( workspace: Option, config_path: Option<&str>, _quiet: bool, + new_session: bool, ) -> Result<()> { use g3_core::get_agent_system_prompt; use g3_core::find_incomplete_agent_session; @@ -679,8 +686,14 @@ async fn run_agent_mode( // Change to the workspace directory first so session scanning works correctly std::env::set_current_dir(&workspace_dir)?; - // Check for incomplete agent sessions before starting a new one - let resuming_session = find_incomplete_agent_session(agent_name).ok().flatten(); + // Check for incomplete agent sessions before starting a new one (unless --new-session is set) + let resuming_session = if new_session { + output.print("\nšŸ†• Starting new session (--new-session flag set)"); + output.print(""); + None + } else { + find_incomplete_agent_session(agent_name).ok().flatten() + }; if let Some(ref incomplete_session) = resuming_session { output.print(&format!(