wt list shows errors for worktrees being removed in background
Problem
When running wt list immediately after wt remove, the removed worktree often still appears in the list with errors or stale data. This happens because:
wt remove spawns background removal (with 1 second delay)
- User runs
wt list before removal completes
- Git still reports the worktree, but git operations fail because the directory is being deleted
Example
$ wt remove
◎ Running pre-remove project:docs:
lsof -ti :17911 | xargs kill 2>/dev/null || true
◎ Removing todos worktree & branch in background (no added changes on main, ⊂)
○ Switched to worktree for main @ ~/workspace/worktrunk
◎ Running post-switch user hook:
echo | zellij pipe --name change-tab-name -- "$(jq -cn '{pane_id: $ENV.ZELLIJ_PANE_ID, name: " main"}')"
$ wt list
Branch Status HEAD± main↕ Path Remote⇅ URL Commit Age Message
@ main ^| . | :12107 dcda7873 32m adjust guidance...
+ todos _ ../worktrunk.todos :17911 d11fad1a 56y
...
○ Showing 5 worktrees, 1 with changes
▲ Some git operations failed:
todos: commit-details (Failed to execute: git show -s --format=%ct d11fad1a...)
todos: ahead-behind (Failed to execute: git rev-list --left-right --count main...d11fad1a...)
todos: committed-trees-match (Failed to execute: git rev-parse d11fad1a...^{tree} main^{tree})
todos: has-file-changes (Failed to execute: git diff --name-only main...todos)
todos: is-ancestor (Failed to execute: git merge-base --is-ancestor d11fad1a... main)
todos: working-tree-diff (Failed to execute: git status --porcelain)
todos: merge-tree-conflicts (Failed to execute: git merge-tree --write-tree main d11fad1a...)
↳ To create a diagnostic file, re-run with --verbose
Note the 56y age — git operations are failing and returning garbage data.
Root cause
The background removal has a 1 second delay (to let shell cd complete), then runs:
git worktree remove <path>
git branch -D <branch> (if branch was merged)
During this window, git worktree list --porcelain still returns the worktree, but:
- The directory may be partially deleted
- Git commands targeting that worktree fail
- The branch ref may already be deleted
Desired behavior
Worktrees with pending background removal should either:
- Not appear in
wt list at all, OR
- Appear with a clear "pending removal" indicator (no errors, no stale data)
Possible solutions
Neither solution is great, but they're the simplest approaches.
Option A: Marker file in .git/wt-logs/
Write .git/wt-logs/{branch}-pending-removal before spawning background removal.
Delete after removal completes.
In wt list:
- Check for marker file
- Filter out or show with special indicator
Pros: Simple, doesn't touch git state
Cons: Another state file to manage; cleanup on failure
Option B: Check remove log recency
If .git/wt-logs/{branch}-remove.log exists and was modified within last 5 seconds, treat as pending removal.
Pros: No new files/state
Cons: Heuristic, race conditions possible
wt listshows errors for worktrees being removed in backgroundProblem
When running
wt listimmediately afterwt remove, the removed worktree often still appears in the list with errors or stale data. This happens because:wt removespawns background removal (with 1 second delay)wt listbefore removal completesExample
Note the
56yage — git operations are failing and returning garbage data.Root cause
The background removal has a 1 second delay (to let shell cd complete), then runs:
git worktree remove <path>git branch -D <branch>(if branch was merged)During this window,
git worktree list --porcelainstill returns the worktree, but:Desired behavior
Worktrees with pending background removal should either:
wt listat all, ORPossible solutions
Neither solution is great, but they're the simplest approaches.
Option A: Marker file in
.git/wt-logs/Write
.git/wt-logs/{branch}-pending-removalbefore spawning background removal.Delete after removal completes.
In
wt list:Pros: Simple, doesn't touch git state
Cons: Another state file to manage; cleanup on failure
Option B: Check remove log recency
If
.git/wt-logs/{branch}-remove.logexists and was modified within last 5 seconds, treat as pending removal.Pros: No new files/state
Cons: Heuristic, race conditions possible