Skip to content

Feat/custom worktree branch name - #6428

Closed
MrSimmmons wants to merge 9 commits into
pingdotgg:mainfrom
MrSimmmons:feat/custom-worktree-branch-name
Closed

MrSimmmons wants to merge 9 commits into
pingdotgg:mainfrom
MrSimmmons:feat/custom-worktree-branch-name

Conversation

@MrSimmmons

@MrSimmmons MrSimmmons commented Aug 13, 2026 •

Copy link
Copy Markdown

What Changed

Allows the setting of a custom branch name when creating a new worktree from a new thread

Why

Fixes #6421, also adds a workflow / fixes a potential bug for #3044, #5359 #5734 and #967

Was initially developed on top of #6427 to round out some worktree features I found missing when comparing to other apps like VS Code, but its a pretty good stand alone feature addition so this gets its own PR

UI Changes

Before:
Screenshot 2026-08-13 at 4 03 25 PM

After:
Screenshot 2026-08-13 at 2 33 01 PM
Screenshot 2026-08-13 at 2 33 26 PM

Happy to make changes to the UI if the idea seems sound :D

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes

Note

Medium Risk
Touches first-message worktree creation and send gating; incorrect collision logic or stale async checks could block sends or allow invalid branch names, though server-side git would still reject duplicates.

Overview
Adds an optional custom branch name field in the composer context strip when starting a new thread in New worktree mode (before the first send, no existing worktree). The name is sanitized as you type, persisted on the draft (worktreeBranchName), and used in prepareWorktree.branch instead of the random t3code/… temporary name when it passes validation.

Conflict checks call listRefs with a new queryMode: "collision" on the Git VCS driver, which returns local refs that would collide with the typed name (exact match, parent, or child under Git’s ref rules—not substring search). The input shows inline errors and blocks send while the check is in flight or if a collision is found; ChatView mirrors those gates with thread errors.

Supporting changes: sanitizeWorktreeBranchNameInput / normalizeWorktreeBranchName in shared git helpers (with tests), queryMode on VcsListRefsInput, and minor toolbar layout tweaks (shrink / flex-auto) so the new control fits beside existing selectors.

Reviewed by Cursor Bugbot for commit 64bb942. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add custom worktree branch name input with collision validation

  • Users can now type and validate a custom branch name when creating a worktree from a draft thread, via the new BranchToolbarWorktreeNameInput component rendered inside BranchToolbar
  • Input is sanitized per-keystroke with sanitizeWorktreeBranchNameInput and normalized with normalizeWorktreeBranchName to comply with Git ref rules
  • Adds a collision query mode to listRefs (VcsListRefsInput) backed by the new refCollidesWithName helper in GitVcsDriverCore, returning only refs that would collide with the given name
  • ChatView defers sends while validation is in-flight, blocks sends on collisions, and skips LLM-based branch naming when a custom name is used
  • The typed name persists in the draft session via a new worktreeBranchName field in composerDraftStore
  • Risk: filterBranchesForListQuery now accepts an optional queryMode parameter; callers that omit it retain the existing substring behavior, but any out-of-tree consumers of VcsListRefsInput should be aware of the new optional field
📊 Macroscope summarized 64bb942. 5 files reviewed, 3 issues evaluated, 3 issues filtered, 0 comments posted

🗂️ Filtered Issues

apps/web/src/components/BranchToolbarWorktreeNameInput.tsx — 0 comments posted, 2 evaluated, 2 filtered
  • line 42: normalizeWorktreeBranchName leaves the special branch name HEAD unchanged, so the collision query can report it as available and the send path uses it for git worktree add -b. Git rejects HEAD as a branch name, meaning typing HEAD passes the new validation but causes worktree creation to fail. [ Already posted ]
  • line 67: A failed listRefs lookup is treated as checked and therefore produces the available state at lines 65-78. If the lookup failed while a local branch with the requested name already exists, the send path accepts that status and attempts git worktree add -b; Git then rejects the colliding ref, so the UI shows the name as available but the first send fails instead of asking the user to retry validation or choose another name. [ Already posted ]
