Skip to content

feat: continue an existing local or remote branch in a new worktree - #85

Merged
Fryuni merged 5 commits into
mainfrom
fryuni/reuse-remote-branch-worktree
Nov 4, 2026
Merged

Fryuni merged 5 commits into
mainfrom
fryuni/reuse-remote-branch-worktree

Conversation

@Fryuni

@Fryuni Fryuni commented Nov 4, 2026

Copy link
Copy Markdown
Owner

A branch that was only on the remote, such as one pushed from another device, could not be continued in a new worktree. New worktree always created a second branch from it. Turning off the Create new branch switch (hidden in the branch picker) allowed only local branches, so remote refs were greyed out. The two choices lived in different selectors.

What changed

  • One Workspace selector picks the mode. It now offers Current checkout, New worktree (new branch from a base), Check out in worktree (the branch itself), and Previous worktree. The Create new branch switch is gone. Mobile's workspace chip cycles through the same three modes. Check out in worktree is hidden for servers without existingBranchWorktree and during multi-model fan-out.
  • Remote branches can be checked out. In Check out in worktree, a remote ref like origin/feature can be selected. ThreadLaunchService fetches that branch, creates a local feature tracking it, and checks it out. A local feature that already tracks it is reused without a fetch. A local feature that tracks something else is refused before the thread exists. A remote branch deleted since the last fetch fails preparation instead of being revived from the stale tracking ref. Retries resolve to the branch the first attempt created.
  • Docs: ADR 0008/0009 rewritten for the new choice, and the user guide is updated. The t3_thread_launch tool description is unchanged because changing it needs a paid mcp-tool-use eval run. Agents can still pass remote refs (noted in the ADR).

Screenshots

Before After
Before: workspace menu with only Current checkout and New worktree After: workspace menu with Current checkout, New worktree, Check out in worktree, Previous worktree
Before: Create new branch switched off, every ref including the remote-only one disabled After: Check out in worktree, the remote-only origin/feature/pushed-elsewhere is selectable

Narrow composer menu: Narrow workspace menu with Check out in worktree

Verification

  • vp run check:changed: format, lint, knip, typecheck, react compiler, and unit tests pass. The browser test runner can't start on this machine (missing libglib for headless Chromium), so CI covers those.
  • New and extended ThreadLaunchService tests cover: a remote-only ref creating a tracking branch, reuse of an existing tracking branch (including the listRefs origin dedupe), refusal of an unrelated same-named local branch, missing refs, and a remote branch deleted since the last fetch.
  • Live run against a fixture repo with a bare remote. With Check out in worktree selected, origin/feature/from-other-device produced a worktree on local feature/from-other-device tracking origin, at a commit pushed after the last local fetch. origin/feature/second worked the same way after the refs/remotes/... start-point fix.
  • Reviewed over 3 rounds by GPT 6.1 Sol reviewers (Codex, high reasoning), sliced by server, clients, mobile, and fit/docs. All reviewers were CONFIDENT in the final round.

Implemented by Claude Opus 5.5 in Claude Code (T3 Code), reviewed by GPT 6.1 Sol via Codex.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 4, 2026 05:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T05:13:47.132516Z a04c8a7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change enabling existing local or remote branches to be checked out in a new worktree.

No open issues 🎉

What changed in this PR

This PR lets users continue an existing local or remote branch in a new worktree through T3 Code’s web, desktop, and mobile clients, without creating a second branch.

Changes:

  • Adds Check out in worktree to workspace selection and removes the branch-picker toggle.
  • Resolves remote refs to local tracking branches, reuses matching local branches, and rejects conflicting branches or deleted remote refs.
  • Extends server and shared-state tests and updates user guidance and architectural decisions.
File Description
packages/​contracts/​src/​orchestrationV2.ts Documents remote refs in existing-branch checkout mode.
packages/​client-runtime/​src/​state/​vcsRef.ts Allows remote refs as checkout candidates.
packages/​client-runtime/​src/​state/​vcsRef.test.ts Updates checkout eligibility tests for remote refs.
docs/​user/​thread-sidebar.md Explains workspace choices and branch-fetch behavior.
docs/​adr/​0009-choose-where-new-worktrees-start.md Updates terminology for default-branch selection.
docs/​adr/​0008-start-threads-on-existing-branches.md Records workspace selection and remote-checkout decisions.
apps/​web/​src/​components/​BranchToolbarEnvModeSelector.tsx Adds the existing-branch workspace option.
apps/​web/​src/​components/​BranchToolbarBranchSelector.tsx Removes wiring for the old branch-creation toggle.
apps/​web/​src/​components/​BranchToolbar.tsx Connects workspace choices to mode and branch-creation state.
apps/​web/​src/​components/​BranchToolbar.logic.ts Adds workspace-choice types and labels.
apps/​web/​src/​components/​BranchPicker.tsx Removes the branch-creation toggle UI.
apps/​server/​src/​orchestration-v2/​ThreadLaunchService.ts Resolves, validates, and prepares local or remote branch checkouts.
apps/​server/​src/​orchestration-v2/​ThreadLaunchService.test.ts Covers remote checkout, tracking reuse, conflicts, and deleted refs.
apps/​server/​src/​mcp/​toolkits/​project/​handlers.test.ts Updates expected workspace-error wording.
apps/​mobile/​src/​features/​threads/​NewTaskDraftScreen.tsx Cycles workspace choices and updates accessible labels.
apps/​mobile/​src/​features/​threads/​NewTaskContextPickerScreens.tsx Removes the toggle and explains remote-branch checkout.
apps/​mobile/​src/​features/​threads/​new-task-flow-provider.tsx Combines workspace and branch-creation selection updates.
apps/​mobile/​src/​features/​threads/​new-task-context-presentation.ts Adds capability-aware workspace cycling and labels.

Review effort: Balanced

@fryuni-proval

fryuni-proval Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thanks for making the workspace choices clearer across web, desktop, and mobile, and extending existing-branch checkout to remote refs.

Overview

Summary

This change separates new-branch worktrees from existing-branch checkouts in the workspace controls. The server resolves remote selections to local tracking branches, rejects conflicting or occupied branches, and fetches before first-time remote checkout.

Good points

🟢 The deleted-remote regression test checks the failed run, fetch-stage detail, user-visible error, and absence of worktree creation (apps/server/src/orchestration-v2/ThreadLaunchService.test.ts:1645), guarding against restoring a deleted branch from a stale tracking ref.
🟢 Responsive and panel workspace controls share onWorkspaceChoiceChange, while fan-out forces new-branch creation (apps/web/src/components/BranchToolbar.tsx:652–658), keeping the different presentations aligned.
🟢 Mobile resolves the branch using the next creation mode and saves both in one workspace-selection update (apps/mobile/src/features/threads/new-task-flow-provider.tsx:663–678), preserving eligible remote selections without mismatching the draft's checkout strategy.

Main Issues

No blocking issues found in the verified review candidates. Recommend merging.

Verification was by code inspection; tests were not run during this review.

@fryuni-proval

fryuni-proval Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thanks for making the workspace choices more explicit across web, desktop, and mobile while preserving the existing launch model.

Overview

Summary

This change separates new-branch worktrees from existing-branch checkouts in the workspace controls and adds server-side resolution of remote selections to local tracking branches. The clients continue to use the existing workspace mode and branch-creation fields rather than introducing another launch strategy.

Good points

🟢 apps/server/src/orchestration-v2/ThreadLaunchService.ts:302 rejects same-named local branches with a different upstream, while the admission check at line 333 rejects occupied branches, preventing remote selections from silently landing on unrelated or already-checked-out work.
🟢 apps/web/src/components/BranchToolbar.tsx:656 centralizes workspace-choice transitions in one adapter shared by the panel, compact menu, and wide selector, keeping web and desktop entry points consistent.
🟢 apps/mobile/src/features/threads/new-task-flow-provider.tsx:667 evaluates branch retention against the destination branch-creation choice and persists both choices together, keeping the draft aligned with the selected workspace.

Main Issues

None found in the reviewed candidates. Ready to merge from this review.

Additional Notes

Tests were not executed; verification used the PR diffs and targeted reads of the current code.

@Fryuni
Fryuni merged commit b3728c9 into main Nov 4, 2026
10 checks passed
@Fryuni
Fryuni deleted the fryuni/reuse-remote-branch-worktree branch November 4, 2026 05:29
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.

2 participants