Skip to main content
skill CX Codex

using-git-worktrees · julianobarbosa — Claude Code skill: worktrees with tmux

using-git-worktrees creates a git worktree under .claude/worktrees/, opens it in a tmux window of the current session and sends the task there.

MIT 106 installs ★ 17 updated 2026-10-14

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add julianobarbosa/claude-code-skills --skill using-git-worktrees -a claude-code
Open on GitHub

What using-git-worktrees does

One pass covers the whole setup. The skill runs git worktree add into .claude/worktrees/{name}, spawns a tmux window named {session}-{name} inside the session you are already in, then types the command into that window with send-keys. Ask only for a worktree and it stops after the window; ask for a worktree plus a task and the command goes in too. Teardown after a merge closes the window, removes the directory and the branch, then prunes.

Two things trip it up. The .claude/worktrees/ path has to be ignored by git, otherwise the parent repo treats worktree files as untracked, so the skill checks and appends the line when it is missing. Running git status in two worktrees at once can also hit index.lock, because the index is locked per repository. Long window names run into path-length limits in tmux.

There is a scripts/setup-worktree.sh for scripted setup, plus references/tmux-integration.md and references/bmad-orchestration.md for tmux tuning and BMAD dependency work. Unattended runs need claude --dangerously-skip-permissions, which the skill reserves for an explicit request. No tmux session? The window and dispatch steps drop out and you get the worktree path back.

What it helps with

  • Spin up a separate worktree per feature without touching the main checkout
  • Send a task into a fresh tmux window of the session you are in
  • Run several Claude instances side by side in one session
  • Tear down the worktree, its window and the merged branch
  • Keep .claude/worktrees/ out of the parent repo's index

Example prompts for the agent

  • Create a worktree for story-1-3 and start claude there with the task
  • Open a worktree off main in a new tmux window of this session
  • Clean up the story-1-3 worktree and its window after the merge

How to install using-git-worktrees

1Skills CLI (Vercel)

npx skills add julianobarbosa/claude-code-skills --skill using-git-worktrees -a claude-code

2Manually: put the files in place

~/.claude/skills/using-git-worktrees/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/using-git-worktrees/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about using-git-worktrees

How do I install using-git-worktrees in Claude Code?

Run npx skills add julianobarbosa/claude-code-skills --skill using-git-worktrees -a claude-code. The skill file lands at ~/.claude/skills/using-git-worktrees/SKILL.md.

What does using-git-worktrees do?

It builds a git worktree under .claude/worktrees/, opens a tmux window in your current session and dispatches the command into it. It also removes the worktree, window and branch once the work is merged.

Do I need tmux for this skill?

Yes for the window and dispatch steps. Without a tmux session the skill creates the worktree only and reports its path.

Source text

SKILL.md · MIT
---
name: using-git-worktrees
description: Git worktree management with tmux integration and task dispatch. Use when creating isolated dev environments, launching parallel feature work, running multiple Claude instances, managing worktrees, dispatching tasks to worktree terminals, or cleaning up after merge. Covers worktree creation in .claude/worktrees/, tmux window management in the current session, and command dispatch. Also use when someone says "create a worktree", "launch in a worktree", "worktree for story X", or "parallel development".
---

# Git Worktrees with tmux Integration

Create isolated workspaces, open them in tmux windows within your current session, and dispatch tasks — all in one flow.

## Core Flow

```
1. Create worktree     → git worktree add .claude/worktrees/{name} -b {branch}
2. Create tmux window  → new window in CURRENT session named {session}-{name}
3. cd into worktree    → send-keys to the new window
4. Dispatch task       → send-keys with the command to execute
```

## Workflow Routing

| Intent | Action |
|--------|--------|
| "create worktree for X" | Create → steps 1-3 only |
| "create worktree and run Y" | Create + Dispatch → steps 1-4 |
| "clean up worktree X" | Cleanup → remove worktree + tmux window + optionally delete branch |
| "list worktrees" | Show `git worktree list` |
| "analyze for parallelization" | Read `references/bmad-orchestration.md` for BMAD-specific dependency analysis |
| "merge worktree branches" | Read `references/bmad-orchestration.md` for merge workflow |

## Step 1: Create Worktree

### Safety Check

Before creating, verify `.claude/worktrees/` is git-ignored:

```bash
# Check if ignored (test with a hypothetical file)
git check-ignore .claude/worktrees/test 2>/dev/null
```

If NOT ignored, add to `.gitignore` immediately:

```bash
echo ".claude/worktrees/" >> .gitignore
# Stage and commit the gitignore change
```

### Create

```bash
REPO_ROOT=$(git rev-parse --show-toplevel)
WORKTREE_NAME="the-feature-name"
BRANCH_NAME="feature/the-feature-name"  # or bmad/story-1-3 etc.
BASE_BRANCH="main"  # or current branch

mkdir -p "$REPO_ROOT/.claude/worktrees"
git worktree add "$REPO_ROOT/.claude/worktrees/$WORKTREE_NAME" -b "$BRANCH_NAME" "$BASE_BRANCH"
```

### Verify

```bash
git worktree list
```

## Step 2: Create tmux Window

Create a new window in the **current tmux session** (not a new session). The window name follows the pattern `{current-session-name}-{worktree-name}` so it's easy to identify.

```bash
# Get current tmux session name
SESSION=$(tmux display-message -p '#S')
WINDOW_NAME="${SESSION}-${WORKTREE_NAME}"
WORKTREE_PATH="$REPO_ROOT/.claude/worktrees/$WORKTREE_NAME"

# Create window in current session, starting in worktree directory
tmux new-window -t "$SESSION" -n "$WINDOW_NAME" -c "$WORKTREE_PATH"
```

## Step 3: Ensure Working Directory

The `-c` flag in step 2 already sets the initial directory, but if you need to explicitly cd (e.g., shell profile overrides it):

```bash
tmux send-keys -t "${SESSION}:${WINDOW_NAME}" "cd '$WORKTREE_PATH'" Enter
```

## Step 4: Dispatch Task (Optional)

Send a command to the new tmux window:

```bash
# Example: launch Claude Code with a task
tmux send-keys -t "${SESSION}:${WINDOW_NAME}" "claude 'your task here'" Enter

# Example: run a BMAD skill
tmux send-keys -t "${SESSION}:${WINDOW_NAME}" "claude '/bmad-create-story story 1-3'" Enter

# Example: run any shell command
tmux send-keys -t "${SESSION}:${WINDOW_NAME}" "make test" Enter
```

For unattended execution (no permission prompts):
```bash
tmux send-keys -t "${SESSION}:${WINDOW_NAME}" "claude --dangerously-skip-permissions 'your task'" Enter
```

**Important:** Only use `--dangerously-skip-permissions` if the user explicitly requests it.

## Cleanup Workflow

After work is complete and merged:

```bash
WORKTREE_NAME="the-feature-name"
REPO_ROOT=$(git rev-parse --show-toplevel)
SESSION=$(tmux display-message -p '#S')

# 1. Kill the tmux window
tmux kill-window -t "${SESSION}:${SESSION}-${WORKTREE_NAME}" 2>/dev/null

# 2. Remove the git worktree
git worktree remove "$REPO_ROOT/.claude/worktrees/$WORKTREE_NAME"

# 3. Optionally delete the branch (only if merged)
git branch -d "$BRANCH_NAME" 2>/dev/null

# 4. Prune stale worktree references
git worktree prune
```

## Quick Reference

| Situation | Action |
|-----------|--------|
| `.claude/worktrees/` exists | Use it (verify ignored) |
| Not in `.gitignore` | Add `.claude/worktrees/` and commit |
| Not in tmux | Skip tmux steps, just create worktree and report path |
| Branch already exists | Use `git worktree add <path> <existing-branch>` (no `-b`) |
| Worktree path exists | Report error, ask user to remove or pick different name |

## Naming Conventions

| Element | Pattern | Example |
|---------|---------|---------|
| Worktree directory | `.claude/worktrees/{name}` | `.claude/worktrees/story-1-3` |
| Branch | `{convention}/{name}` | `bmad/story-1-3-deploy-nat-gateway` |
| tmux window | `{session}-{name}` | `myproject-golden-image-story-1-3` |

The branch naming convention depends on the project. Check CLAUDE.md for project-specific patterns (e.g., `bmad/story-{id}` for BMAD projects).

## Troubleshooting

**Branch already checked out:**
```bash
# Another worktree has this branch — remove it first or use a different name
git worktree list  # find which worktree has the branch
```

**tmux window name conflict:**
```bash
# Rename or kill the conflicting window
tmux kill-window -t "session:conflicting-name" 2>/dev/null
```

**Worktree not in .gitignore after adding:**
```bash
# .gitignore uses directory patterns — ensure trailing slash
# Check with: git check-ignore .claude/worktrees/testfile
```

## References

- [WORKFLOW.md](WORKFLOW.md) — Detailed step-by-step workflow with edge cases
- [references/bmad-orchestration.md](references/bmad-orchestration.md) — BMAD sprint parallelization, dependency analysis, and merge workflows
- [references/tmux-integration.md](references/tmux-integration.md) — Advanced tmux configuration for worktrees
- [scripts/setup-worktree.sh](scripts/setup-worktree.sh) — Shell script for automated worktree setup

---

## Gotchas

- **`.claude/worktrees/` conflicts with `.gitignore` defaults** — must explicitly ignore it or the parent repo sees worktree files as untracked.
- **tmux session names with worktree paths hit filename length limits** — use short branch-based names or the socket path errors.
- **Concurrent `git status` across worktrees can fail with index.lock errors** — git locks the index per-repo, not per-worktree.
- **BMAD-specific parallel work assumes disjoint files**: overlapping edits across stories cause merge headaches at integration.
- **Shell prompts that read git branch via the worktree path can be slow** — disable expensive prompt parts in worktrees.

© julianobarbosa · MIT · julianobarbosa/claude-code-skills

Similar skills

All skills for Git and GitHub →

using-git-worktrees by other authors comes first.

using-git-worktrees Jesse Vincent using-git-worktrees prepares an isolated workspace before feature work or plan execution. It checks the repository first, then uses native worktree support or Git. CX Codex +1 217,153installs using-git-worktrees osmontero The using-git-worktrees Claude Code skill sets up a separate Git worktree for a task. It kicks in before feature work or an implementation plan when the current checkout should stay untouched. CX Codex +1 103installs using-git-worktrees GanyuanRan using-git-worktrees — a Claude Code skill that decides whether a git worktree is actually needed before creating one. It checks repository state and only adds a checkout when a concrete conflict exists. CX Codex +1 ★ 1,450repo stars git-worktrees jamesrochabrun git-worktrees is a Claude Code skill for running parallel sessions on separate branches without conflicts. It provides scripts to create, manage, and clean up isolated worktrees. CX Codex +1 135installs worktree-init davila7 worktree-init — a Claude Code command that turns a task list into separate git worktrees. Each task gets its own branch, directory, and a ready command for a Ghostty panel. CX Codex +1 94installs using-tmux-for-interactive-commands obra using-tmux-for-interactive-commands teaches an agent to drive vim, REPLs and interactive git rebase through detached tmux sessions. Useful when plain bash just hangs. CX Codex +1 515installs create-worktrees davila7 create-worktrees — a command for Claude Code fetches all open PRs through GitHub CLI and creates a git worktree for each branch in ./tree/<BRANCH_NAME>. Multiple PRs can be reviewed or worked on in parallel, each in its own directory. CX Codex +1 351installs git-worktree-runner dyoshikawa git-worktree-runner — a skill that teaches the agent to drive git worktrees through the gtr CLI: create, open in an editor, run commands, remove. CX Codex +1 ★ 1,636repo stars create-worktree-skill disler create-worktree-skill creates a separate Git worktree for a chosen branch and prepares its ports and configuration. Use it to run multiple project branches side by side. CX Codex +1 ★ 1,573repo stars

From the same set37

The whole set →
knative knative guides Kubernetes serverless deployments, scale-to-zero autoscaling, traffic splitting, and CloudEvents routing. CX Codex +1 109installs pyroscope Guides and configs for Grafana Pyroscope continuous profiling: Helm deployments, Go/Java/Python SDK setups, object storage, and trace correlation. CX Codex +1 108installs using-cloud-cli The using-cloud-cli skill sets patterns for bq, gcloud, and aws. Use it for BigQuery queries, cloud resource commands, and AWS or GCP service decisions. CX Codex +1 108installs tempo A practical Grafana Tempo guide for OpenTelemetry tracing, covering Helm deployment, object storage, TraceQL queries, and Kubernetes troubleshooting. CX Codex +1 107installs looking-up-docs looking-up-docs retrieves version-specific library documentation and live API examples through Context7 inside your coding agent. CX Codex +1 106installs defectdojo Connects Claude Code with DefectDojo to inspect vulnerabilities, filter security findings, and manage test engagements from your terminal. CX Codex +1 105installs external-dns external-dns — a skill for automatic DNS record synchronization with Azure DNS, AWS Route53, Cloudflare and Google Cloud DNS based on Kubernetes Ingress and Service resources. CX Codex +1 105installs keyvault-csi-driver keyvault-csi-driver is a skill for connecting Azure Key Vault to Kubernetes with the Secrets Store CSI Driver. It guides SecretProviderClass setup, secret mounts, and access-error troubleshooting. CX Codex +1 102installs

Project sponsors

Companies that keep this analytics open