feat(hooks): base new worktrees on next#402
Merged
Merged
Conversation
Add a WorktreeCreate hook so every worktree Claude Code creates branches from `next` (falling back to `main` when `next` is absent) instead of the repo default. Registered in .claude/settings.json. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
blafourcade
added a commit
that referenced
this pull request
Jul 10, 2026
Add a WorktreeCreate hook so every worktree Claude Code creates branches from `next` (falling back to `main` when `next` is absent) instead of the repo default. Registered in .claude/settings.json. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 What & why
New worktrees created by Claude Code branched from the repo default (
origin/HEAD=main). Day-to-day work targetsnext, so worktrees should start there. This adds aWorktreeCreatehook that bases every new worktree onnext, falling back tomainwhennextis absent.🛠️ How it works
Claude Code's
WorktreeCreatehook replaces the defaultgit worktree add: it reads{ name }on stdin and must print the created worktree path on stdout..claude/hooks/worktree-create.js does exactly that — picks
next(elsemain), thengit worktree add <root>/.claude/worktrees/<name> -b worktree-<name> <base>, and prints the path. git's own output goes to stderr so stdout stays the path only. .claude/settings.json registers it.Kept deliberately minimal: only
.nameis documented as hook input, so no speculative field parsing. Base is the localnextbranch (notorigin/next) to keep it simple; call out if fresh-from-origin is wanted.🧪 How to verify
claude --worktree probefrom repo rootgit -C .claude/worktrees/probe log --oneline -1→ matchesnexttipgit -C .claude/worktrees/probe branch --show-current→worktree-probeNot yet exercised by a real
claude --worktreerun — logic tested only in throwaway repos. The.nameinput key is from docs, not observed live; if the worktree lands empty, the payload key differs and the script needs adjusting.✅ I certify