worktree-init — Claude Code command: parallel git worktrees
Turns a list of tasks into separate git worktrees, each ready for its own Claude session in a Ghostty panel.
npx claude-code-templates@latest --command git-workflow/worktree-initWhat worktree-init does
You pass tasks separated by |, and the command checks that you are inside a git repository, then creates a branch like claude/<task-name> for each one with a working directory at ../worktrees/<repo>/claude-<name>. Every new worktree gets a .worktree-task.md file holding the task description, branch and creation date. A summary table with paths and copy-ready Ghostty commands closes the run.
Before creating anything, it checks the working tree with git status --porcelain. Dirty state triggers a warning and a question about continuing. Then it fetches from origin and picks main or master as the base, whichever origin/HEAD points to.
If a package.json sits in the repo root, the command notes that each worktree likely needs its dependencies installed and points at the matching lockfile: package-lock.json, yarn.lock, pnpm-lock.yaml or bun.lockb. Worth checking that installs go through cleanly before you spin up several Claude instances at once.
What it helps with
- split several tasks across branches without typing
git worktree addby hand - run parallel Claude sessions in separate terminal panels
- keep the task description next to its working directory
- get copy-ready commands for entering each worktree
- remember dependency installs in the fresh directories
Example prompts for the agent
- /worktree-init fix login flow | update API docs | add export tests
- /worktree-init refactor billing module | migrate to the new SDK
How to install worktree-init
1claude-code-templates
npx claude-code-templates@latest --command git-workflow/worktree-init2Manually: put the files in place
.claude/commands/worktree-init.mdCall it with /worktree-init. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/worktree-init.mdCall it with /prompts:worktree-init. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/worktree-init.prompt.mdManually: put the files in place
.gemini/commands/worktree-init.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about worktree-init
How do I install worktree-init in Claude?
Through the templates CLI: npx claude-code-templates@latest --command git-workflow/worktree-init. The command file lands at .claude/commands/worktree-init.md.
What does worktree-init do?
It creates one git worktree per task, sets up claude/<name> branches and prints the commands for launching Claude in Ghostty panels.
How do I pass multiple tasks?
List them in the argument separated by a pipe, for example /worktree-init task 1 | task 2. With an empty argument the command asks you to describe them.
Source text
worktree-init.md · MIT
--- allowed-tools: Bash(git:*), Bash(mkdir:*), Bash(ls:*), Bash(cat:*), Bash(basename:*), Bash(pwd:*), Bash(sed:*) argument-hint: task 1 | task 2 | task 3 description: Create parallel worktrees for multi-task development with Ghostty panels --- # Worktree Parallel Init Create multiple git worktrees for parallel development: $ARGUMENTS ## Instructions You are setting up parallel worktrees so the user can work on multiple tasks simultaneously in separate Ghostty terminal panels, each running its own Claude instance. ### Step 1: Validate Environment 1. Check this is a git repository: `git rev-parse --is-inside-work-tree` 2. Get the repo name: `basename $(git rev-parse --show-toplevel)` 3. Get the main branch name (check for `main` or `master`): `git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@'` — if that fails, default to `main` 4. Ensure working tree is clean: `git status --porcelain`. If dirty, warn the user and ask if they want to continue. 5. Fetch latest: `git fetch origin` ### Step 2: Parse Tasks Parse tasks from `$ARGUMENTS`. Tasks are separated by `|` (pipe character). If `$ARGUMENTS` is empty, use AskUserQuestion to ask the user to describe their tasks (they can provide multiple separated by `|`). For each task description: - Trim whitespace - Generate a kebab-case branch name: `claude/<kebab-case-task>` (max 50 chars, alphanumeric and hyphens only) - Generate a worktree directory path: `../worktrees/<repo-name>/claude-<kebab-case-task>` ### Step 3: Create Worktrees For each task: 1. Create the parent directory if needed: `mkdir -p ../worktrees/<repo-name>` 2. Create the worktree: ```bash git worktree add -b claude/<name> ../worktrees/<repo-name>/claude-<name> origin/<main-branch> ``` 3. Write a `.worktree-task.md` file inside the new worktree with this content: ```markdown # Worktree Task **Branch:** claude/<name> **Task:** <original task description> **Created:** <ISO date> **Source repo:** <path to main repo> ``` ### Step 4: Check for Dependencies If a `package.json` exists in the repo root, note that each worktree may need `npm install` (or the appropriate package manager). Check for: - `package-lock.json` → npm install - `yarn.lock` → yarn install - `pnpm-lock.yaml` → pnpm install - `bun.lockb` → bun install ### Step 5: Output Summary Display a clear summary table: ``` | # | Task | Branch | Path | |---|------|--------|------| | 1 | ... | claude/... | ../worktrees/repo/claude-... | ``` Then display ready-to-copy commands for Ghostty panels. For each worktree: ``` # Panel <N>: <task description> cd <absolute-path-to-worktree> && claude ``` If dependencies were detected, add a note: ``` # Note: Run <package-manager> install in each worktree before starting ``` Finally, remind the user: - Open a new Ghostty panel with `Cmd+D` (split right) or `Cmd+Shift+D` (split down) - When done with a task, use `/worktree-deliver` to commit, push, and create a PR - After merging all PRs, use `/worktree-cleanup --all` from the main repo
© davila7 · MIT · davila7/claude-code-templates