Cleanup has entered the editor
Visual Studio Code 1.141 adds a worktree cleanup editor for inactive agent sessions. It can filter by inactivity and size. It can also configure automatic cleanup for sessions whose pull requests were merged.[1]
The release notes state what cleanup does. It marks selected sessions done and deletes their worktrees. Restoring a session can recreate its worktree. Active, running, needs-input, and pinned sessions are protected.
The cleanup button joins two records. One belongs to the agent session. The other belongs to Git.
The window is no longer the process
VS Code's Agent Host is a dedicated process that owns agent sessions. A session can continue after its original folder or editor window closes. Several clients can connect to that host while the session remains one live object.[2]
Version 1.141 also adds a Background Shells list for Copilot harness sessions. It shows commands that still run while the agent takes other steps.[1] That list matters during cleanup because a quiet chat panel is no longer proof of a quiet machine.
Git keeps its own ledger
Git describes a linked worktree as a working tree plus administrative metadata. git worktree list reports the checked-out revision, branch, lock state, and whether an entry is prunable. A worktree lock prevents pruning, moving, and deletion.[3]
git worktree prune removes stale administrative records. git worktree remove removes a linked working tree. They are not the same operation. Git also refuses to remove a dirty worktree unless force is used. A cleanup interface should keep these differences visible instead of compressing them into one storage number.
Inspect in the order damage can happen
Check the process first. A background command can still write into the tree. Check the tree second for edits and untracked files. Check the branch third for commits that exist only locally or changes that never reached the intended target. Close the session record last, after the work has an owner and a recovery route.
Age and disk size can sort the queue. They cannot make the disposal decision. A two-day-old clean worktree tied to a running migration deserves a hold. A month-old worktree with an unpushed fix deserves an owner.
Keep the delete command off the checklist
The tow yard below is a teaching fixture. It never deletes a worktree. It produces a review sheet with read-only Git checks and placeholders for the live shell record, exact path, revision, and recovery owner.
Use the sheet before the editor's cleanup action or a manual Git removal. The final state says review candidate, not safe to delete. Real removal still needs evidence from the named host and repository.