apps/web/src/components/ChatView.tsx — 0 comments posted, 1 evaluated, 1 filtered
  • line 5622: The send gate only validates a custom name when worktreeBranchNameStatus is truthy. Immediately after entering a name (before the input's effect publishes its checking status), draftWorktreeBranchName is non-null but the status is still null, so the send proceeds and line 5879 falls back to a generated branch. Thus a user can submit a first worktree message quickly and silently lose the requested custom branch name instead of waiting for validation. [ Already posted ]

@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2cc47715-6bfe-4b5c-9600-d673bbab0266

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 13, 2026
Comment thread apps/web/src/composerDraftStore.ts Resolved
// A custom name skips the server's LLM branch naming:
// only temporary-pattern branches get renamed.
branch:
customWorktreeBranchName ?? buildTemporaryWorktreeBranchName(randomHex),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟠 High components/ChatView.tsx:5248

customWorktreeBranchName can pass Git-invalid names such as feature.lock or foo.lock/bar to prepareWorktree.branch, so the conflict check passes and the first send fails during worktree creation. Validate the final branch name against Git's full ref-format rules, including slash-separated components ending in .lock, before dispatching it.

Also found in 1 other location(s)

packages/shared/src/git.ts:133

normalizeWorktreeBranchName can return names Git rejects because it never removes or rejects a slash-separated component ending in .lock (for example, feature.lock or team.lock/topic). Git's ref-format rules explicitly forbid such components. The conflict query will not flag a nonexistent invalid ref, so send proceeds with this custom name and worktree/branch creation fails instead of creating the new thread.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/ChatView.tsx around line 5248:

`customWorktreeBranchName` can pass Git-invalid names such as `feature.lock` or `foo.lock/bar` to `prepareWorktree.branch`, so the conflict check passes and the first send fails during worktree creation. Validate the final branch name against Git's full ref-format rules, including slash-separated components ending in `.lock`, before dispatching it.

Also found in 1 other location(s):
- packages/shared/src/git.ts:133 -- `normalizeWorktreeBranchName` can return names Git rejects because it never removes or rejects a slash-separated component ending in `.lock` (for example, `feature.lock` or `team.lock/topic`). Git's ref-format rules explicitly forbid such components. The conflict query will not flag a nonexistent invalid ref, so send proceeds with this custom name and worktree/branch creation fails instead of creating the new thread.

Comment thread apps/web/src/composerDraftStore.ts Resolved
Comment thread packages/shared/src/git.ts Resolved
@macroscopeapp

macroscopeapp Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a new custom worktree-branch workflow spanning the composer UI, persisted drafts, shared Git helpers, RPC contracts, and server-side worktree creation. Its asynchronous validation and unresolved risks around Git-invalid names, case/path collisions, and mobile layout behavior require human review.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@MrSimmmons
MrSimmmons force-pushed the feat/custom-worktree-branch-name branch from 85e8859 to efd6128 Compare August 18, 2026 02:42

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three consistency issues in the new BranchToolbarWorktreeNameInput control, all within the composer context strip it joins.

Posted via Macroscope — UI Consistency

listRefs matches the query as a substring and pages the result, so an
exact branch could fall off a 20-ref page and the gate would report the
name as available. Ask for local refs only at the schema's max page size,
and export that ceiling so the two stay in step.

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One finding: the new worktree-name input is rendered as a direct child of the context strip in the mobile layout, where useLabelsOverflow's width accounting only sums a child's children, so the field's width is invisible to the compact/expand heuristic.

Posted via Macroscope — UI Consistency

previousWorktreeLabel={previousWorktreeLabel}
onUsePreviousWorktree={onUsePreviousWorktree}
/>
{worktreeNameInput}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the mobile branch this input becomes a direct child of the strip, but useLabelsOverflow treats every direct child as a group and measures it with contentWidth(child), which sums child.children. An <input> has no element children, so it contributes 0 to needed (only the extra 8px strip gap is counted) even though it occupies up to w-44 (176px).

Because the same undercount applies in both directions, the expand test in compact mode (needed > available - 16) can conclude the expanded layout fits when it doesn't: the strip expands, the branch label then clips, needed > available fires, and it flips back to compact — a flap loop with FLIP animations at widths where the field is the deciding factor. In the desktop branch the input sits inside the flex min-w-0 flex-1 group div and is measured correctly, so only the mobile path is affected.

Smallest fix: give the mobile pair the same group container the desktop layout uses, e.g. wrap MobileRunContextSelector and {worktreeNameInput} in <div className="flex min-w-0 items-center gap-2"> (same gap the strip uses, so spacing is unchanged). Alternatively, have contentWidth fall back to the child's own offsetWidth when it has no element children.

Posted via Macroscope — UI Consistency

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 64bb942. Configure here.

*/
function refCollidesWithName(refName: string, name: string): boolean {
return refName === name || refName.startsWith(`${name}/`) || name.startsWith(`${refName}/`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Collision check ignores letter case

Medium Severity

refCollidesWithName compares refs with case-sensitive equality and prefix checks. Sibling helpers in the same package already treat branch collisions as case-insensitive, and git with core.ignorecase (default on macOS and Windows) refuses a new branch that differs from an existing one only by case. The input can mark a name available and the send path will proceed, then git worktree add -b fails.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 64bb942. Configure here.

const checked =
deferredNormalizedValue === normalizedValue &&
(conflictRefsQuery.data !== null || conflictRefsQuery.error !== null);
const conflict = checked && (conflictRefsQuery.data?.totalCount ?? 0) > 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slash and dash names share paths

Medium Severity

The new collision check only compares git ref hierarchy, but createWorktree turns every / in the branch name into - for the worktree directory. Names such as feat/foo and feat-foo are treated as available even when they map to the same path, so the second create fails after the UI has already cleared the name for send.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 64bb942. Configure here.

@t3dotgg

t3dotgg commented Aug 28, 2026

Copy link
Copy Markdown
Member

Note

🤖 GPT-5.6 Sol responding on behalf of Theo

We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

This adds custom worktree branch names across server, contracts, web, and mobile. We are not adding this new worktree naming path through the current backlog.

If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

@t3dotgg t3dotgg closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Fully custom branch name when starting a new worktree thread

2 participants