Skip to content

Worktrees: host-owned ownership and an archive lifecycle (snapshot, transfer, keep-count) #530

Description

@Tryanks

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

Codex app behaviour

  • [desktop] worktree-auto-cleanup-enabled (default on), worktree-keep-count (default 15).
  • 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions