worktree — Claude Code command: isolated branch work
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.
CC-BY-SA-4.0 ★ 6,529 updated 2026-10-22
.claude/commands/worktree.mdWhat worktree 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.
What it helps with
- 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.gitignoreon first run
Example prompts for the agent
- 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
How to install worktree
Manually: put the files in place
.claude/commands/worktree.mdCall it with /worktree. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/worktree.mdCall it with /prompts:worktree. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/worktree.prompt.mdManually: put the files in place
.gemini/commands/worktree.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about worktree
How do I install worktree in Claude Code?
Copy the command file to .claude/commands/worktree.md in your project. Claude Code reads this directory automatically on startup.
What does the worktree command do?
It creates an isolated directory for a git branch, checks .gitignore, and validates the branch name. You can then open that directory separately in Claude Code to work on multiple branches at once.
What branch naming format should I use?
Use prefix/description, such as feature/pr-9-skills, fix/typo, or docs/add-section. The slash in the name becomes a dash in the directory name (.worktrees/feature-pr-9-skills).