You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move worktree ownership to the host and give archived threads a Codex-style worktree lifecycle: deferred cleanup, snapshot before removal, ownership transfer, keep-count.
Tcode today
Nothing happens to a worktree on archive. On delete, an optional git worktree remove --force (branch tcode/<id> kept, uncommitted work lost; crates/services/src/worktree.rs).
After archive, cleanup runs after 60 s; unarchive inside the window cancels it.
If another unarchived thread uses the worktree, ownership moves to it; otherwise the state is committed to refs/codex/snapshots/<id> ("Codex worktree snapshot: …") and the worktree is deleted; it can be restored.
Count-based cleanup keeps pinned and in-progress threads' worktrees and deletes at most 20 per run.
Proposal
Host owns ownership. A worktree is in use while any unarchived session's cwd is inside it. The host computes this; archived_worktree_branches and the UI-side check go away.
On archive finalisation (after the 60 s window from Archive: align with the Codex app (log move, provider-native archive, undo) #529): if another unarchived thread uses the worktree (a fork, or a thread started in an existing worktree), transfer the worktree ownership field to it. Otherwise snapshot uncommitted state to refs/tcode/snapshots/<id>, remove the worktree, keep the tcode/<id> branch.
Keep-count. Keep the most recent 15 archived worktrees on disk (setting), cleaning older ones with the same snapshot step.
Unarchive recreates the worktree from the branch and restores the snapshot.
Delete honours "keep worktree" with an explicit keep record; the orphan sweep treats any session cwd inside ~/.tcode/worktrees, any pending-cleanup entry and any keep record as known.
Related work
guivieiras/tcode has unmerged work that makes shared worktrees common: reusing existing worktrees from the workspace selector (241616d) and named worktrees with a chosen base branch (8556ded). The ownership model above has to cover threads that join an existing worktree.
Summary
Move worktree ownership to the host and give archived threads a Codex-style worktree lifecycle: deferred cleanup, snapshot before removal, ownership transfer, keep-count.
Tcode today
git worktree remove --force(branchtcode/<id>kept, uncommitted work lost;crates/services/src/worktree.rs).worktree_orphaned_by_delete,crates/ui/src/store/mod.rs) and ignores forks, which share the cwd without owningworktree(Removing a deleted thread's worktree also deletes its forks' working directory #517).Codex app behaviour
[desktop] worktree-auto-cleanup-enabled(default on),worktree-keep-count(default 15).refs/codex/snapshots/<id>("Codex worktree snapshot: …") and the worktree is deleted; it can be restored.Proposal
archived_worktree_branchesand the UI-side check go away.worktreeownership field to it. Otherwise snapshot uncommitted state torefs/tcode/snapshots/<id>, remove the worktree, keep thetcode/<id>branch.~/.tcode/worktrees, any pending-cleanup entry and any keep record as known.Related work
guivieiras/tcode has unmerged work that makes shared worktrees common: reusing existing worktrees from the workspace selector (241616d) and named worktrees with a chosen base branch (8556ded). The ownership model above has to cover threads that join an existing worktree.