After removing a worktree, there is a remaining folder with `removing` - why?
example: workstream-mono.payr-0-wt-test.wt-removing-1773715045
why is this left in my folder. Is there some background process that failed to complete?
Thanks for reporting this! I was able to reproduce the issue and identified the root cause: when wt remove renames the worktree directory to a staging path (.wt-removing-<timestamp>) but the background rm -rf process doesn't complete (e.g., process killed, system shutdown), the staging directory is left behind with no cleanup mechanism.
I've opened #1574 with a fix that cleans up stale .wt-removing-* directories opportunistically before each new removal. A maintainer will review it shortly.
Oh, it did eventually remove - it just took a really long time...
Good to know it did complete! That's actually the expected behavior — wt remove renames the directory to a staging path (.wt-removing-*) first so you can keep working immediately, then removes it in the background. For large worktrees with lots of files, that background deletion can take a while.
That said, the fix in #1574 is still worth having — if the background process ever does get interrupted (system shutdown, process kill), those staging directories would be left behind permanently today. The PR adds opportunistic cleanup so they get swept up on the next removal.
One thing I guess we could do, is to move it somewhere less more discreet while the background process removes it, like /tmp; would that make this less confusing?
Good idea — hiding it from the user's workspace would avoid the confusion entirely.
The reason the current implementation uses a sibling path is that rename() only works within the same filesystem — /tmp is often a separate tmpfs mount on Linux, so moving there would fall back to a full recursive copy, which is slow for large worktrees and defeats the "instant rename" benefit.
A few options:
- Try
/tmpfirst, fall back to sibling — best UX when filesystems match, but adds a visible.wt-removing-*path on the (common) cross-filesystem case anyway - Use a hidden sibling directory — e.g.,
.wt-removing/feature-1234567890in the parent — slightly more discreet sincelswon't show it by default - Move into
.git/— always same filesystem, already hidden from the user, and gets cleaned up if they delete the repo
Option 3 seems like the best tradeoff — same-filesystem rename is guaranteed, and the staging directory is completely out of sight. The only caveat is bare repos where .git/ is the repo root, but we could use a subdirectory like .git/wt-removing/.
What do you think?
yes, OK, good idea; draft it please @worktrunk-bot
can we use a path in .git that we already use, for our tiny metadata / log files?
can we make it clear it's not used; maybe name a subpath .trash?
Drafted in #1583 — staging directories now go to .git/wt-trash/ (following the existing .git/wt-logs/ convention). The rename is still instant since .git/ is always on the same filesystem as worktrees.
If the trash directory can't be created for some reason, it falls back to the legacy git worktree remove path.
great. thanks for the suggestion @ortonomy !