[FEATURE] worktree.branchPrefix setting — worktree branch names are hardcoded to worktree-<name>

Status Open
Reported on v2.1.267
Maintainer reply None cached
Activity 2 comments · opened Sep 10, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Worktree branch names are hardcoded and there is no setting for them. The shipped v2.1.267 bundle derives the branch name as:

function yUn(e){ return e.replaceAll("/","+") }
function Kfe(e){ return `worktree-${yUn(e)}` }

which matches the observed behavior: claude --worktree feature-auth creates branch worktree-feature-auth, and slashes in the name are rewritten to +.

Teams with a branch-naming convention can't use the built-in worktree support without renaming the branch after every creation. Our repo's convention is feat/<slug>, so every Claude-created worktree has to be followed by git switch -c feat/<slug> before the first commit — a step we documented in our CLAUDE.md purely to work around the prefix. Forget it once and the work lands on a branch CI and our MR tooling don't recognize, plus the original worktree-* branch is left behind.

No such setting exists: neither worktreeBranchPrefix nor worktree.branchPrefix appears anywhere in the settings schema.

Proposed Solution

Add one key to the worktree settings object that already exists:

{
  "worktree": {
    "branchPrefix": "feat/"
  }
}
  • Default "worktree-", i.e. no behavior change for anyone who doesn't set it.
  • "" produces the worktree name verbatim.
  • Applies to --worktree, EnterWorktree, and Agent with isolation: "worktree" — the same surfaces worktree.baseRef already covers.
  • The / → + substitution should not apply to the prefix, so "claude/" yields claude/feature-auth, not claude+feature-auth. (How slashes inside the name are handled is a separate matter; this request doesn't touch it.)

Why this is a one-key change, and why the earlier requests aren't a reason to close it

The worktree settings object already exists in v2.1.267, carrying symlinkDirectories, sparsePaths, baseRef (fresh|head), bgIsolation (worktree|none) and location. So this is no longer "add a configuration surface for worktrees" — it's one more key beside baseRef, with the same scope and the same consumers. That wasn't true when the earlier requests were filed.

Every earlier dedicated request for this was closed by automation rather than on merit:

  • #42365 — closed not planned by the stale bot, with no maintainer response
  • #67384 — flagged duplicate, then closed by the stale bot
  • #25902, #28761, #62309 — closed stale or superseded

And the two open issues that touch branch naming don't cover this ask:

  • #31969 bundles three separate requests (resume-existing-worktree, branch naming, hook removal control). Its own author notes the earlier attempts were "either closed due to inactivity or mixed with separate concerns", which is what happened to the branch-naming half here too.
  • #85998 asks for something mechanically different: inferring the convention from CLAUDE.md. That's a heuristic read of prose; this is an explicit settings key with a defined default. The two are complementary, not duplicates.

Alternative Solutions

  • WorktreeCreate + WorktreeRemove hooks. Works today, but it's a heavy trade for a naming prefix: configuring WorktreeCreate also disables Claude Code's own worktree removal, so WorktreeRemove has to be reimplemented, and auto-cleanup plus the resume / reset-to-fresh-base handling has to be replicated. It's also imperative config that has to win against whatever else a repo loads, where a declarative setting simply applies.
  • Rename after the fact (git switch -c <name>) — what we do now. Easy to forget before the first commit, and it leaves the auto-created branch behind.
  • Desktop parity — #42365 reported that the desktop app exposes a branch-prefix setting in its UI while the CLI has no equivalent. If that's still accurate, this would close the gap.

Feature Area

Configuration and settings

Use Case Example

  1. Repo convention is feat/<slug>; CI rules and our MR tooling key off that prefix.
  2. claude --worktree license-badge creates branch worktree-license-badge.
  3. Before the first commit I have to git switch -c feat/license-badge, leaving worktree-license-badge dangling.
  4. With worktree.branchPrefix: "feat/" the branch is feat/license-badge at creation time, and the built-in worktree lifecycle (auto-cleanup, base-ref handling, resume) stays intact.

Additional Context

  • Version 2.1.267, Windows 11, CLI.
  • Branch-naming behavior above was read out of the shipped bundle and matches what we see in practice; the same worktree-<name> prefix is reported in #67384 and #62309.
  • The + substitution in yUn is what #47439 ran into when a worktree name contained a slash.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