Goal
Implement a feature in a separate working directory (git worktree) on a new branch.
Rules
- •Do not edit feature code in the main working directory.
- •Run all git commands in the worktree using:
git -C <path> ... - •Do not create a PR yet. Leave the work ready for review and ask the user for approval.
Steps
- •Preflight
- •Confirm this is a git repository.
- •Determine the base branch:
- •Prefer
mainif it exists, otherwise trymaster.
- •Prefer
- •If remote
originexists, rungit fetch origin.
- •Naming
- •Branch name:
feat/<slug>(short slug derived from the feature name). - •Worktree path:
.worktrees/<slug>(keep worktrees inside the repo).
- •Create the worktree + new branch
- •Create
.worktrees/if it does not exist. - •Create a worktree and new branch from the base ref (prefer
origin/<base>if available):- •
git worktree add -b <branch> .worktrees/<slug> <base_ref>
- •
- •Record the active worktree
- •Create/update
.worktrees/_active.jsonwith:- •
branch - •
base - •
path
- •
- •Implement the feature
- •Make all code changes under
.worktrees/<slug>/... - •Run tests/lint in the worktree (choose appropriate commands based on the repo: package.json -> npm test; pyproject/pytest -> pytest; etc.)
- •Make small, clear commits.
- •Finish
- •Ensure the worktree is clean (no uncommitted changes).
- •Summarize:
- •what changed
- •how to run tests
- •any risks / follow-ups
- •Ask the user for approval to open a PR and clean up the worktree.