Extract /setup-worktree and /teardown-worktree Scripts
Introduction
/start and /finish each contain inline worktree lifecycle steps — setup (create worktree, install deps, copy settings) and teardown (remove venv, delete remote branch, remove worktree and local branch). Extracting these into standalone /setup-worktree and /teardown-worktree scripts makes them reusable, keeps /start and /finish focused on their orchestration role, and creates a clear mirror-image pair for worktree lifecycle management.
Objectives
- Create
/setup-worktreescript that accepts a branch name and sets up the worktree environment - Create
/teardown-worktreescript that auto-detects context and tears down the worktree environment, including remote branch deletion - Update
/startto delegate steps 3–6 to/setup-worktree - Update
/finishto delegate steps 15–16 to/teardown-worktree - Compile all four scripts to regenerate their
.pycounterparts
Architecture
Current structure:
.mekara/scripts/nl/
├── start.md # steps 1-7 inline (includes worktree setup steps 3-6)
├── finish.md # steps 0-16 inline (includes worktree teardown steps 15-16)
└── ...
.mekara/scripts/compiled/
├── start.py
├── finish.py
└── ...
Target structure:
.mekara/scripts/nl/
├── start.md # steps 1-2 + delegates to /setup-worktree + step 7
├── finish.md # steps 0-14 + delegates to /teardown-worktree
├── setup-worktree.md # NEW: worktree creation + dep install + settings copy
├── teardown-worktree.md # NEW: venv removal + remote branch deletion + worktree removal
└── ...
.mekara/scripts/compiled/
├── start.py
├── finish.py
├── setup-worktree.py # NEW
├── teardown-worktree.py # NEW
└── ...
Design Details
/setup-worktree
Takes $ARGUMENTS as the branch name. Steps:
- Create worktree:
git worktree add -b mekara/<branch> ../<branch>— if the branch already exists, choose a different name - Install Python deps:
cd ../<branch> && poetry install --with dev - Install docs deps:
cd ../<branch> && pnpm --dir docs/ i --frozen-lockfile - Copy settings:
cp .claude/settings.local.json ../<branch>/.claude/settings.local.json
/teardown-worktree
No arguments — auto-detects from the current directory. Steps:
- Detect branch:
git branch --show-current - Detect worktree path:
pwd - Remove poetry venv:
poetry env remove --all - Delete remote branch if it exists: check with
git ls-remote --exit-code origin <branch>, thengit push origin --delete <branch>if found - Remove worktree and local branch (run from
../main):git worktree remove -f <path> && rm -rf <path> && git branch -D <branch>
Invariants
/setup-worktreeis always called from themainworktree (where.claude/settings.local.jsonlives)/teardown-worktreeis always called from inside the worktree being torn down
Implementation Plan
Phase 1: Create setup-worktree.md and teardown-worktree.md
Goal: Write the two new NL scripts
Tasks:
- Write
.mekara/scripts/nl/setup-worktree.md - Write
.mekara/scripts/nl/teardown-worktree.md - Run
/compile setup-worktreeto generatesetup-worktree.py - Run
/compile teardown-worktreeto generateteardown-worktree.py
Phase 2: Update start.md and finish.md
Goal: Replace inline steps with calls to the new scripts
Tasks:
- Edit
start.mdto replace steps 3–6 with a call to/setup-worktree <branch-name> - Edit
finish.mdto replace steps 15–16 with a call to/teardown-worktree - Run
/compile startto regeneratestart.py - Run
/compile finishto regeneratefinish.py
Phase 3: Generalize bundled scripts
Goal: Sync all edited scripts to their bundled counterparts
Tasks:
- Run
/mekara:generalize-bundled-scriptonsetup-worktree - Run
/mekara:generalize-bundled-scriptonteardown-worktree - Run
/mekara:generalize-bundled-scriptonstart - Run
/mekara:generalize-bundled-scriptonfinish