Skip to content

feat(hooks): base new worktrees on next#402

Merged
blafourcade merged 1 commit into
nextfrom
chore/worktree-next-base
Jul 7, 2026
Merged

feat(hooks): base new worktrees on next#402
blafourcade merged 1 commit into
nextfrom
chore/worktree-next-base

Conversation

@blafourcade

@blafourcade blafourcade commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🎯 What & why

New worktrees created by Claude Code branched from the repo default (origin/HEAD = main). Day-to-day work targets next, so worktrees should start there. This adds a WorktreeCreate hook that bases every new worktree on next, falling back to main when next is absent.

🛠️ How it works

Claude Code's WorktreeCreate hook replaces the default git 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 (else main), then git 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 .name is documented as hook input, so no speculative field parsing. Base is the local next branch (not origin/next) to keep it simple; call out if fresh-from-origin is wanted.

🧪 How to verify

  • claude --worktree probe from repo root
  • git -C .claude/worktrees/probe log --oneline -1 → matches next tip
  • git -C .claude/worktrees/probe branch --show-currentworktree-probe

⚠️ Heads-up

Not yet exercised by a real claude --worktree run — logic tested only in throwaway repos. The .name input key is from docs, not observed live; if the worktree lands empty, the payload key differs and the script needs adjusting.

✅ I certify

  • I DO CERTIFY I READ EACH LINE OF THE PULL REQUEST BECAUSE I AM A SOFTWARE ENGINEER, NOT A AI PUPPY.

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 blafourcade merged commit a40c288 into next Jul 7, 2026
7 checks passed
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>
@aidd-bot aidd-bot Bot mentioned this pull request Jul 10, 2026
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.

1 participant