Prompt file imported from eitatech/gatomia-vscode (
.windsurf/workflows/speckit.worktrees.create.md). Fill in{{arguments}},{{repo}},{{branch}}before use. Copyright stays with the author.
Create Worktree
Spawn an isolated git worktree for a feature branch so you can work on multiple features — or run multiple agents — in parallel without switching branches.
User Input
{{arguments}}
You MUST consider the user input before proceeding (if not empty). The user may specify:
- A branch name (e.g.,
005-user-auth) currentto create a worktree for the current branch--in-placeor--no-worktreeto skip worktree creation entirely
Prerequisites
- Verify the project is a git repository (
git rev-parse --show-toplevel) - Verify
git worktreeis available (git worktree listsucceeds)
Configuration
Read configuration from .specify/extensions/worktrees/worktree-config.yml if it exists. Defaults apply when the file is absent.
| Key | Default | Description |
|---|---|---|
layout |
sibling |
sibling — worktree at ../<repo>--<branch> (IDE-friendly); nested — at .worktrees/<branch>/ inside repo |
auto_create |
true |
When true, the after_specify hook creates a worktree without prompting |
sibling_pattern |
{{repo}}--{{branch}} |
Name pattern for sibling directories |
dotworktrees_dir |
.worktrees |
Subdirectory name for nested layout |
Environment variable SPECIFY_WORKTREE_PATH overrides the computed path entirely.
Outline
-
Determine target branch:
- If user specifies a branch name, use that
- If user says
current, use the output ofgit branch --show-current - If no input and this is an
after_specifyhook call, use the branch that/speckit.specifyjust created (read fromSPECIFY_FEATUREenv var or the most recent feature branch) - Validate the branch exists in git (local or remote)
-
Invoke the script: Run the deterministic bash script shipped with this extension:
bash "$(dirname "$0")/../scripts/bash/create-worktree.sh" \ --json \ [--layout sibling|nested] \ [--path <override>] \ [--in-place] \ [--dry-run] \ "$BRANCH_NAME"The script reads
worktree-config.ymlautomatically and outputs JSON:{"branch":"005-user-auth","worktree":true,"path":"/Users/me/code/MyProject--005-user-auth","layout":"sibling"}If the script is unavailable (e.g., non-bash environment), perform the equivalent operations directly:
- Resolve the worktree path based on layout config
- Run
git worktree add -b <branch> <path> <base-ref>(new branch) orgit worktree add <path> <branch>(existing branch) - For nested layout, ensure
.worktrees/is in.gitignore
-
Verify spec artifacts: Check that
specs/<branch>/exists in the new worktree. List which artifacts are present (spec.md, plan.md, tasks.md). -
Report: Output a summary:
## Worktree Created | Field | Value | |-------|-------| | **Branch** | 005-user-auth | | **Layout** | sibling | | **Worktree path** | /Users/me/code/MyProject--005-user-auth | | **Spec artifacts** | spec.md, plan.md | **Next steps:** - Open the worktree directory in your IDE or a new terminal - Run `/speckit.implement` from the worktree root - Run `/speckit.worktrees.list` to see all active worktrees
Rules
- Default behavior is to create a worktree — only skip if the user explicitly passes
--in-placeor--no-worktree, orauto_createisfalsein config and this is a hook call - One worktree per branch — refuse to create a duplicate; report the existing path instead
- Never modify the primary checkout — worktree operations happen in the new directory only
- Always update .gitignore for nested layout — add the
dotworktrees_dirvalue if not present - Validate branch exists — for existing branches; for new branches the
after_specifyhook should have already created the branch via the git extension
