Skip to content

Merged-worktree cleanup skips worktrees whose branch was renamed #16559

Description

@elmarbeckmann

Summary

The "Delete merged worktrees" cleanup rule never removes a worktree when the thread's branch is renamed after T3 Code creates it. A common case is an agent that renames the generated t3code/... branch to a ticket branch name before it opens the PR.

Steps to reproduce

  1. Turn on Settings → Storage cleanup → Delete merged worktrees.
  2. Start a thread in a new worktree. T3 Code creates a branch such as t3code/revert-login-screen.
  3. In the worktree, rename the branch, for example git branch -m feature/ABC-123-remove-login-theme.
  4. Open a PR from the renamed branch and merge it into the default branch.
  5. Leave the thread idle and wait for the storage cleanup sweep.

Expected result

The cleanup sweep removes the worktree, because its PR is merged and its commits are in the default branch.

Actual result

The worktree stays. StorageCleanup.cleanWorktrees runs and exits with success, but it removes nothing.

Cause

The thread projection keeps the original branch name (thread.branch = "t3code/revert-login-screen"). It does not update after the rename. cleanWorktrees then exits early on this check:

const status = yield* git.statusDetailsLocal(worktreePath);
if (!status.isRepo || status.branch !== thread.branch || status.hasWorkingTreeChanges) return;

The same mismatch also makes gitManager.branchPullRequest look up the PR for the old branch name. That lookup cannot find the merged PR either.

Suggested fix

Update thread.branch when the branch checked out in the thread's worktree changes. Or, in cleanup, use the branch that is checked out in the worktree when it differs from the recorded branch.

Environment

  • T3 Code 0.0.46-nightly.20261005.2702
  • macOS

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

    bugSomething is broken or behaving incorrectly.via-triageFiled through npx t3 triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions