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
1) Preflight
- Confirm this is a git repository.
- Determine the base branch:
- Prefer
mainif it exists, otherwise trymaster. - If remote
originexists, rungit fetch origin.
2) Naming
- Branch name:
feat/<slug>(short slug derived from the feature name). - Worktree path:
.worktrees/<slug>(keep worktrees inside the repo).
3) 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>
4) Record the active worktree
- Create/update
.worktrees/_active.jsonwith: branchbasepath
5) 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.
6) 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.