# worktree

A command that creates a separate git worktree folder for feature or fix branches. Useful when you need to work on multiple tasks in parallel without conflicts in your main branch.

- command · `type=command` · Claude Code, Codex, GitHub Copilot, Gemini CLI · ★ 6529 repo stars
- Author: FlorianBruniaux
- License: CC-BY-SA-4.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/HEAD/.claude/commands/worktree.md
- Updated: 2026-10-22
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/commands/worktree

## What it does

The `/worktree` command automates setup of an isolated workspace using git worktree. Provide a branch name in `prefix/description` format (e.g., `feature/pr-9-skill-improvements`), and the script creates a directory `.worktrees/prefix-description`, checks if `.worktrees/` is in `.gitignore`, and switches to the new branch.

It validates the branch name, rejecting spaces and git-reserved characters. A `--fast` flag skips the `.gitignore` check. If the branch already exists, the worktree reuses it. When done, the command shows how to switch into the new directory and start Claude there.

Remove a specific worktree with `/remove-worktree` or clean all merged ones with `/clean-worktrees`. Handy for parallel development or when working on docs and need to test different versions side by side.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/commands/worktree.md` — Call it with /worktree. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/worktree.md` — Call it with /prompts:worktree. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/worktree.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/worktree.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/HEAD/.claude/commands/worktree.md

## When to use it
- Create a separate branch for a feature without conflicts in the main codebase
- Work on multiple tasks simultaneously in isolated directories
- Switch quickly between separate worktree environments
- Automatically add `.worktrees/` to `.gitignore` on first run

## Example prompts
- Create a worktree for a feature: `/worktree feature/pr-9-skill-improvements`
- Create a worktree for a fix: `/worktree fix/typo-in-guide`
- Create a worktree and skip gitignore check: `/worktree feat/new-section --fast`

## Similar
- [worktree-init](https://affpapa.org/en/nevibecode/commands/worktree-init.md) — command · 94 installs
- [worktree-check](https://affpapa.org/en/nevibecode/commands/worktree-check.md) — command · 81 installs
- [git-worktree-runner](https://affpapa.org/en/nevibecode/skills/git-worktree-runner.md) — skill · ★ 1636 repo stars
- [branch-finalization](https://affpapa.org/en/nevibecode/skills/branch-finalization.md) — skill · 131 installs
- [ce-worktree](https://affpapa.org/en/nevibecode/skills/ce-worktree.md) — skill · 3200 installs
- [git-worktree-isolation](https://affpapa.org/en/nevibecode/skills/git-worktree-isolation.md) — skill · 2300 installs

From the same set: [florianbruniaux/claude-code-ultimate-guide](https://affpapa.org/en/nevibecode/by/florianbruniaux/claude-code-ultimate-guide.md) — 45 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
