[Feature]: Clean up worktrees for settled threads without deleting history #5208
Before submitting#
- I searched existing issues and did not find an open issue covering this exact behavior.
- I am describing a concrete problem or use case, not just a vague idea.
Area#
apps/web, apps/server
Problem or use case#
Sidebar V2 can classify threads as settled manually, after a PR is merged or closed, or after inactivity. Settling only changes the thread lifecycle and UI state. The linked worktree stays on disk.
With a worktree-first workflow, finished threads can leave behind many checkouts containing node_modules, build outputs, and other generated files. Deleting the thread can remove an orphaned worktree, but it also deletes the conversation history. I want to keep the settled thread while releasing its worktree.
Proposed solution#
Add a safe Remove worktree action for settled threads.
Normal removal should only be allowed when the worktree:
- has no running session or pending work
- is not referenced by another thread
- has no uncommitted changes
- has no unpushed commits
The thread, branch, and conversation history should remain. If the thread is used again, T3 Code could recreate the worktree or offer to do so.
A later extension could auto-prune safe worktrees after a configurable number of days settled. Automatic cleanup should never force-delete dirty or unpushed work.
Smallest useful scope#
A manual action in the settled thread context menu, with a confirmation and a clear reason when removal is blocked.
Alternatives considered#
- Delete the thread: frees the worktree, but also removes history.
- Delete the directory manually: can leave T3 Code and Git worktree state out of sync.
Examples or references#
- #4765 tracks clearing settled threads, but does so by deleting or archiving the threads.
- #684 requested repo-level bulk worktree cleanup, but is closed.
- #4742 implemented a broader worktree inventory and pruning system, but was closed without merging.
Contribution#
- I would be open to helping implement this.
Sign in to join this conversation.
I am also encountering this issue, it makes it inconvenient to use sidebar v2 without manually doing the second step of archiving as well