Skip to content

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

Use --foreground in remove-then-switch hint (#2040)

Maximilian Roos814d9fdba11c
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index 531f93f56..5a2c850ba 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -406,7 +406,7 @@ shouldn't clutter user output:
"To rebase onto main, run wt step rebase or wt merge"
// GOOD - recovery command after shadowing a remote branch
-"To switch to the remote branch, delete this branch and run without --create: wt remove feature && wt switch feature"
+"To switch to the remote branch, delete this branch and run without --create: wt remove --foreground feature && wt switch feature"
// BAD - command without context
"wt remove feature -D deletes unmerged branches"
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index e35615a46..c3427ab65 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -363,7 +363,10 @@ fn resolve_switch_target(
"Branch <bold>{resolved_branch}</> exists on remote ({remote_ref}); creating new branch from base instead"
))
);
- let remove_cmd = suggest_command("remove", &[&resolved_branch], &[]);
+ // `--foreground` is required: background removal leaves a placeholder
+ // directory at the original path (to keep shell PWD valid), which
+ // would block the subsequent `wt switch` with "Directory already exists".
+ let remove_cmd = suggest_command("remove", &[&resolved_branch], &["--foreground"]);
let switch_cmd = suggest_command("switch", &[&resolved_branch], &[]);
eprintln!(
"{}",
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
index aee7a6223..359ee87b6 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
@@ -46,7 +46,7 @@ exit_code: 0
----- stderr -----
▲ Branch remote-feature exists on remote (origin/remote-feature); creating new branch from base instead
-↳ To switch to the remote branch, delete this branch and run without --create: wt remove remote-feature && wt switch remote-feature
+↳ To switch to the remote branch, delete this branch and run without --create: wt remove --foreground remote-feature && wt switch remote-feature
✓ Created branch remote-feature from main and worktree @ _REPO_.remote-feature
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed