Skip to main content
command CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/worktree.md
Open on GitHub

What 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 .gitignore on 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.md

Call it with /worktree. For all projects use ~/.claude/commands/

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).

Similar slash commands

All slash commands for Git and GitHub →

From the same set45

The whole set →
update-threat-db The update-threat-db command delegates threat database changes to AgentSec and checks the resulting feed, catalogue, and compatibility data. CX Codex +1 ★ 6,529repo stars remove-worktree remove-worktree deletes a worktree by branch name: the directory, the git entry and the local branch. Useful when merged branches leave copies behind. CX Codex +1 ★ 6,529repo stars clean-worktrees clean-worktrees cleans up Git worktrees for branches already merged into main. Useful after landing pull requests to reclaim disk space without prompt fatigue. CX Codex +1 ★ 6,529repo stars park park stores the active session in a Markdown file so work can resume after a restart. It is made for Claude Code and Codex workflows. CX Codex +1 ★ 6,529repo stars worktree-status worktree-status is a Claude Code command that reports the branch, path, commit hash, and modified-file count for each active git worktree. CX Codex +1 ★ 6,529repo stars track-mentions track-mentions finds fresh web references to the Claude Code Ultimate Guide and updates its tracker. Use it when you need a repeatable mention audit. CX Codex +1 ★ 6,529repo stars audit-quiz-coverage The audit-quiz-coverage command for Claude Code and Codex compares recent releases and guide changes with quiz questions, then drafts questions for topics not yet covered. CX Codex +1 ★ 6,529repo stars retex retex logs technical incidents, rollbacks, and mistakes into project memory so Claude Code retains prevention rules across sessions. CX Codex +1 ★ 6,529repo stars

Project sponsors

Companies that keep this analytics open