Skip to content

Removing an external worktree leaves its T3 thread unable to start #38964

Done

Description

@Qnt

What happened

I asked the agent to check out the PR branch in the main project folder so I could inspect the diff. The agent moved the uncommitted changes there and removed the temporary worktree. The changes were still present in the main checkout, but every subsequent message in the original thread failed before the agent started. I expected to be able to point the same thread at the new checkout without losing its history.

Diagnosis

Before the checkout, the thread was bound to a manually created worktree outside T3's managed worktree directory. Removing it with Git did not update the saved worktreePath. In v0.1.10, restoreMissingWorktree skips unmanaged paths, and ProviderSessionManager.open rejects the missing working directory. A recovery action to select an existing checkout, including the project root, would let users keep the same thread without silently running it in a different directory.

Steps to reproduce

  1. In a disposable repo, start a project thread. Create a linked Git worktree outside T3's managed worktrees directory, with its own local branch.
  2. Select that branch in T3 and verify the thread is bound to the external worktree.
  3. When the thread is idle and that worktree is clean, run git -C <external-worktree> switch --detach, check out the same branch in the main project checkout, then run git -C <project-root> worktree remove <external-worktree>.
  4. Send another message in the same thread. It still points to the old path and fails before the provider starts.

These steps are reduced from the observed incident and source; they were not replayed in a fresh install.

Version

T3 Code server 0.1.10 (confirmed). Desktop 0.1.10 is the client that initiated triage.

Environment

Windows desktop; local Linux x64 server under WSL2; Claude provider; Git 2.56.1; Node v26.13.1 in triage diagnostics.

Evidence

05:30:12 UTC  thread.metadata-updated: worktreePath = <external-worktree>
05:30:52 UTC  git worktree remove completed; the branch and local changes were in the main checkout
05:32:06 UTC  ProviderWorkspaceMissingError: This thread's workspace folder no longer exists or is not a directory: <external-worktree>. Restore the folder at this path before retrying.
05:32:15 UTC  Retrying a simple message fails with the same error.

Related issues

#29062 covers the incorrect Initialize Git action after removal of a managed worktree. #36415 covers a PR branch that remains checked out in a worktree. Neither covers rebinding a thread after its external worktree has been removed.

Fix applied or workaround

Not applied. Recreate a detached Git worktree at the original path long enough to make the branch picker available. Select the branch already checked out in the project root and verify the thread's workspace before removing the temporary worktree. The uncommitted changes can stay in the main checkout.

Filed by

OpenCode (lab/gpt-6.2-sol), via T3 triage

Activity

  1. added
    via-triage
    on Nov 19, 2026
  2. paveltar commented on Nov 20, 2026

    @paveltar

    Same failure on macOS, with a few details that widen the scope.

    Environment: macOS 27.2 (arm64), T3 Code Desktop 0.1.10 with its local 0.1.10 server, Claude provider (claude-opus-5-5).

    What happened: The thread was bound to a Git worktree that Claude Code created (<repo>/.claude/worktrees/dev), outside T3's managed worktrees directory. I asked the agent to delete the worktree, check out the branch in the main checkout, and move the thread there. It removed the worktree and checked out the branch, then reported that it could not rebind the thread: "T3 still lists it as attached to the deleted worktree path, and none of my tools can change a thread's folder." The next message failed 1.5 s after it was sent, before the provider started:

    Provider session failed to open
    This thread's workspace folder no longer exists or is not a directory: <repo>/.claude/worktrees/dev. Restore the folder at this path before retrying.
    

    Additional findings

    1. Side chats inherit the dead path. A side chat forked from the broken thread a few seconds later (lineage.sideChat: true, forkedFrom.type: run) got the same worktreePath and its first message ("test") failed with the same error. So a fork is not a way out either.
    2. Every thread on that worktree breaks at once. 35 non-deleted threads (parent, side chats, subagents and delegated tasks) still have worktreePath = <repo>/.claude/worktrees/dev.
    3. The branch picker cannot help while the folder is missing. It lists refs with cwd set to the thread's worktree path, and the server trace shows GitCommandError: ... headPath (<repo>/.claude/worktrees/dev): Failed to spawn Git process. The environment mode selector is locked once a thread has messages, so there is no UI path back to the project root.
    4. The agent cannot do it either. t3_worktree_handoff only moves a thread into a new managed worktree. No MCP tool can set a thread's folder to the project root or an existing checkout (as [Bug]: Agents can't move a thread out of its workspace before deleting it, so the thread becomes unusable #36151 described before it was closed as a feature request).

    Timeline (UTC, 2026-11-19)

    15:20:09  run 51: user asks to delete the worktree, check out the branch in the main checkout, and move the thread
    15:21:28  run 51 completed: worktree removed, branch checked out in main, agent says it cannot rebind the thread
    15:29:03  side chat forked from the thread; run 1 failed 15:29:05, ProviderWorkspaceMissingError
    15:29:18  run 52 on the original thread failed 15:29:19, ProviderWorkspaceMissingError
    

    Workaround confirmed from source (v0.1.10): resolveBranchSelectionTarget sets nextWorktreePath to null when the picked branch is checked out in the project's own checkout. So: recreate a throwaway worktree at the old path (git worktree add --detach <old-path>) so the picker can list refs, pick the branch checked out in the main checkout, then remove the temporary worktree.

    Suggestion: besides a "Move to project root" recovery action on the error, it would help if t3_worktree_status or the tool docs told agents that deleting the thread's own worktree leaves the thread (and every fork of it) unusable, so they stop and ask first.

  3. juliusmarminge commented on Dec 2, 2026

    @juliusmarminge
    Member

    Fixed by #47234, now on main: After removing an external worktree, use Choose folder in the missing-workspace warning to select the existing project checkout, then send another message in the same thread with its conversation and link preserved.

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

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions