Skip to content

Commit 35fe53a

Browse files
committed
feat(scripts): add worktree-create hook script
- creates a git worktree under .git/worktrees/<name> - branches off origin/HEAD with the worktree name - pushes branch to remote with tracking - prints worktree path to stdout for claude code hook consumption
1 parent 1399232 commit 35fe53a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Read JSON from stdin
5+
INPUT=$(cat)
6+
7+
# Parse fields from Claude Code hook input
8+
BASE_PATH=$(echo "$INPUT" | jq -r '.cwd')
9+
WORKTREE_NAME=$(echo "$INPUT" | jq -r '.name')
10+
11+
# Worktree lives under .git/worktrees/<name>
12+
WORKTREE_PATH="$BASE_PATH/.git/worktrees/$WORKTREE_NAME"
13+
14+
cd "$BASE_PATH"
15+
16+
# Create worktree — branch name matches worktree name (no prefix)
17+
git worktree add "$WORKTREE_PATH" -b "$WORKTREE_NAME" origin/HEAD
18+
19+
# Push branch to remote with tracking
20+
git -C "$WORKTREE_PATH" push -u origin "$WORKTREE_NAME"
21+
22+
# Required: print the worktree path to stdout
23+
echo "$WORKTREE_PATH"
24+
exit 0

0 commit comments

Comments
 (0)