No supported way to configure a custom branch name for worktrees #10
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lz/agent-nexus#10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
No supported way to configure a custom branch name for worktrees
Summary
When using
--worktree, Claude Code always creates a branch namedworktree-<name>. There is no built-in option to change this prefix oruse a different naming convention (e.g.
feature/<name>,claude/<name>,or just
<name>with no prefix). This conflicts with team branch namingconventions and produces noisy branch names in pull requests and code review
tools.
Expected behaviour
A configuration option such as
worktreeBranchPrefixinsettings.jsonshould allow setting an arbitrary prefix (or an empty string to use the
worktree name directly):
So
claude --worktree add-dark-modewould create branchfeature/add-dark-modeinstead of
worktree-add-dark-mode.Current workaround and its problems
The only current workaround is a
WorktreeCreatehook that replaces the defaultgit logic entirely and applies a custom branch name. This works for creation, but
introduces a correctness problem in the paired
WorktreeRemovehook:WorktreeCreatecreates the branch as e.g.feature/add-dark-mode.claude/worktrees/add-dark-mode/WorktreeRemovereceives onlyworktree_pathin its JSON payload —there is no
branch_namefielde.g.
worktree-$(basename "$WORKTREE_PATH")— which is wrong the momentany custom prefix is used
The result is that
WorktreeRemovesilently fails to delete the branch.The worktree directory is removed but the branch is left behind, requiring
manual cleanup with
git branch -D.A reliable workaround requires writing the branch name into a sentinel file
(
.claude-worktree-branch) inside the worktree at creation time and readingit back at removal time — which is fragile and should not be necessary.
Here is the full hook script that demonstrates the problem and the sentinel
file workaround:
Proposed fix
Either:
Add a
worktreeBranchPrefix(orworktreeBranchName) setting thatcontrols what branch name the built-in logic uses, without requiring a
full hook replacement; or
Include
branch_namein theWorktreeRemovehook payload alongsideworktree_path, so hooks that customise branch naming can clean upcorrectly without resorting to sentinel files or fragile path inference.
Option 2 is a low-effort fix that unblocks the hook-based workaround
immediately, even before a first-class config option is added.
Environment
--worktreesupport, v2.1.50+)I would distribute the script or an adaptation of it outside of the
.claudedirectory within the worker image.