| name | git-worktree |
| description | Manage git worktrees for parallel branch work. PROACTIVELY USE when user mentions working on a PR, new feature, or new task - ask if they want to create a worktree BEFORE starting implementation. |
| allowed-tools | Bash, AskUserQuestion |
| context | fork |
| agent | general-purpose |
Git Worktree Manager
Overview
| Workflow | Trigger | Scripts |
|---|
| A. Create Worktree | PR/์ ๊ธฐ๋ฅ ์์
์ธ๊ธ | create-and-open.sh |
| B-1. Bare Clone | ์ ํ๋ก์ ํธ ์ธํ
์์ฒญ | bare-clone.sh |
| B-2. Convert to Bare | bare ์ ํ ์์ฒญ | detect.sh โ convert-to-bare.sh |
| C. Cleanup | worktree ์ ๋ฆฌ ์์ฒญ | cleanup-worktree.sh |
CRITICAL: Script-Only Execution
์ ๋ git worktree/tmux ๋ช
๋ น์ด๋ฅผ ์ง์ ์คํํ์ง ๋ง์ธ์.
๋ชจ๋ ์ํฌํ๋ก์ฐ๋ ๋ฐ๋์ $PLUGIN_DIR/scripts/ ์ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด ์คํํด์ผ ํฉ๋๋ค.
์คํฌ๋ฆฝํธ๊ฐ worktree ์์ฑ, push, CLAUDE.local.md ์์ฑ, tmux ์๋์ฐ ์ด๊ธฐ๋ฅผ ๋ชจ๋ ์ฒ๋ฆฌํฉ๋๋ค.
๊ธ์ง ๋ช
๋ น์ด: git worktree add, tmux new-window, tmux split-window ๋ฑ์ ์ง์ ํธ์ถํ์ง ๋ง์ธ์.
๋ฐ๋์ ์๋ Bash ์ฝ๋๋ธ๋ก์ ๊ทธ๋๋ก ๋ณต์ฌํ์ฌ ํ๋ ์ด์คํ๋({...})๋ง ์นํ ํ ์คํํ์ธ์.
Smart Detection (Proactive Trigger)
When the user mentions any of these, skip the Workflow/Type selection and proceed directly:
| User says | Action |
|---|
| PR number (e.g., "PR #9", "work on PR 123") | โ Workflow A: PR Checkout (0 questions) |
| New feature/task (e.g., "implement auth", "add dark mode") | โ Workflow A: New Branch (3-4 questions) |
/git-worktree manual trigger | โ Workflow Selection (show menu) |
Ask BEFORE proceeding with implementation work.
Workflow Selection (Manual Trigger Only)
Only show when /git-worktree is explicitly invoked. First run the Inline Detection block below to determine WORKTREE_STYLE, then filter options:
| WORKTREE_STYLE | Available Options |
|---|
bare | Create Worktree, Cleanup, Bare Clone |
normal | Create Worktree, Convert to Bare, Cleanup, Bare Clone |
none | Bare Clone only |
Question: "์ด๋ค ์์
์ ํ์๊ฒ ์ต๋๊น?"
Header: "Workflow"
Options: (filtered by WORKTREE_STYLE)
- "Create Worktree" - PR ์ฒดํฌ์์ ๋๋ ์ ๋ธ๋์น๋ก worktree ์์ฑ
- "Convert to Bare" - ํ์ฌ repo๋ฅผ bare ๊ตฌ์กฐ๋ก ๋ณํ
- "Cleanup" - ๋ถํ์ํ worktree ์ ๊ฑฐ
- "Bare Clone" - ์ ํ๋ก์ ํธ๋ฅผ bare repo๋ก clone
To detect WORKTREE_STYLE, run this single Bash call:
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "WORKTREE_STYLE=none"
elif [ -f "$TOPLEVEL/.git" ]; then
echo "WORKTREE_STYLE=bare"
else
echo "WORKTREE_STYLE=normal"
fi
Workflow A: Create Worktree
Smart Path: PR Checkout (0 questions)
When user mentions a PR number, extract it and run this complete Bash block. Replace {NUMBER} with the actual PR number:
PLUGIN_DIR=$(find ~/.claude/plugins/cache -maxdepth 6 -path "*/git-worktree-plugin/*/scripts/create-and-open.sh" 2>/dev/null \
| sed 's|/scripts/create-and-open.sh||' \
| sort -V \
| tail -1)
if [ -z "$PLUGIN_DIR" ]; then
_SKILL_SCRIPTS=$(find ~/.agents/skills -maxdepth 4 -path "*/git-worktree/scripts/create-and-open.sh" 2>/dev/null | head -1)
[ -n "$_SKILL_SCRIPTS" ] && PLUGIN_DIR=$(dirname "$_SKILL_SCRIPTS")/..
fi
if [ -z "$PLUGIN_DIR" ]; then echo "ERROR: Plugin scripts not found" >&2; exit 1; fi
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "ERROR: Not in a git repository" >&2; exit 1
elif [ -f "$TOPLEVEL/.git" ]; then
GIT_COMMON=$(cd "$TOPLEVEL" && git rev-parse --git-common-dir)
BARE_DIR=$(cd "$TOPLEVEL" && cd "$GIT_COMMON" && pwd)
PROJECT_ROOT=$(dirname "$BARE_DIR")
WORKTREE_ROOT="$PROJECT_ROOT/trees"
else
PROJECT_ROOT="$TOPLEVEL"
WORKTREE_ROOT="$TOPLEVEL/trees"
fi
PR_INFO=$(gh pr view {NUMBER} --json title,body --jq '"PR #\(.number): \(.title)\n\n\(.body)"' 2>/dev/null || echo "PR #{NUMBER}")
bash "$PLUGIN_DIR/scripts/create-and-open.sh" \
--project-root "$PROJECT_ROOT" \
--worktree-root "$WORKTREE_ROOT" \
--pr {NUMBER} \
--tmux-name "pr-{NUMBER}" \
--context "$PR_INFO"
Smart Path: New Branch (3-4 questions)
When user mentions a new feature/task, ask 3-4 questions:
Question 1: Branch type
Question: "๋ธ๋์น ํ์
์ ์ ํํ์ธ์"
Header: "Branch"
Options:
- "feat/ (Recommended)" - ์ ๊ธฐ๋ฅ ๊ฐ๋ฐ
- "fix/" - ๋ฒ๊ทธ ์์
- "chore/" - ์ ์ง๋ณด์ ์์
- "refactor/" - ์ฝ๋ ๋ฆฌํฉํ ๋ง
Parse the selection: prefix = first word before /.
If user selects "Other", ask for custom prefix.
Question 2: Base branch
Question: "์ด๋ ๋ธ๋์น์์ ๋ถ๊ธฐํ์๊ฒ ์ต๋๊น?"
Header: "Base"
Options:
- "main (Recommended)" - main ๋ธ๋์น์ ์ต์ remote ์ํ์์ ๋ถ๊ธฐ
- "develop" - develop ๋ธ๋์น์ ์ต์ remote ์ํ์์ ๋ถ๊ธฐ
Parse the selection: base = origin/{selection}.
If user selects "Other", ask for custom base (e.g., origin/release/v2).
Question 3: Feature name
Ask user to briefly describe the feature. Format: lowercase, spaces/underscores โ dashes.
Question 4: Context interview (optional)
Question: "Worktree์์ ์์
ํ ๋ด์ฉ์ ์์ธํ ์
๋ ฅํ์๊ฒ ์ต๋๊น?"
Header: "Context"
Options:
- "์
๋ ฅํ๊ธฐ" - ํด๊ฒฐํ ๋ฌธ์ , ํ ์ผ, ์ฐธ๊ณ ์ฌํญ์ ์
๋ ฅ
- "๊ฑด๋๋ฐ๊ธฐ" - ๊ธฐ๋ณธ ์ปจํ
์คํธ๋ง ์ฌ์ฉ
If user selects "์
๋ ฅํ๊ธฐ", ask a follow-up free-text question:
"์์
์ปจํ
์คํธ๋ฅผ ์์ ๋กญ๊ฒ ์
๋ ฅํด์ฃผ์ธ์. ์์:
- ํด๊ฒฐํ ๋ฌธ์ : ๋ก๊ทธ์ธ ์ธ์
๋ง๋ฃ ์ ์๋ ๊ฐฑ์ ์ด ์ ๋จ
- ํ ์ผ: ํ ํฐ ๊ฐฑ์ ๋ก์ง ์ถ๊ฐ, ๋ฏธ๋ค์จ์ด ์์ , ํ
์คํธ ์์ฑ
- ์ฐธ๊ณ : src/auth/ ๋๋ ํ ๋ฆฌ, v2 API ํธํ ํ์"
Organize the user's response into ## Problem, ## Tasks, ## Notes sections and append to the --context parameter.
--context format when interview is completed:
Branch: {prefix}/{feature-name}, Base: origin/{base-branch}
Feature: {description}
## Problem
{organized problem description}
## Tasks
{organized task list}
## Notes
{organized notes}
--context format when skipped: same as before (Branch + Feature only).
Then run this complete Bash block. Replace {prefix}, {feature-name}, {base-branch}, {dir-name}, and {description}:
PLUGIN_DIR=$(find ~/.claude/plugins/cache -maxdepth 6 -path "*/git-worktree-plugin/*/scripts/create-and-open.sh" 2>/dev/null \
| sed 's|/scripts/create-and-open.sh||' \
| sort -V \
| tail -1)
if [ -z "$PLUGIN_DIR" ]; then
_SKILL_SCRIPTS=$(find ~/.agents/skills -maxdepth 4 -path "*/git-worktree/scripts/create-and-open.sh" 2>/dev/null | head -1)
[ -n "$_SKILL_SCRIPTS" ] && PLUGIN_DIR=$(dirname "$_SKILL_SCRIPTS")/..
fi
if [ -z "$PLUGIN_DIR" ]; then echo "ERROR: Plugin scripts not found" >&2; exit 1; fi
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "ERROR: Not in a git repository" >&2; exit 1
elif [ -f "$TOPLEVEL/.git" ]; then
GIT_COMMON=$(cd "$TOPLEVEL" && git rev-parse --git-common-dir)
BARE_DIR=$(cd "$TOPLEVEL" && cd "$GIT_COMMON" && pwd)
PROJECT_ROOT=$(dirname "$BARE_DIR")
WORKTREE_ROOT="$PROJECT_ROOT/trees"
else
PROJECT_ROOT="$TOPLEVEL"
WORKTREE_ROOT="$TOPLEVEL/trees"
fi
bash "$PLUGIN_DIR/scripts/create-and-open.sh" \
--project-root "$PROJECT_ROOT" \
--worktree-root "$WORKTREE_ROOT" \
--branch "{prefix}/{feature-name}" \
--base "origin/{base-branch}" \
--push \
--tmux-name "{dir-name}" \
--context "Branch: {prefix}/{feature-name}, Base: origin/{base-branch}
Feature: {description}"
Manual Path: Create Worktree
If reached via Workflow Selection, first ask Type (PR or New Branch), then follow the appropriate Smart Path above.
Workflow B-1: Bare Clone
Use AskUserQuestion to collect URL and path, then run this complete Bash block. Replace {URL} and {PATH}:
PLUGIN_DIR=$(find ~/.claude/plugins/cache -maxdepth 6 -path "*/git-worktree-plugin/*/scripts/create-and-open.sh" 2>/dev/null \
| sed 's|/scripts/create-and-open.sh||' \
| sort -V \
| tail -1)
if [ -z "$PLUGIN_DIR" ]; then
_SKILL_SCRIPTS=$(find ~/.agents/skills -maxdepth 4 -path "*/git-worktree/scripts/create-and-open.sh" 2>/dev/null | head -1)
[ -n "$_SKILL_SCRIPTS" ] && PLUGIN_DIR=$(dirname "$_SKILL_SCRIPTS")/..
fi
if [ -z "$PLUGIN_DIR" ]; then echo "ERROR: Plugin scripts not found" >&2; exit 1; fi
bash "$PLUGIN_DIR/scripts/bare-clone.sh" \
--url "{URL}" \
--path "{PATH}" \
--branch "main"
Workflow B-2: Convert to Bare
Step 1: Detect and confirm
Run inline detection. If WORKTREE_STYLE is already "bare", inform user it's already a bare repo.
Use AskUserQuestion:
Question: "Convert this repository to bare structure? A backup will be created at .git-backup/"
Header: "Convert"
Options:
- "Proceed" - Convert to bare (backup included)
- "Cancel" - Abort
Step 2: Execute
Run this complete Bash block:
PLUGIN_DIR=$(find ~/.claude/plugins/cache -maxdepth 6 -path "*/git-worktree-plugin/*/scripts/create-and-open.sh" 2>/dev/null \
| sed 's|/scripts/create-and-open.sh||' \
| sort -V \
| tail -1)
if [ -z "$PLUGIN_DIR" ]; then
_SKILL_SCRIPTS=$(find ~/.agents/skills -maxdepth 4 -path "*/git-worktree/scripts/create-and-open.sh" 2>/dev/null | head -1)
[ -n "$_SKILL_SCRIPTS" ] && PLUGIN_DIR=$(dirname "$_SKILL_SCRIPTS")/..
fi
if [ -z "$PLUGIN_DIR" ]; then echo "ERROR: Plugin scripts not found" >&2; exit 1; fi
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "ERROR: Not in a git repository" >&2; exit 1
elif [ -f "$TOPLEVEL/.git" ]; then
GIT_COMMON=$(cd "$TOPLEVEL" && git rev-parse --git-common-dir)
BARE_DIR=$(cd "$TOPLEVEL" && cd "$GIT_COMMON" && pwd)
PROJECT_ROOT=$(dirname "$BARE_DIR")
else
PROJECT_ROOT="$TOPLEVEL"
fi
bash "$PLUGIN_DIR/scripts/convert-to-bare.sh" --project-root "$PROJECT_ROOT"
โป Failure triggers automatic rollback. Backup is kept at .git-backup/.
Workflow C: Cleanup
Step 1: List worktrees
Run this complete Bash block to detect and list:
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "ERROR: Not in a git repository" >&2; exit 1
elif [ -f "$TOPLEVEL/.git" ]; then
GIT_COMMON=$(cd "$TOPLEVEL" && git rev-parse --git-common-dir)
BARE_DIR=$(cd "$TOPLEVEL" && cd "$GIT_COMMON" && pwd)
PROJECT_ROOT=$(dirname "$BARE_DIR")
else
PROJECT_ROOT="$TOPLEVEL"
fi
git -C "$PROJECT_ROOT" worktree list
Step 2: Select target
Use AskUserQuestion to ask which worktree(s) to remove.
Step 3: Execute
Run this complete Bash block. Replace {WORKTREE_PATH} with the selected path, or use --all:
PLUGIN_DIR=$(find ~/.claude/plugins/cache -maxdepth 6 -path "*/git-worktree-plugin/*/scripts/create-and-open.sh" 2>/dev/null \
| sed 's|/scripts/create-and-open.sh||' \
| sort -V \
| tail -1)
if [ -z "$PLUGIN_DIR" ]; then
_SKILL_SCRIPTS=$(find ~/.agents/skills -maxdepth 4 -path "*/git-worktree/scripts/create-and-open.sh" 2>/dev/null | head -1)
[ -n "$_SKILL_SCRIPTS" ] && PLUGIN_DIR=$(dirname "$_SKILL_SCRIPTS")/..
fi
if [ -z "$PLUGIN_DIR" ]; then echo "ERROR: Plugin scripts not found" >&2; exit 1; fi
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$TOPLEVEL" ]; then
echo "ERROR: Not in a git repository" >&2; exit 1
elif [ -f "$TOPLEVEL/.git" ]; then
GIT_COMMON=$(cd "$TOPLEVEL" && git rev-parse --git-common-dir)
BARE_DIR=$(cd "$TOPLEVEL" && cd "$GIT_COMMON" && pwd)
PROJECT_ROOT=$(dirname "$BARE_DIR")
else
PROJECT_ROOT="$TOPLEVEL"
fi
bash "$PLUGIN_DIR/scripts/cleanup-worktree.sh" \
--project-root "$PROJECT_ROOT" \
--path "{WORKTREE_PATH}"
Format Rules
- Feature names: lowercase, spaces/underscores โ dashes
- Branch format:
{prefix}/{feature-name} (e.g., feat/user-authentication)
- PR format:
pr-{number} (e.g., pr-123)
- Worktree path:
./trees/{branch-name} (customizable)