Skip to content

feat(vcs): open the existing worktree that already holds a branch - #63

Merged
enisze merged 1 commit into
mainfrom
feature/open-existing-worktree-with-threads
Aug 19, 2026
Merged

enisze merged 1 commit into
mainfrom
feature/open-existing-worktree-with-threads

Conversation

@enisze

@enisze enisze commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

Reopening a branch through a worktree thread previously failed with an opaque git worktree add failed whenever git refused the add. This PR handles the cases the caller cannot fix by hand and resolves GitHub account routes through symlinks.

VCS worktree handling (GitVcsDriverCore.ts)

  • Branch already checked out in another worktree → hand that worktree (and the threads rooted at it) back instead of failing. When the claim is the main repo checkout, explain clearly that it cannot also become a worktree.
  • Derived directory is taken (a worktree kept its directory after its branch was switched) → fall back to a sibling <name>-2.
  • Stale worktree whose directory was removed behind git's back → git worktree prune and retry once.
  • All of this runs on the failure path only, so a successful add stays a single spawn.

GitHub account resolution (GitHubAccountResolver.ts)

  • Resolve account routes through symlinks: a cwd and the stored project root routinely name one directory via different symlinks (/tmp vs /private/tmp, symlinked home/worktree dirs). On a literal miss, resolve both sides' real paths (cached, TTL) before falling back to the ambient account.
  • Sharpen the token-failure warnings to reflect that commands now refuse rather than silently act as the ambient account.

Web (ChatView.tsx)

  • Preserve the previous draft when opening a review chat beside the current one, so a fresh review draft stays attached to its worktree.

Test plan

  • New GitVcsDriverCore.test.ts cases: reuse a worktree that already holds the branch, explain a branch only the requesting checkout holds, create a sibling worktree when the directory is taken, reopen a branch whose worktree directory was deleted.
  • New GitHubAccountResolver.test.ts case: resolve a cwd that reaches the workspace root through a symlink.

🤖 Generated with Claude Code

Reopening a branch through a worktree thread failed with an opaque
"git worktree add failed" whenever git refused the add. Handle the two
cases the caller cannot fix by hand:

- the branch is already checked out in another worktree — hand that
  worktree (and the threads rooted at it) back instead of failing, and
  explain clearly when the claim is the main repo checkout.
- the derived directory is taken because a worktree kept its directory
  after its branch was switched — fall back to a sibling `<name>-2`.

Prune-and-retry once for a stale worktree whose directory was removed
behind git's back. All of this runs on the failure path only, so a
successful add stays a single spawn.

Resolve GitHub account routes through symlinks: a cwd and the stored
project root routinely name one directory via different symlinks
(/tmp vs /private/tmp, symlinked home or worktree dirs). On a literal
miss, resolve both sides' real paths (cached) before falling back to
the ambient account, and sharpen the token-failure warnings.

Preserve the previous draft when opening a review chat beside the
current one, so a fresh review draft stays attached to its worktree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@enisze
enisze merged commit fe9fae9 into main Aug 19, 2026
@enisze
enisze deleted the feature/open-existing-worktree-with-threads branch August 19, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant