Skip to content

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

feat: add `wt step prune` to remove merged worktrees (#1191)

Maximilian Roos35c2172b746e
diff --git a/Cargo.lock b/Cargo.lock
index bc8cfd77b..ac3e6cf25 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1105,6 +1105,12 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "humantime"
+version = "2.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
+
[[package]]
name = "iana-time-zone"
version = "0.1.64"
@@ -3196,6 +3202,7 @@ dependencies = [
"etcetera",
"fs2",
"home",
+ "humantime",
"ignore",
"indexmap",
"insta",
diff --git a/Cargo.toml b/Cargo.toml
index 9c4443936..110726c67 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -103,6 +103,7 @@ wrap-ansi = "0.1"
osc8 = "0.1.0"
supports-hyperlinks = "3"
home = "0.5.12"
+humantime = "2.2"
once_cell = "1.21"
dirs = "6.0"
normalize-path = "0.2.1"
diff --git a/docs/content/step.md b/docs/content/step.md
index fe29c3eb3..d9cc85d3d 100644
--- a/docs/content/step.md
+++ b/docs/content/step.md
@@ -38,6 +38,7 @@ wt step push
- `copy-ignored` — Copy gitignored files between worktrees
- `for-each` — [experimental] Run a command in every worktree
- `promote` — [experimental] Put a branch into the main worktree
+- `prune` — Remove worktrees and branches merged into the default branch
- `relocate` — [experimental] Move worktrees to expected paths
## See also
@@ -64,6 +65,7 @@ Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span
<b><span class=c>copy-ignored</span></b> Copy gitignored files to another worktree
<b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=c>promote</span></b> [experimental] Put a branch into the main worktree
+ <b><span class=c>prune</span></b> Remove worktrees merged into the default branch
<b><span class=c>relocate</span></b> [experimental] Move worktrees to expected paths
<b><span class=g>Options:</span></b>
@@ -447,6 +449,75 @@ Usage: <b><span class=c>wt step for-each</span></b> <span class=c>[OPTIONS]</spa
Verbose output (-v: hooks, templates; -vv: debug report)
{% end %}
+## wt step prune
+
+Remove worktrees merged into the default branch.
+
+Bulk-removes worktrees and branches that are integrated into the default branch, using the same criteria as `wt remove`'s branch cleanup. Stale worktree entries are cleaned up too.
+
+In `wt list`, candidates show `_` (same commit) or `⊂` (content integrated). Run `--dry-run` to preview. See `wt remove --help` for the full integration criteria.
+
+Locked worktrees and the main worktree are always skipped. The current worktree is removed last, triggering cd to the primary worktree. Pre-remove and post-remove hooks run for each removal.
+
+### Min-age guard
+
+Worktrees younger than `--min-age` (default: 1 hour) are skipped. This prevents removing a worktree just created from the default branch — it looks "merged" because its branch points at the same commit.
+
+```bash
+wt step prune --min-age=0s # no age guard
+wt step prune --min-age=2d # skip worktrees younger than 2 days
+```
+
+### Examples
+
+Preview what would be removed:
+
+```bash
+wt step prune --dry-run
+```
+
+Remove all merged worktrees:
+
+```bash
+wt step prune
+```
+
+### Command reference
+
+{% terminal() %}
+wt step prune - Remove worktrees merged into the default branch
+
+Usage: <b><span class=c>wt step prune</span></b> <span class=c>[OPTIONS]</span>
+
+<b><span class=g>Options:</span></b>
+ <b><span class=c>--dry-run</span></b>
+ Show what would be removed
+
+ <b><span class=c>-y</span></b>, <b><span class=c>--yes</span></b>
+ Skip approval prompts
+
+ <b><span class=c>--min-age</span></b><span class=c> &lt;MIN_AGE&gt;</span>
+ Skip worktrees younger than this
+
+ [default: 1h]
+
+ <b><span class=c>--foreground</span></b>
+ Run removal in foreground (block until complete)
+
+ <b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
+ Print help (see a summary with &#39;-h&#39;)
+
+<b><span class=g>Global Options:</span></b>
+ <b><span class=c>-C</span></b><span class=c> &lt;path&gt;</span>
+ Working directory for this command
+
+ <b><span class=c>--config</span></b><span class=c> &lt;path&gt;</span>
+ User config file path
+
+ <b><span class=c>-v</span></b>, <b><span class=c>--verbose</span></b><span class=c>...</span>
+ Verbose output (-v: hooks, templates; -vv: debug report)
+{% end %}
+
## wt step relocate
[experimental] Move worktrees to expected paths. Relocates worktrees whose path doesn't match the worktree-path template.
diff --git a/skills/worktrunk/reference/step.md b/skills/worktrunk/reference/step.md
index f89e8c752..0fbd596f8 100644
--- a/skills/worktrunk/reference/step.md
+++ b/skills/worktrunk/reference/step.md
@@ -29,6 +29,7 @@ wt step push
- `copy-ignored` — Copy gitignored files between worktrees
- `for-each` — [experimental] Run a command in every worktree
- `promote` — [experimental] Put a branch into the main worktree
+- `prune` — Remove worktrees and branches merged into the default branch
- `relocate` — [experimental] Move worktrees to expected paths
## Command reference
@@ -49,6 +50,7 @@ Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span
<b><span class=c>copy-ignored</span></b> Copy gitignored files to another worktree
<b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=c>promote</span></b> [experimental] Put a branch into the main worktree
+ <b><span class=c>prune</span></b> Remove worktrees merged into the default branch
<b><span class=c>relocate</span></b> [experimental] Move worktrees to expected paths
<b><span class=g>Options:</span></b>
@@ -423,6 +425,73 @@ Usage: <b><span class=c>wt step for-each</span></b> <span class=c>[OPTIONS]</spa
<b><span class=c>-v</span></b>, <b><span class=c>--verbose</span></b><span class=c>...</span>
Verbose output (-v: hooks, templates; -vv: debug report)
+## wt step prune
+
+Remove worktrees merged into the default branch.
+
+Bulk-removes worktrees and branches that are integrated into the default branch, using the same criteria as `wt remove`'s branch cleanup. Stale worktree entries are cleaned up too.
+
+In `wt list`, candidates show `_` (same commit) or `⊂` (content integrated). Run `--dry-run` to preview. See `wt remove --help` for the full integration criteria.
+
+Locked worktrees and the main worktree are always skipped. The current worktree is removed last, triggering cd to the primary worktree. Pre-remove and post-remove hooks run for each removal.
+
+### Min-age guard
+
+Worktrees younger than `--min-age` (default: 1 hour) are skipped. This prevents removing a worktree just created from the default branch — it looks "merged" because its branch points at the same commit.
+
+```bash
+wt step prune --min-age=0s # no age guard
+wt step prune --min-age=2d # skip worktrees younger than 2 days
+```
+
+### Examples
+
+Preview what would be removed:
+
+```bash
+wt step prune --dry-run
+```
+
+Remove all merged worktrees:
+
+```bash
+wt step prune
+```
+
+### Command reference
+
+wt step prune - Remove worktrees merged into the default branch
+
+Usage: <b><span class=c>wt step prune</span></b> <span class=c>[OPTIONS]</span>
+
+<b><span class=g>Options:</span></b>
+ <b><span class=c>--dry-run</span></b>
+ Show what would be removed
+
+ <b><span class=c>-y</span></b>, <b><span class=c>--yes</span></b>
+ Skip approval prompts
+
+ <b><span class=c>--min-age</span></b><span class=c> &lt;MIN_AGE&gt;</span>
+ Skip worktrees younger than this
+
+ [default: 1h]
+
+ <b><span class=c>--foreground</span></b>
+ Run removal in foreground (block until complete)
+
+ <b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
+ Print help (see a summary with &#39;-h&#39;)
+
+<b><span class=g>Global Options:</span></b>
+ <b><span class=c>-C</span></b><span class=c> &lt;path&gt;</span>
+ Working directory for this command
+
+ <b><span class=c>--config</span></b><span class=c> &lt;path&gt;</span>
+ User config file path
+
+ <b><span class=c>-v</span></b>, <b><span class=c>--verbose</span></b><span class=c>...</span>
+ Verbose output (-v: hooks, templates; -vv: debug report)
+
## wt step relocate
[experimental] Move worktrees to expected paths. Relocates worktrees whose path doesn't match the worktree-path template.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index a20712877..daeae4512 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1028,6 +1028,7 @@ wt step push
- `copy-ignored` — Copy gitignored files between worktrees
- `for-each` — [experimental] Run a command in every worktree
- `promote` — [experimental] Put a branch into the main worktree
+- `prune` — Remove worktrees and branches merged into the default branch
- `relocate` — [experimental] Move worktrees to expected paths
## See also
@@ -1038,6 +1039,7 @@ wt step push
<!-- subdoc: squash -->
<!-- subdoc: copy-ignored -->
<!-- subdoc: for-each -->
+<!-- subdoc: prune -->
<!-- subdoc: relocate -->"#
)]
Step {
diff --git a/src/cli/step.rs b/src/cli/step.rs
index 58125b12c..f8f108af0 100644
--- a/src/cli/step.rs
+++ b/src/cli/step.rs
@@ -423,6 +423,56 @@ Gitignored files are swapped along with the branches so each worktree keeps the
branch: Option<String>,
},
+ /// Remove worktrees merged into the default branch
+ #[command(
+ after_long_help = r#"Bulk-removes worktrees and branches that are integrated into the default branch, using the same criteria as `wt remove`'s branch cleanup. Stale worktree entries are cleaned up too.
+
+In `wt list`, candidates show `_` (same commit) or `⊂` (content integrated). Run `--dry-run` to preview. See `wt remove --help` for the full integration criteria.
+
+Locked worktrees and the main worktree are always skipped. The current worktree is removed last, triggering cd to the primary worktree. Pre-remove and post-remove hooks run for each removal.
+
+## Min-age guard
+
+Worktrees younger than `--min-age` (default: 1 hour) are skipped. This prevents removing a worktree just created from the default branch — it looks "merged" because its branch points at the same commit.
+
+```console
+wt step prune --min-age=0s # no age guard
+wt step prune --min-age=2d # skip worktrees younger than 2 days
+```
+
+## Examples
+
+Preview what would be removed:
+
+```console
+wt step prune --dry-run
+```
+
+Remove all merged worktrees:
+
+```console
+wt step prune
+```
+"#
+ )]
+ Prune {
+ /// Show what would be removed
+ #[arg(long)]
+ dry_run: bool,
+
+ /// Skip approval prompts
+ #[arg(short, long)]
+ yes: bool,
+
+ /// Skip worktrees younger than this
+ #[arg(long, default_value = "1h")]
+ min_age: String,
+
+ /// Run removal in foreground (block until complete)
+ #[arg(long)]
+ foreground: bool,
+ },
+
/// \[experimental\] Move worktrees to expected paths
///
/// Relocates worktrees whose path doesn't match the `worktree-path` template.
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 9b4aece34..ac8be8637 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -41,7 +41,7 @@ pub(crate) use merge::{MergeOptions, handle_merge};
pub(crate) use select::handle_select;
pub(crate) use step_commands::{
PromoteResult, RebaseResult, SquashResult, handle_promote, handle_rebase, handle_squash,
- step_commit, step_copy_ignored, step_diff, step_relocate, step_show_squash_prompt,
+ step_commit, step_copy_ignored, step_diff, step_prune, step_relocate, step_show_squash_prompt,
};
pub(crate) use worktree::{
OperationMode, handle_remove, handle_remove_current, is_worktree_at_expected_path,
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rs
index 660e6b4c8..24a646a2a 100644
--- a/src/commands/repository_ext.rs
+++ b/src/commands/repository_ext.rs
@@ -19,6 +19,8 @@ pub enum RemoveTarget<'a> {
Branch(&'a str),
/// Remove the current worktree (supports detached HEAD)
Current,
+ /// Remove worktree by path (supports detached HEAD)
+ Path(&'a std::path::Path),
}
/// CLI-only helpers implemented on [`Repository`] via an extension trait so we can keep orphan
@@ -137,15 +139,18 @@ impl RepositoryCliExt for Repository {
}
}
}
- RemoveTarget::Current => {
+ RemoveTarget::Current | RemoveTarget::Path(_) => {
+ let lookup_path = match target {
+ RemoveTarget::Path(p) => p,
+ _ => current_path.as_path(),
+ };
let wt = worktrees
.iter()
- .find(|wt| wt.path == current_path)
+ .find(|wt| wt.path == lookup_path)
.ok_or_else(|| {
- anyhow::anyhow!("Current worktree not found in worktree list")
+ anyhow::anyhow!("Worktree not found at {}", lookup_path.display())
})?;
if wt.locked.is_some() {
- // Use branch name if available, otherwise use directory name
let name = wt
.branch
.clone()
@@ -157,7 +162,8 @@ impl RepositoryCliExt for Repository {
}
.into());
}
- (wt.path.clone(), wt.branch.clone(), true)
+ let is_current = wt.path == current_path;
+ (wt.path.clone(), wt.branch.clone(), is_current)
}
};
diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rs
index 640b24d01..3381c1694 100644
--- a/src/commands/step_commands.rs
+++ b/src/commands/step_commands.rs
@@ -10,10 +10,12 @@
//! Standalone:
//! - `step_copy_ignored` - Copy gitignored files matching .worktreeinclude
//! - `handle_promote` - Put a branch into the main worktree
+//! - `step_prune` - Remove worktrees merged into the default branch
use std::fs;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
+use std::time::Duration;
use anyhow::Context;
use color_print::cformat;
@@ -31,7 +33,9 @@ use super::command_approval::approve_hooks;
use super::commit::{CommitGenerator, CommitOptions, StageMode};
use super::context::CommandEnv;
use super::hooks::{HookFailureStrategy, run_hook_with_filter};
-use super::repository_ext::RepositoryCliExt;
+use super::repository_ext::{RemoveTarget, RepositoryCliExt};
+use super::worktree::BranchDeletionMode;
+use crate::output::handle_remove_output;
use worktrunk::shell_exec::Cmd;
/// Handle `wt step commit` command
@@ -1266,6 +1270,305 @@ fn create_symlink(target: &Path, src_path: &Path, dest_path: &Path) -> anyhow::R
Ok(())
}
+/// Remove worktrees and branches integrated into the default branch.
+///
+/// Handles four cases: live worktrees with branches (removed + branch deleted),
+/// detached HEAD worktrees (directory removed, no branch to delete), stale worktree
+/// entries (pruned + branch deleted), and orphan branches without worktrees (deleted).
+/// Skips the main/primary worktree, locked worktrees, and worktrees younger than
+/// `min_age`. Removes the current worktree last to trigger cd to primary.
+pub fn step_prune(dry_run: bool, yes: bool, min_age: &str, foreground: bool) -> anyhow::Result<()> {
+ let min_age_duration =
+ humantime::parse_duration(min_age).context("Invalid --min-age duration")?;
+
+ let repo = Repository::current()?;
+ let config = UserConfig::load()?;
+
+ let integration_target = match repo.integration_target() {
+ Some(target) => target,
+ None => {
+ anyhow::bail!("cannot determine default branch");
+ }
+ };
+
+ let worktrees = repo.list_worktrees()?;
+ let current_root = repo.current_worktree().root()?.to_path_buf();
+ let current_root = dunce::canonicalize(&current_root).unwrap_or(current_root);
+ let now_secs = worktrunk::utils::get_now();
+
+ let default_branch = repo.default_branch();
+
+ // Gather candidates: integrated worktrees + integrated branch-only refs
+ struct Candidate {
+ /// Branch name (None for detached HEAD worktrees)
+ branch: Option<String>,
+ /// Display label: branch name or abbreviated commit SHA
+ label: String,
+ /// Worktree path (for Path-based removal of detached worktrees)
+ path: Option<PathBuf>,
+ /// Current worktree, other worktree, or branch-only (no worktree)
+ kind: CandidateKind,
+ reason_desc: String,
+ }
+ enum CandidateKind {
+ Current,
+ Other,
+ BranchOnly,
+ }
+
+ let mut candidates: Vec<Candidate> = Vec::new();
+ let mut skipped_young: Vec<String> = Vec::new();
+ // Track branches seen via worktree entries so we don't double-count.
+ // Pre-seed with the default branch to prevent it from being pruned
+ // (it's trivially "integrated" into itself).
+ let mut seen_branches: std::collections::HashSet<String> =
+ default_branch.iter().cloned().collect();
+
+ for wt in &worktrees {
+ // Track branches so the orphan scan doesn't re-discover them
+ if let Some(branch) = &wt.branch {
+ seen_branches.insert(branch.clone());
+ }
+
+ // Skip locked worktrees
+ if wt.locked.is_some() {
+ continue;
+ }
+
+ // Never prune the default branch
+ if let Some(branch) = &wt.branch
+ && default_branch.as_deref() == Some(branch.as_str())
+ {
+ continue;
+ }
+
+ // Prunable entries (directory gone): check integration, include as branch-only
+ if wt.is_prunable() {
+ if let Some(branch) = &wt.branch {
+ let (effective_target, reason) =
+ repo.integration_reason(branch, &integration_target)?;
+ if let Some(reason) = reason {
+ candidates.push(Candidate {
+ label: branch.clone(),
+ branch: Some(branch.clone()),
+ path: None,
+ kind: CandidateKind::BranchOnly,
+ reason_desc: format!("{} {}", reason.description(), effective_target),
+ });
+ }
+ }
+ continue;
+ }
+
+ // Skip main worktree (non-linked); in bare repos all are linked,
+ // so the default-branch check above is the primary guard.
+ let wt_tree = repo.worktree_at(&wt.path);
+ if !wt_tree.is_linked()? {
+ continue;
+ }
+
+ // For integration check: use branch name, or commit SHA for detached
+ let integration_ref = match &wt.branch {
+ Some(b) if !wt.detached => b.as_str(),
+ _ => &wt.head,
+ };
+
+ // Check integration first — only apply age guard to integrated worktrees
+ let (effective_target, reason) =
+ repo.integration_reason(integration_ref, &integration_target)?;
+ let Some(reason) = reason else {
+ continue;
+ };
+
+ let label = wt
+ .branch
+ .clone()
+ .unwrap_or_else(|| format!("(detached {})", &wt.head[..7.min(wt.head.len())]));
+
+ // Check age: skip recently-created worktrees that look "merged" because
+ // they were just created from the default branch
+ if min_age_duration > Duration::ZERO {
+ let git_dir = wt_tree.git_dir()?;
+ let metadata = fs::metadata(&git_dir).context("Failed to read worktree git dir")?;
+ let created = metadata.created().or_else(|_| {
+ // Fallback: mtime of the `commondir` file (write-once by git worktree add)
+ fs::metadata(git_dir.join("commondir")).and_then(|m| m.modified())
+ });
+ if let Ok(created) = created
+ && let Ok(created_epoch) = created.duration_since(std::time::UNIX_EPOCH)
+ {
+ let age = Duration::from_secs(now_secs.saturating_sub(created_epoch.as_secs()));
+ if age < min_age_duration {
+ skipped_young.push(label);
+ continue;
+ }
+ }
+ }
+
+ let wt_path = dunce::canonicalize(&wt.path).unwrap_or(wt.path.clone());
+ let is_current = wt_path == current_root;
+ candidates.push(Candidate {
+ branch: if wt.detached { None } else { wt.branch.clone() },
+ label,
+ path: Some(wt.path.clone()),
+ kind: if is_current {
+ CandidateKind::Current
+ } else {
+ CandidateKind::Other
+ },
+ reason_desc: format!("{} {}", reason.description(), effective_target),
+ });
+ }
+
+ // Also scan local branches that don't have a worktree entry
+ for branch in repo.all_branches()? {
+ if seen_branches.contains(&branch) {
+ continue;
+ }
+ let (effective_target, reason) = repo.integration_reason(&branch, &integration_target)?;
+ if let Some(reason) = reason {
+ // Apply min-age guard: check reflog creation timestamp
+ if min_age_duration > Duration::ZERO {
+ let ref_name = format!("refs/heads/{branch}");
+ if let Ok(stdout) = repo.run_command(&["reflog", "show", "--format=%ct", &ref_name])
+ {
+ // Last reflog entry is the branch creation event
+ if let Some(created_epoch) = stdout
+ .trim()
+ .lines()
+ .last()
+ .and_then(|s| s.parse::<u64>().ok())
+ {
+ let age = Duration::from_secs(now_secs.saturating_sub(created_epoch));
+ if age < min_age_duration {
+ skipped_young.push(branch.clone());
+ continue;
+ }
+ }
+ }
+ }
+ candidates.push(Candidate {
+ label: branch.clone(),
+ branch: Some(branch),
+ path: None,
+ kind: CandidateKind::BranchOnly,
+ reason_desc: format!("{} {}", reason.description(), effective_target),
+ });
+ }
+ }
+
+ if candidates.is_empty() {
+ let msg = if skipped_young.is_empty() {
+ "No merged worktrees to remove".to_string()
+ } else {
+ let names = skipped_young.join(", ");
+ format!("No merged worktrees to remove (skipped {names}, younger than {min_age})")
+ };
+ eprintln!("{}", info_message(msg));
+ return Ok(());
+ }
+
+ if !skipped_young.is_empty() {
+ let names = skipped_young.join(", ");
+ eprintln!(
+ "{}",
+ info_message(format!("Skipped {names} (younger than {min_age})"))
+ );
+ }
+
+ if dry_run {
+ for c in &candidates {
+ eprintln!(
+ "{}",
+ info_message(cformat!("<bold>{}</> — {}", c.label, c.reason_desc,))
+ );
+ }
+ let noun = if candidates.len() == 1 {
+ "worktree"
+ } else {
+ "worktrees"
+ };
+ eprintln!(
+ "{}",
+ hint_message(format!(
+ "{} {noun} would be removed (dry run)",
+ candidates.len()
+ ))
+ );
+ return Ok(());
+ }
+
+ // Approve hooks
+ let env = CommandEnv::for_action_branchless()?;
+ let ctx = env.context(yes);
+ let run_hooks = approve_hooks(
+ &ctx,
+ &[
+ HookType::PreRemove,
+ HookType::PostRemove,
+ HookType::PostSwitch,
+ ],
+ )?;
+ if !run_hooks {
+ eprintln!("{}", info_message("Commands declined, continuing removal"));
+ }
+
+ // Sort: current worktree last so cd-to-primary happens after other removals
+ candidates.sort_by_key(|c| matches!(c.kind, CandidateKind::Current));
+
+ // Prepare removal plans
+ let mut plans: Vec<super::worktree::RemoveResult> = Vec::new();
+ for c in &candidates {
+ let target = match c.kind {
+ CandidateKind::Current => RemoveTarget::Current,
+ CandidateKind::BranchOnly => {
+ RemoveTarget::Branch(c.branch.as_ref().expect("BranchOnly has branch"))
+ }
+ CandidateKind::Other => match &c.branch {
+ Some(branch) => RemoveTarget::Branch(branch),
+ None => RemoveTarget::Path(c.path.as_ref().expect("detached has path")),
+ },
+ };
+ let plan =
+ repo.prepare_worktree_removal(target, BranchDeletionMode::SafeDelete, false, &config)?;
+ plans.push(plan);
+ }
+
+ // Execute removals (current worktree is last due to sort above)
+ for result in &plans {
+ handle_remove_output(result, !foreground, run_hooks)?;
+ }
+
+ let worktree_count = candidates
+ .iter()
+ .filter(|c| !matches!(c.kind, CandidateKind::BranchOnly))
+ .count();
+ let branch_count = candidates.len() - worktree_count;
+ let mut parts = Vec::new();
+ if worktree_count > 0 {
+ let noun = if worktree_count == 1 {
+ "worktree"
+ } else {
+ "worktrees"
+ };
+ parts.push(format!("{worktree_count} {noun}"));
+ }
+ if branch_count > 0 {
+ let noun = if branch_count == 1 {
+ "branch"
+ } else {
+ "branches"
+ };
+ parts.push(format!("{branch_count} {noun}"));
+ }
+ eprintln!(
+ "{}",
+ success_message(format!("Pruned {}", parts.join(", ")))
+ );
+
+ Ok(())
+}
+
/// Move worktrees to their expected paths based on the `worktree-path` template.
///
/// See `src/commands/relocate.rs` for the implementation details and algorithm.
diff --git a/src/main.rs b/src/main.rs
index defc01598..1d63ee259 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,7 +53,7 @@ use commands::{
handle_rebase, handle_remove, handle_remove_current, handle_show_theme, handle_squash,
handle_state_clear, handle_state_clear_all, handle_state_get, handle_state_set,
handle_state_show, handle_switch, handle_unconfigure_shell, resolve_worktree_arg, run_hook,
- step_commit, step_copy_ignored, step_diff, step_for_each, step_relocate,
+ step_commit, step_copy_ignored, step_diff, step_for_each, step_prune, step_relocate,
};
use output::handle_remove_output;
@@ -564,6 +564,12 @@ fn main() {
}
})
}
+ StepCommand::Prune {
+ dry_run,
+ yes,
+ min_age,
+ foreground,
+ } => step_prune(dry_run, yes, &min_age, foreground),
StepCommand::Relocate {
branches,
dry_run,
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 173482c49..640654d48 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -594,11 +594,12 @@ fn test_complete_step_subcommands(repo: TestRepo) {
assert!(subcommands.contains(&"diff"), "Missing diff");
assert!(subcommands.contains(&"for-each"), "Missing for-each");
assert!(subcommands.contains(&"promote"), "Missing promote");
+ assert!(subcommands.contains(&"prune"), "Missing prune");
assert!(subcommands.contains(&"relocate"), "Missing relocate");
assert_eq!(
subcommands.len(),
- 9,
- "Should have exactly 9 step subcommands"
+ 10,
+ "Should have exactly 10 step subcommands"
);
}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index c9454a0e0..2f8155c60 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -57,6 +57,7 @@ pub mod statusline;
pub mod step_copy_ignored;
pub mod step_diff;
pub mod step_promote;
+pub mod step_prune;
pub mod step_relocate;
pub mod switch;
pub mod switch_picker;
diff --git a/tests/integration_tests/step_prune.rs b/tests/integration_tests/step_prune.rs
new file mode 100644
index 000000000..f398bf1dd
--- /dev/null
+++ b/tests/integration_tests/step_prune.rs
@@ -0,0 +1,357 @@
+//! Integration tests for `wt step prune`
+
+use crate::common::{TestRepo, make_snapshot_cmd, repo};
+use insta_cmd::assert_cmd_snapshot;
+use rstest::rstest;
+
+/// No merged worktrees — nothing to prune
+#[rstest]
+fn test_prune_no_merged(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a worktree with a unique commit (not merged into main)
+ repo.add_worktree_with_commit("feature", "f.txt", "content", "feature commit");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--dry-run", "--min-age=0s"],
+ None
+ ));
+}
+
+/// Prune dry-run shows merged worktrees.
+///
+/// Two worktrees exercise the "N worktrees" plural path in the dry-run hint.
+#[rstest]
+fn test_prune_dry_run(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create worktrees at same commit as main (look merged)
+ repo.add_worktree("merged-a");
+ repo.add_worktree("merged-b");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--dry-run", "--min-age=0s"],
+ None
+ ));
+
+ // Verify worktrees still exist (dry run)
+ let parent = repo.root_path().parent().unwrap();
+ assert!(
+ parent.join("repo.merged-a").exists(),
+ "Dry run should not remove worktrees"
+ );
+ assert!(
+ parent.join("repo.merged-b").exists(),
+ "Dry run should not remove worktrees"
+ );
+}
+
+/// Prune actually removes merged worktrees
+#[rstest]
+fn test_prune_removes_merged(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a worktree at same commit as main (integrated)
+ repo.add_worktree("merged-branch");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+
+ // Verify worktree was removed
+ let worktree_path = repo
+ .root_path()
+ .parent()
+ .unwrap()
+ .join("repo.merged-branch");
+ assert!(!worktree_path.exists(), "Merged worktree should be removed");
+}
+
+/// Prune skips worktrees with unique commits (not merged)
+#[rstest]
+fn test_prune_skips_unmerged(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // One merged worktree
+ repo.add_worktree("merged-one");
+
+ // One unmerged worktree (has a unique commit)
+ repo.add_worktree_with_commit("unmerged", "u.txt", "content", "unmerged commit");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+
+ // Merged worktree removed
+ let merged_path = repo.root_path().parent().unwrap().join("repo.merged-one");
+ assert!(!merged_path.exists(), "Merged worktree should be removed");
+
+ // Unmerged worktree still exists
+ let unmerged_path = repo.root_path().parent().unwrap().join("repo.unmerged");
+ assert!(unmerged_path.exists(), "Unmerged worktree should remain");
+}
+
+/// Min-age guard: worktrees younger than threshold are skipped.
+///
+/// With test epoch (Jan 2025) and real file creation (Feb 2026), get_now()
+/// returns a time before the file was created, so age is 0 — always younger
+/// than any positive threshold. This verifies the guard works.
+#[rstest]
+fn test_prune_min_age_skips_young(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a worktree at same commit as main (would be pruned without age guard)
+ repo.add_worktree("young-branch");
+
+ // Default min-age (1h) — worktree appears "young" due to test epoch
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--dry-run"],
+ None
+ ));
+
+ // Verify worktree still exists
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.young-branch");
+ assert!(worktree_path.exists(), "Young worktree should be skipped");
+}
+
+/// Prune multiple merged worktrees at once
+#[rstest]
+fn test_prune_multiple(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ repo.add_worktree("merged-a");
+ repo.add_worktree("merged-b");
+ repo.add_worktree("merged-c");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+
+ // All merged worktrees removed
+ let parent = repo.root_path().parent().unwrap();
+ assert!(!parent.join("repo.merged-a").exists());
+ assert!(!parent.join("repo.merged-b").exists());
+ assert!(!parent.join("repo.merged-c").exists());
+}
+
+/// Prune skips unmerged detached HEAD worktrees
+#[rstest]
+fn test_prune_skips_unmerged_detached(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Merged worktree — should be pruned
+ repo.add_worktree("merged-branch");
+
+ // Unmerged worktree with detached HEAD — should be skipped (not integrated)
+ repo.add_worktree_with_commit("detached-branch", "d.txt", "data", "detached commit");
+ repo.detach_head_in_worktree("detached-branch");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--dry-run", "--min-age=0s"],
+ None
+ ));
+
+ // Both worktrees still exist (dry run)
+ let parent = repo.root_path().parent().unwrap();
+ assert!(parent.join("repo.merged-branch").exists());
+ assert!(parent.join("repo.detached-branch").exists());
+}
+
+/// Prune removes integrated detached HEAD worktrees
+#[rstest]
+fn test_prune_removes_integrated_detached(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Worktree at same commit as main, then detach — integrated and detached
+ repo.add_worktree("detached-integrated");
+ repo.detach_head_in_worktree("detached-integrated");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+
+ // Worktree was removed
+ let parent = repo.root_path().parent().unwrap();
+ assert!(
+ !parent.join("repo.detached-integrated").exists(),
+ "Integrated detached worktree should be removed"
+ );
+}
+
+/// Prune skips locked worktrees
+#[rstest]
+fn test_prune_skips_locked(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Merged worktree — should be pruned
+ repo.add_worktree("merged-branch");
+
+ // Locked worktree at same commit — should be skipped
+ repo.add_worktree("locked-branch");
+ repo.lock_worktree("locked-branch", Some("in use"));
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+
+ // Merged removed, locked remains
+ let parent = repo.root_path().parent().unwrap();
+ assert!(!parent.join("repo.merged-branch").exists());
+ assert!(
+ parent.join("repo.locked-branch").exists(),
+ "Locked worktree should be skipped"
+ );
+}
+
+/// Prune deletes orphan branches (integrated branches without worktrees).
+///
+/// Two orphan branches exercise the "N branches" plural path in the summary.
+/// Uses a far-future epoch so branches pass the reflog age guard through the
+/// normal age-check path (rather than bypassing with --min-age=0s).
+#[rstest]
+fn test_prune_orphan_branches(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create two branches at HEAD (integrated) without worktrees
+ repo.create_branch("orphan-a");
+ repo.create_branch("orphan-b");
+
+ // Create an unmerged branch (has a unique commit via worktree, then remove worktree)
+ repo.add_worktree_with_commit("unmerged-orphan", "u.txt", "data", "unique commit");
+
+ // Far-future epoch: branches appear ~5 years old, passing the default 1h guard
+ let mut cmd = make_snapshot_cmd(&repo, "step", &["prune", "--yes"], None);
+ cmd.env("WORKTRUNK_TEST_EPOCH", "1893456000"); // 2030-01-01
+
+ assert_cmd_snapshot!(cmd);
+}
+
+/// Orphan branches (no worktree) respect the min-age guard via reflog timestamps.
+///
+/// GIT_COMMITTER_DATE=2025-01-01T00:00:00Z makes the branch reflog timestamp
+/// epoch 1735689600. Setting TEST_EPOCH to 30 minutes later (1735691400) means
+/// the branch appears 30 minutes old, which is younger than the default 1h.
+#[rstest]
+fn test_prune_orphan_branch_min_age(repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a branch at HEAD (integrated) without a worktree
+ repo.create_branch("orphan-integrated");
+
+ // Epoch 30 minutes after GIT_COMMITTER_DATE → branch appears 30min old, < 1h
+ let mut cmd = make_snapshot_cmd(&repo, "step", &["prune", "--yes"], None);
+ cmd.env("WORKTRUNK_TEST_EPOCH", "1735691400"); // 2025-01-01T00:30:00Z
+
+ assert_cmd_snapshot!(cmd);
+}
+
+/// Prune from a merged worktree removes it last (CandidateKind::Current).
+///
+/// Skipped on Windows: Windows locks the current working directory, preventing
+/// `git worktree remove` from deleting it.
+#[rstest]
+#[cfg(not(target_os = "windows"))]
+fn test_prune_current_worktree(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a worktree at same commit as main
+ let wt_path = repo.add_worktree("current-merged");
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ Some(&wt_path)
+ ));
+
+ // Current worktree was removed
+ assert!(
+ !wt_path.exists(),
+ "Current merged worktree should be removed"
+ );
+}
+
+/// Prune handles stale/prunable worktrees (directory deleted but git metadata remains)
+#[rstest]
+fn test_prune_stale_worktree(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Create a worktree at same commit (integrated), then delete its directory
+ let wt_path = repo.add_worktree("stale-branch");
+ std::fs::remove_dir_all(&wt_path).unwrap();
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--yes", "--min-age=0s"],
+ None
+ ));
+}
+
+/// Min-age check passes when worktrees are old enough.
+///
+/// Uses a far-future epoch (2030) so real worktrees (created Feb 2026) appear
+/// ~4 years old, passing the default 1h min-age. This exercises the age
+/// fall-through path that `--min-age=0s` bypasses entirely.
+#[rstest]
+fn test_prune_min_age_passes(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ repo.add_worktree("old-merged");
+
+ // Far-future epoch: worktrees appear ~4 years old
+ let mut cmd = make_snapshot_cmd(&repo, "step", &["prune", "--dry-run"], None);
+ cmd.env("WORKTRUNK_TEST_EPOCH", "1893456000"); // 2030-01-01
+
+ assert_cmd_snapshot!(cmd);
+}
+
+/// Stale candidate + young worktrees: shows both the candidate and skipped count.
+///
+/// A stale worktree (directory deleted) bypasses the age check because it goes
+/// through the `is_prunable()` path. A regular merged worktree with the default
+/// epoch appears young and is skipped. This exercises the "N skipped" message
+/// alongside candidates (lines that require both skipped_young > 0 and
+/// non-empty candidates).
+#[rstest]
+fn test_prune_stale_plus_young(mut repo: TestRepo) {
+ repo.commit("initial");
+
+ // Stale worktree: directory deleted, but git metadata remains → candidate
+ let wt_path = repo.add_worktree("stale-branch");
+ std::fs::remove_dir_all(&wt_path).unwrap();
+
+ // Regular merged worktree: with default epoch it appears "young"
+ repo.add_worktree("young-branch");
+
+ // Default min-age (1h) — young-branch is skipped, stale-branch is a candidate
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--dry-run"],
+ None
+ ));
+}
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_long.snap b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
index 7d3ec2169..45211261e 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
@@ -45,6 +45,7 @@ Usage: wt step [OPTIONS] <COMMAND>
copy-ignored Copy gitignored files to another worktree
for-each [experimental] Run command in each worktree
promote [experimental] Put a branch into the main worktree
+ prune Remove worktrees merged into the default branch
relocate [experimental] Move worktrees to expected paths
Options:
@@ -84,6 +85,7 @@ Manual merge workflow with review between steps:
- copy-ignored — Copy gitignored files between worktrees
- for-each — [experimental] Run a command in every worktree
- promote — [experimental] Put a branch into the main worktree
+- prune — Remove worktrees and branches merged into the default branch
- relocate — [experimental] Move worktrees to expected paths
See also
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_short.snap b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
index d6c417cef..72db40629 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
@@ -17,6 +17,7 @@ info:
TERM: alacritty
WORKTRUNK_APPROVALS_PATH: /nonexistent/test/approvals.toml
WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+ WORKTRUNK_SYSTEM_CONFIG_PATH: /etc/xdg/worktrunk/config.toml
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
@@ -42,6 +43,7 @@ Usage: wt step [OPTIONS] <COMMAND>
copy-ignored Copy gitignored files to another worktree
for-each [experimental] Run command in each worktree
promote [experimental] Put a branch into the main worktree
+ prune Remove worktrees merged into the default branch
relocate [experimental] Move worktrees to expected paths
Options:
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap
new file mode 100644
index 000000000..3418e31e7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing current-merged worktree & branch in background (same commit as main, _)
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
+✓ Pruned 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap
new file mode 100644
index 000000000..26a676ba9
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/step_prune.rs
+assertion_line: 34
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ merged-a — same commit as main
+○ merged-b — same commit as main
+↳ 2 worktrees would be removed (dry run)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap
new file mode 100644
index 000000000..7c217c814
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1893456000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ old-merged — same commit as main
+↳ 1 worktree would be removed (dry run)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_skips_young.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_skips_young.snap
new file mode 100644
index 000000000..2ed0e5c2f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_skips_young.snap
@@ -0,0 +1,45 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No merged worktrees to remove (skipped young-branch, younger than 1h)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap
new file mode 100644
index 000000000..463fde594
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing merged-a worktree & branch in background (same commit as main, _)
+◎ Removing merged-b worktree & branch in background (same commit as main, _)
+◎ Removing merged-c worktree & branch in background (same commit as main, _)
+✓ Pruned 3 worktrees
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_no_merged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_no_merged.snap
new file mode 100644
index 000000000..b45b55090
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_no_merged.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No merged worktrees to remove
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branch_min_age.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branch_min_age.snap
new file mode 100644
index 000000000..adb9a17b4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branch_min_age.snap
@@ -0,0 +1,45 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735691400"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No merged worktrees to remove (skipped orphan-integrated, younger than 1h)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap
new file mode 100644
index 000000000..e1195c2e3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap
@@ -0,0 +1,50 @@
+---
+source: tests/integration_tests/step_prune.rs
+assertion_line: 246
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1893456000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No worktree found for branch orphan-a
+✓ Removed branch orphan-a (same commit as main, _)
+○ No worktree found for branch orphan-b
+✓ Removed branch orphan-b (same commit as main, _)
+✓ Pruned 2 branches
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap
new file mode 100644
index 000000000..7cf0c1537
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing worktree @ _REPO_.detached-integrated in background (detached HEAD, no branch to delete)
+○ No worktree found for branch detached-integrated
+✓ Removed branch detached-integrated (same commit as main, _)
+✓ Pruned 1 worktree, 1 branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap
new file mode 100644
index 000000000..f79a2e47a
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing merged-branch worktree & branch in background (same commit as main, _)
+✓ Pruned 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap
new file mode 100644
index 000000000..f79a2e47a
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing merged-branch worktree & branch in background (same commit as main, _)
+✓ Pruned 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap
new file mode 100644
index 000000000..8ab9fca58
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Removing merged-one worktree & branch in background (same commit as main, _)
+✓ Pruned 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap
new file mode 100644
index 000000000..63c5e70c6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ merged-branch — same commit as main
+↳ 1 worktree would be removed (dry run)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_stale_plus_young.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_stale_plus_young.snap
new file mode 100644
index 000000000..8f41f3e8d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_stale_plus_young.snap
@@ -0,0 +1,48 @@
+---
+source: tests/integration_tests/step_prune.rs
+assertion_line: 346
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--dry-run"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Skipped young-branch (younger than 1h)
+○ stale-branch — same commit as main
+↳ 1 worktree would be removed (dry run)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_stale_worktree.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_stale_worktree.snap
new file mode 100644
index 000000000..6afd86ea3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_stale_worktree.snap
@@ -0,0 +1,48 @@
+---
+source: tests/integration_tests/step_prune.rs
+assertion_line: 301
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--yes"
+ - "--min-age=0s"
+ 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_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_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: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Pruned stale worktree & removed branch stale-branch (same commit as main, _)
+✓ Pruned 1 branch