Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(switch): enrich error hints with --execute context (#1064)

Maximilian Roos51b5f6ef5fe8
diff --git a/src/commands/handle_switch.rs b/src/commands/handle_switch.rs
index 0abadc0bc..d3a43fdfc 100644
--- a/src/commands/handle_switch.rs
+++ b/src/commands/handle_switch.rs
@@ -6,7 +6,7 @@ use std::path::Path;
use anyhow::Context;
use worktrunk::HookType;
use worktrunk::config::{UserConfig, expand_template};
-use worktrunk::git::Repository;
+use worktrunk::git::{GitError, Repository, SwitchSuggestionCtx};
use worktrunk::styling::{eprintln, info_message};
use super::command_approval::approve_hooks;
@@ -147,8 +147,31 @@ pub fn handle_switch(
let repo = Repository::current().context("Failed to switch worktree")?;
+ // Build switch suggestion context for enriching error hints with --execute/trailing args.
+ // Without this, errors like "branch already exists" would suggest `wt switch <branch>`
+ // instead of the full `wt switch <branch> --execute=<cmd> -- <args>`.
+ let suggestion_ctx = execute.map(|exec| {
+ let escaped = shlex::try_quote(exec).unwrap_or(exec.into());
+ SwitchSuggestionCtx {
+ extra_flags: vec![format!("--execute={escaped}")],
+ trailing_args: execute_args.to_vec(),
+ }
+ });
+
// Validate FIRST (before approval) - fails fast if branch doesn't exist, etc.
- let plan = plan_switch(&repo, branch, create, base, clobber, config)?;
+ let plan = plan_switch(&repo, branch, create, base, clobber, config).map_err(|err| {
+ match suggestion_ctx {
+ Some(ref ctx) => match err.downcast::<GitError>() {
+ Ok(git_err) => GitError::WithSwitchSuggestion {
+ source: Box::new(git_err),
+ ctx: ctx.clone(),
+ }
+ .into(),
+ Err(err) => err,
+ },
+ None => err,
+ }
+ })?;
// "Approve at the Gate": collect and approve hooks upfront
// This ensures approval happens once at the command entry point
diff --git a/src/git/error.rs b/src/git/error.rs
index 1a336bf10..a44faaf22 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -105,6 +105,43 @@ pub struct FailedCommand {
pub exit_info: String,
}
+/// Extra CLI context for enriching `wt switch` suggestions in error hints.
+///
+/// When a switch error is raised deep in the planning layer, the error only knows
+/// the branch name. The command handler wraps the error with this context so the
+/// Display impl can produce a fully copy-pasteable suggestion including flags like
+/// `--execute` and trailing args.
+#[derive(Debug, Clone)]
+pub struct SwitchSuggestionCtx {
+ pub extra_flags: Vec<String>,
+ pub trailing_args: Vec<String>,
+}
+
+impl SwitchSuggestionCtx {
+ /// Append extra flags and trailing args to a suggested command string.
+ ///
+ /// Clap's `#[arg(last = true)]` on `execute_args` means `--` always routes
+ /// to execute_args, so a dash-prefixed branch can't coexist with `--execute`
+ /// via the CLI. The suggested command therefore never has a pre-existing `--`
+ /// separator when this context is applied.
+ fn apply(&self, cmd: String) -> String {
+ let mut result = cmd;
+ // Flags are pre-escaped at construction (handle_switch.rs uses shlex::try_quote)
+ for flag in &self.extra_flags {
+ result.push(' ');
+ result.push_str(flag);
+ }
+ if !self.trailing_args.is_empty() {
+ result.push_str(" --");
+ for arg in &self.trailing_args {
+ result.push(' ');
+ result.push_str(&escape(Cow::Borrowed(arg.as_str())));
+ }
+ }
+ result
+ }
+}
+
/// Domain errors for git and worktree operations.
///
/// This enum provides structured error data that can be pattern-matched and tested.
@@ -272,13 +309,33 @@ pub enum GitError {
Other {
message: String,
},
+
+ /// Wrapper that enriches an inner error's switch suggestions with CLI context.
+ ///
+ /// The inner error renders normally, but any `wt switch` suggestion includes
+ /// the extra flags and trailing args from the context.
+ WithSwitchSuggestion {
+ source: Box<GitError>,
+ ctx: SwitchSuggestionCtx,
+ },
}
impl std::error::Error for GitError {}
-impl std::fmt::Display for GitError {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+impl GitError {
+ /// Format with optional switch suggestion context.
+ ///
+ /// Most variants ignore `ctx`. The three that render `wt switch` suggestions
+ /// (`BranchAlreadyExists`, `BranchNotFound`, `WorktreePathExists`) use it
+ /// to append extra flags and trailing args for a copy-pasteable command.
+ fn fmt_with_ctx(
+ &self,
+ f: &mut std::fmt::Formatter<'_>,
+ ctx: Option<&SwitchSuggestionCtx>,
+ ) -> std::fmt::Result {
match self {
+ GitError::WithSwitchSuggestion { source, ctx } => source.fmt_with_ctx(f, Some(ctx)),
+
GitError::DetachedHead { action } => {
let message = match action {
Some(action) => format!("Cannot {action}: not on a branch (detached HEAD)"),
@@ -325,7 +382,10 @@ impl std::fmt::Display for GitError {
}
GitError::BranchAlreadyExists { branch } => {
- let switch_cmd = suggest_command("switch", &[branch], &[]);
+ let mut switch_cmd = suggest_command("switch", &[branch], &[]);
+ if let Some(ctx) = ctx {
+ switch_cmd = ctx.apply(switch_cmd);
+ }
write!(
f,
"{}\n{}",
@@ -342,7 +402,10 @@ impl std::fmt::Display for GitError {
} => {
let list_cmd = suggest_command("list", &[], &["--branches", "--remotes"]);
let hint = if *show_create_hint {
- let create_cmd = suggest_command("switch", &[branch], &["--create"]);
+ let mut create_cmd = suggest_command("switch", &[branch], &["--create"]);
+ if let Some(ctx) = ctx {
+ create_cmd = ctx.apply(create_cmd);
+ }
cformat!(
"To create a new branch, run <bright-black>{create_cmd}</>; to list branches, run <bright-black>{list_cmd}</>"
)
@@ -438,7 +501,10 @@ impl std::fmt::Display for GitError {
} else {
&["--clobber"]
};
- let switch_cmd = suggest_command("switch", &[branch], flags);
+ let mut switch_cmd = suggest_command("switch", &[branch], flags);
+ if let Some(ctx) = ctx {
+ switch_cmd = ctx.apply(switch_cmd);
+ }
write!(
f,
"{}\n{}",
@@ -805,6 +871,12 @@ impl std::fmt::Display for GitError {
}
}
+impl std::fmt::Display for GitError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.fmt_with_ctx(f, None)
+ }
+}
+
/// Semantic errors that require special handling in main.rs
///
/// Most errors use anyhow::bail! with formatted messages. This enum is only
@@ -997,7 +1069,7 @@ mod tests {
};
assert_snapshot!(err.to_string(), @"
✗ Directory already exists: /some/path
- ↳ To remove manually, run rm -rf /some/path; to overwrite (with backup), run wt switch feature --create --clobber
+ ↳ To remove manually, run rm -rf /some/path; to overwrite (with backup), run wt switch --create --clobber feature
");
}
@@ -1337,7 +1409,7 @@ mod tests {
};
let display = err.to_string();
assert!(display.contains("Cannot remove worktree"));
- assert!(display.contains("wt remove feature --force"));
+ assert!(display.contains("wt remove --force feature"));
assert!(display.contains("to lose uncommitted changes, run"));
}
@@ -1487,4 +1559,92 @@ mod tests {
assert!(display.contains("main"));
// Empty output shouldn't cause issues
}
+
+ #[test]
+ fn snapshot_with_switch_suggestion_branch_already_exists() {
+ let err = GitError::WithSwitchSuggestion {
+ source: Box::new(GitError::BranchAlreadyExists {
+ branch: "emails".into(),
+ }),
+ ctx: SwitchSuggestionCtx {
+ extra_flags: vec!["--execute=claude".into()],
+ trailing_args: vec!["Check my emails".into()],
+ },
+ };
+ assert_snapshot!(err.to_string(), @"
+ ✗ Branch emails already exists
+ ↳ To switch to the existing branch, run without --create: wt switch emails --execute=claude -- 'Check my emails'
+ ");
+ }
+
+ #[test]
+ fn snapshot_with_switch_suggestion_worktree_path_exists() {
+ let err = GitError::WithSwitchSuggestion {
+ source: Box::new(GitError::WorktreePathExists {
+ branch: "emails".into(),
+ path: PathBuf::from("/tmp/repo.emails"),
+ create: true,
+ }),
+ ctx: SwitchSuggestionCtx {
+ extra_flags: vec!["--execute=claude".into()],
+ trailing_args: vec!["Check my emails".into()],
+ },
+ };
+ assert_snapshot!(err.to_string(), @"
+ ✗ Directory already exists: /tmp/repo.emails
+ ↳ To remove manually, run rm -rf /tmp/repo.emails; to overwrite (with backup), run wt switch --create --clobber emails --execute=claude -- 'Check my emails'
+ ");
+ }
+
+ #[test]
+ fn snapshot_with_switch_suggestion_no_trailing_args() {
+ let err = GitError::WithSwitchSuggestion {
+ source: Box::new(GitError::BranchAlreadyExists {
+ branch: "emails".into(),
+ }),
+ ctx: SwitchSuggestionCtx {
+ extra_flags: vec!["--execute=claude".into()],
+ trailing_args: vec![],
+ },
+ };
+ assert_snapshot!(err.to_string(), @"
+ ✗ Branch emails already exists
+ ↳ To switch to the existing branch, run without --create: wt switch emails --execute=claude
+ ");
+ }
+
+ #[test]
+ fn snapshot_with_switch_suggestion_branch_not_found() {
+ let err = GitError::WithSwitchSuggestion {
+ source: Box::new(GitError::BranchNotFound {
+ branch: "emails".into(),
+ show_create_hint: true,
+ }),
+ ctx: SwitchSuggestionCtx {
+ extra_flags: vec!["--execute=claude".into()],
+ trailing_args: vec!["Check my emails".into()],
+ },
+ };
+ assert_snapshot!(err.to_string(), @"
+ ✗ No branch named emails
+ ↳ To create a new branch, run wt switch --create emails --execute=claude -- 'Check my emails'; to list branches, run wt list --branches --remotes
+ ");
+ }
+
+ #[test]
+ fn test_with_switch_suggestion_unwrapped_errors_unaffected() {
+ // Non-switch-suggestion errors should be completely unaffected by the wrapper
+ let inner = GitError::DetachedHead {
+ action: Some("merge".into()),
+ };
+ let wrapped = GitError::WithSwitchSuggestion {
+ source: Box::new(inner.clone()),
+ ctx: SwitchSuggestionCtx {
+ extra_flags: vec!["--execute=claude".into()],
+ trailing_args: vec!["Check my emails".into()],
+ },
+ };
+ // Errors without switch suggestions should render identically
+ assert_eq!(inner.to_string(), wrapped.to_string());
+ }
}
diff --git a/src/git/mod.rs b/src/git/mod.rs
index a78751587..3d9c0ea35 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -45,6 +45,8 @@ pub use error::{
// Platform-specific reference type (PR vs MR)
RefContext,
RefType,
+ // CLI context for enriching switch suggestions in error hints
+ SwitchSuggestionCtx,
WorktrunkError,
// Error inspection functions
add_hook_skip_hint,
diff --git a/src/styling/suggest.rs b/src/styling/suggest.rs
index 3a43c221e..2d1edfb1c 100644
--- a/src/styling/suggest.rs
+++ b/src/styling/suggest.rs
@@ -9,7 +9,7 @@
//! let branch = "feature";
//! let cmd = suggest_command("remove", &[branch], &["--force"]);
//! println!("{}", hint_message(cformat!("To force delete, run <bright-black>{cmd}</>")));
-//! // → ↳ To force delete, run wt remove feature --force
+//! // → ↳ To force delete, run wt remove --force feature
//! ```
//!
//! Handles shell escaping and `--` separator for args starting with `-`:
@@ -17,9 +17,9 @@
//! ```
//! use worktrunk::styling::suggest_command;
//!
-//! // Branch starting with dash gets -- separator
+//! // Branch starting with dash gets -- separator; flags stay before --
//! let cmd = suggest_command("remove", &["-bugfix"], &["--force"]);
-//! assert_eq!(cmd, "wt remove -- -bugfix --force");
+//! assert_eq!(cmd, "wt remove --force -- -bugfix");
//!
//! // Spaces are quoted
//! let cmd = suggest_command("remove", &["my feature"], &[]);
@@ -31,7 +31,7 @@ use std::borrow::Cow;
/// Build a suggested command string for hints.
///
-/// Returns a copy-pasteable command like `wt remove feature --force`.
+/// Returns a copy-pasteable command like `wt remove --force feature`.
///
/// # Arguments
///
@@ -60,6 +60,10 @@ use std::borrow::Cow;
pub fn suggest_command(subcommand: &str, args: &[&str], flags: &[&str]) -> String {
let mut parts = vec!["wt".to_string(), subcommand.to_string()];
+ // Flags go before positional args (and before any -- separator)
+ // so they're always parsed as flags, not positional arguments.
+ parts.extend(flags.iter().map(|s| s.to_string()));
+
// Check if any arg starts with dash (needs -- separator)
let needs_separator = args.iter().any(|arg| arg.starts_with('-'));
let mut separator_inserted = false;
@@ -73,7 +77,6 @@ pub fn suggest_command(subcommand: &str, args: &[&str], flags: &[&str]) -> Strin
parts.push(escape(Cow::Borrowed(*arg)).into_owned());
}
- parts.extend(flags.iter().map(|s| s.to_string()));
parts.join(" ")
}
@@ -93,7 +96,7 @@ mod tests {
fn test_command_with_flag() {
assert_eq!(
suggest_command("remove", &["feature"], &["--force"]),
- "wt remove feature --force"
+ "wt remove --force feature"
);
}
@@ -101,7 +104,7 @@ mod tests {
fn test_command_with_multiple_flags() {
assert_eq!(
suggest_command("remove", &["feature"], &["--force", "--no-delete-branch"]),
- "wt remove feature --force --no-delete-branch"
+ "wt remove --force --no-delete-branch feature"
);
}
@@ -133,7 +136,7 @@ mod tests {
fn test_branch_starting_with_dash_and_flag() {
assert_eq!(
suggest_command("remove", &["-bugfix"], &["--force"]),
- "wt remove -- -bugfix --force"
+ "wt remove --force -- -bugfix"
);
}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap
index 9987ec725..ab9d8f2ed 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap
@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rs
expression: err.to_string()
---
✗ No branch named nonexistent
-↳ To create a new branch, run wt switch nonexistent --create; to list branches, run wt list --branches --remotes
+↳ To create a new branch, run wt switch --create nonexistent; to list branches, run wt list --branches --remotes
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap
index 6232f1d7e..c61aa418f 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap
@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rs
expression: err.to_string()
---
✗ Cannot remove worktree: feature-branch has uncommitted changes
-↳ Commit or stash changes first, or to lose uncommitted changes, run wt remove feature-branch --force
+↳ Commit or stash changes first, or to lose uncommitted changes, run wt remove --force feature-branch
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap
index bfdc909e6..b5206b5f8 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap
@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rs
expression: err.to_string()
---
✗ Directory already exists: /tmp/repo.feature
-↳ To remove manually, run rm -rf /tmp/repo.feature; to overwrite (with backup), run wt switch feature --clobber
+↳ To remove manually, run rm -rf /tmp/repo.feature; to overwrite (with backup), run wt switch --clobber feature
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index e3b413c9d..b0eac95fd 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -87,6 +87,36 @@ fn test_switch_create_existing_branch_error(mut repo: TestRepo) {
);
}
+/// When --execute is passed and the branch already exists, the error hint should
+/// include --execute and trailing args in the suggested command.
+#[rstest]
+fn test_switch_create_existing_with_execute(mut repo: TestRepo) {
+ repo.add_worktree("emails");
+
+ snapshot_switch(
+ "switch_create_existing_with_execute",
+ &repo,
+ &[
+ "--create",
+ "--execute=claude",
+ "emails",
+ "--",
+ "Check my emails",
+ ],
+ );
+}
+
+/// When --execute is passed and the branch doesn't exist (without --create),
+/// the "create" suggestion should include --execute and trailing args.
+#[rstest]
+fn test_switch_nonexistent_with_execute(repo: TestRepo) {
+ snapshot_switch(
+ "switch_nonexistent_with_execute",
+ &repo,
+ &["--execute=claude", "nonexistent", "--", "Check my emails"],
+ );
+}
+
#[rstest]
fn test_switch_create_with_remote_branch_only(#[from(repo_with_remote)] repo: TestRepo) {
// Create a branch on the remote only (no local branch)
diff --git a/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap b/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap
index 4b29446cf..55be49252 100644
--- a/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap
+++ b/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 1
----- stderr -----
✗ No branch named my-feature
-↳ To create a new branch, run wt switch my-feature --create; to list branches, run wt list --branches --remotes
+↳ To create a new branch, run wt switch --create my-feature; to list branches, run wt list --branches --remotes
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap
index 26514c104..fe9a5b27d 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 1
----- stderr -----
✗ No branch named nonexistent-branch
-↳ To create a new branch, run wt switch nonexistent-branch --create; to list branches, run wt list --branches --remotes
+↳ To create a new branch, run wt switch --create nonexistent-branch; to list branches, run wt list --branches --remotes
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
index 6e17a1083..b3c8ede9d 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 0
----- stderr -----
◎ Removing feature-unmerged worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-unmerged -D
+↳ Branch unmerged; to delete, run wt remove -D feature-unmerged
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap b/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap
index 67680c992..5ec3bc4fd 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,4 +41,4 @@ exit_code: 0
----- stderr -----
○ No worktree found for branch feature-unmerged
○ Branch feature-unmerged retained; has unmerged changes
-↳ To delete the unmerged branch, run wt remove feature-unmerged -D
+↳ To delete the unmerged branch, run wt remove -D feature-unmerged
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap
index 7a6811830..a4a4b3323 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 1
----- stderr -----
✗ Cannot remove worktree: feature-dirty has uncommitted changes
-↳ Commit or stash changes first, or to lose uncommitted changes, run wt remove feature-dirty --force
+↳ Commit or stash changes first, or to lose uncommitted changes, run wt remove --force feature-dirty
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
index 94a797732..cff2722bc 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 0
----- stderr -----
◎ Removing feature-a worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-a -D
+↳ Branch unmerged; to delete, run wt remove -D feature-a
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
index 0e9216e58..1be5ec583 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 0
----- stderr -----
◎ Removing feature-b worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-b -D
+↳ Branch unmerged; to delete, run wt remove -D feature-b
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap
index f19e47dd8..c3755fa02 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap
@@ -30,6 +30,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,7 +41,7 @@ exit_code: 0
----- stderr -----
◎ Removing feature-a worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-a -D
+↳ Branch unmerged; to delete, run wt remove -D feature-a
○ No worktree found for branch feature-b
○ Branch feature-b retained; has unmerged changes
-↳ To delete the unmerged branch, run wt remove feature-b -D
+↳ To delete the unmerged branch, run wt remove -D feature-b
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap
index 58f859a68..ef4cf5cfc 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap
@@ -30,6 +30,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,4 +41,4 @@ exit_code: 0
----- stderr -----
◎ Removing feature-modified worktree (--force) in background
-↳ Branch unmerged; to delete, run wt remove feature-modified -D
+↳ Branch unmerged; to delete, run wt remove -D feature-modified
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap b/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap
index 681d78a37..8750cbcc9 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap
@@ -30,6 +30,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -41,4 +42,4 @@ exit_code: 0
----- stderr -----
◎ Removing feature-unmerged-fg worktree...
✓ Removed feature-unmerged-fg worktree
-↳ Branch unmerged; to delete, run wt remove feature-unmerged-fg -D
+↳ Branch unmerged; to delete, run wt remove -D feature-unmerged-fg
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
index d7d198df0..29afc987e 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
@@ -31,6 +31,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -41,10 +42,10 @@ exit_code: 0
----- stderr -----
◎ Removing feature-b worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-b -D
+↳ Branch unmerged; to delete, run wt remove -D feature-b
◎ Removing feature-c worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-c -D
+↳ Branch unmerged; to delete, run wt remove -D feature-c
◎ Removing feature-a worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-a -D
+↳ Branch unmerged; to delete, run wt remove -D feature-a
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
index 3d50cbfac..959af3ab0 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
@@ -31,6 +31,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -41,8 +42,8 @@ exit_code: 0
----- stderr -----
◎ Removing feature-a worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-a -D
+↳ Branch unmerged; to delete, run wt remove -D feature-a
◎ Removing feature-b worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-b -D
+↳ Branch unmerged; to delete, run wt remove -D feature-b
◎ Removing feature-c worktree in background
-↳ Branch unmerged; to delete, run wt remove feature-c -D
+↳ Branch unmerged; to delete, run wt remove -D feature-c
diff --git a/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap b/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap
index 97455caf7..fa26d624f 100644
--- a/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap
+++ b/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap
@@ -30,6 +30,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,4 +41,4 @@ exit_code: 1
----- stderr -----
✗ No branch named __WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6
-↳ To create a new branch, run wt switch '__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6' --create; to list branches, run wt list --branches --remotes
+↳ To create a new branch, run wt switch --create '__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6'; to list branches, run wt list --branches --remotes
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snap
new file mode 100644
index 000000000..b07cc8ed6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - "--execute=claude"
+ - emails
+ - "--"
+ - Check my emails
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ Branch emails already exists
+↳ To switch to the existing branch, run without --create: wt switch emails --execute=claude -- 'Check my emails'
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap
index 3a7c1b947..0360cd767 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap
@@ -30,6 +30,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,4 +41,4 @@ exit_code: 1
----- stderr -----
✗ Directory already exists: _REPO_.occupied-branch
-↳ To remove manually, run rm -rf _REPO_.occupied-branch; to overwrite (with backup), run wt switch occupied-branch --create --clobber
+↳ To remove manually, run rm -rf _REPO_.occupied-branch; to overwrite (with backup), run wt switch --create --clobber occupied-branch
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap
index 79aa91363..093c651e4 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap
@@ -29,6 +29,7 @@ info:
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,4 +40,4 @@ exit_code: 1
----- stderr -----
✗ No branch named nonexistent-branch
-↳ To create a new branch, run wt switch nonexistent-branch --create; to list branches, run wt list --branches --remotes
+↳ To create a new branch, run wt switch --create nonexistent-branch; to list branches, run wt list --branches --remotes
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snap
new file mode 100644
index 000000000..835a0d21b
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--execute=claude"
+ - nonexistent
+ - "--"
+ - Check my emails
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ No branch named nonexistent
+↳ To create a new branch, run wt switch --create nonexistent --execute=claude -- 'Check my emails'; to list branches, run wt list --branches --remotes