By default, branches are deleted when they would add no changes to the default branch if merged. This works with both unchanged git histories, and squash-merge or rebase workflows where commit history differs but file changes match.
Worktrunk checks six conditions:
Same commit — Branch HEAD equals the default branch. Shows _ in wt list.
Ancestor — Branch is in target’s history (fast-forward or rebase case). Shows ⊂.
No added changes — Three-dot diff (target...branch) is empty. Shows ⊂.
Trees match — Branch tree SHA equals target tree SHA. Shows ⊂.
Merge adds nothing — Simulated merge produces the same tree as target. Handles squash-merged branches where target has advanced with changes to different files. Shows ⊂.
Patch-id match — Branch’s entire diff matches a single squash-merge commit on target. Fallback for when the simulated merge conflicts because target later modified the same files the branch touched. Shows ⊂.
The default-branch walk is capped so a single check stays fast; a squash merge with hundreds of commits landed since the merge point falls outside the cap and needs -D to remove.
The ‘same commit’ check uses the local default branch; for other checks, ‘target’ means the default branch, or its upstream (e.g., origin/main) when strictly ahead.
Branches matching these conditions and with empty working trees are dimmed in wt list as safe to delete.
Worktrunk has two force flags for different situations:
Flag
Scope
When to use
Flag--force (-f)
ScopeWorktree
When to useWorktree has uncommitted changes
Flag--force-delete (-D)
ScopeBranch
When to useBranch has unmerged commits
wtremovefeature--force# Remove dirty worktree
wtremovefeature-D# Delete unmerged branch
wtremovefeature--force-D# Both
Before --force discards uncommitted changes, Worktrunk saves them (except ignored files and changes inside submodules) to refs/wt-backup/<branch> and prints a command to recover them in a new worktree.
Use --no-delete-branch to keep the branch regardless of merge status.
Removal runs in the background by default — the command returns immediately, and output goes to .git/wt/logs/{branch}/internal/remove.log. Use --foreground to wait for it.
--reap terminates processes left running in the worktree before it is removed — a post-start dev server, a file watcher, a language server — freeing the ports and file handles they hold. Processes are discovered by working directory: any process whose current directory is at or under the worktree path (SIGTERM, then SIGKILL for survivors).
wtremove--reapfeature
◎ Reaping 2 processes under feature worktree
┃ 51234 node
┃ 51240 esbuild
✓ Reaped 2 processes
◎ Removing feature worktree & branch in background (same commit as main, _)
To avoid killing work the user did not mean to kill, two guards keep --reap conservative:
Interactive processes are spared. A process holding a controlling terminal — an interactive shell, or a terminal editor such as vim with unsaved buffers — is never reaped. Only detached processes remain candidates.
Discovery is by working directory only. A process that started in the worktree and later changed directory, or a daemon that reparented to init, no longer reports a directory under the worktree and is not found. To reliably reap those, launch them with wt step tether, which kills the whole process group when the worktree is removed.
--format=json prints one object per removal to stdout: {kind, branch, path, branch_outcome, branch_checked_out_at} for a worktree, with pruned in place of path for a branch-only removal. Branch-only results also include detached_worktree: the path of a detached worktree at the branch’s expected location, which the removal leaves in place, or null.
branch_outcome names what happened to the branch, so a caller can tell a deletion the removal declined from one it was never asked to make:
Value
Meaning
deleted
The branch is gone
deferred
Left to the background removal, whose result this run doesn’t see. --foreground never reports it
not_attempted
No deletion was tried: a detached worktree, a sibling checkout, or --no-delete-branch
retained_unmerged
Declined: the branch was not integrated into the target
retained_checked_out
Declined: another worktree has the branch checked out
retained_raced
Declined: the branch moved during the removal. Retry
pre-remove hooks run before the worktree is deleted (with access to worktree files). post-remove hooks run after removal. See wt hook for configuration.
You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.