# Worktrees

> Worktrees is an open-source agent skill for developer tools. Creates git worktrees in tmux sessions and starts an AI agent on a prompt. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/richardgill/nix/tree/main/built/ai-agents/opencode/skills/worktrees
- **Repository:** https://github.com/richardgill/nix
- **GitHub stars:** 39
- **License:** MIT
- **Skill name:** worktrees
- **Collection:** https://github.com/richardgill/nix
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

This skill sets up an isolated git worktree for a branch, opens it in a new tmux session, and launches an AI agent there with a prompt. The agent runs in the fourth tmux window, and the session is marked recent without switching to it, so work can continue in the current session.

The skill chooses between three prompt sources: an existing issue, plan, design doc or spec file; a generated temporary prompt file written to /tmp; or no prompt at all, in which case the worktree is created and the current session keeps working in it. It assumes a base branch of main unless told otherwise, and it runs a worktree-branch helper script from the user's Scripts folder. The skill also advises checking the fourth tmux window afterward to confirm the agent started and received its prompt.

It expects a git repository with a main worktree, tmux, and the worktree-branch script installed. The examples use the oc binary as the agent launcher.

## When your agent uses it

> This skill creates git worktrees with tmux sessions and spawns an AI agent with a prompt. Triggers: "create a worktree", "new worktree", "worktree for branch", "spawn worktree", "parallel branch", "work on branch in new session", "worktree-branch script". Creates isolated worktree directories with an AI agent running automatically. Not for regular git branching or checkout operations.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/richardgill/nix/tree/HEAD/built/ai-agents/opencode/skills/worktrees)
- [License: MIT](https://github.com/richardgill/nix/tree/HEAD/built/ai-agents/opencode/skills/worktrees)

## Features

- **Worktree creation:** Creates a sibling git worktree from local main HEAD or from an explicit source ref.
- **Tmux session setup:** Opens the new worktree in a tmux session without switching the current session to it.
- **Automatic agent launch:** Starts an AI agent in the fourth tmux window with the chosen prompt file.
- **Prompt file selection:** Chooses between an existing spec file, a generated temp prompt, or no prompt.
- **Startup verification:** Advises checking the agent window to confirm it started and received the prompt.

## Good for

- Start a parallel branch for a feature while keeping my current session free
- Spin up a worktree from a planning document and let an agent begin implementing it
- Create a new branch from a remote feature branch in its own worktree and session
- Hand a bug description to an agent in a fresh isolated worktree

## Install

### Claude Code

Copy the skill folder to `~/.claude/skills/worktrees` to use it in all your projects:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/richardgill/nix.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/worktrees &&
cp -R "$tmp/built/ai-agents/opencode/skills/worktrees" ~/.claude/skills/worktrees &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/worktrees` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/worktrees` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/richardgill/nix.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/worktrees &&
cp -R "$tmp/built/ai-agents/opencode/skills/worktrees" ~/.agents/skills/worktrees &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/worktrees` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/worktrees` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/richardgill/nix.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/worktrees &&
cp -R "$tmp/built/ai-agents/opencode/skills/worktrees" ~/.cursor/skills/worktrees &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/worktrees` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/richardgill/nix.git --path built/ai-agents/opencode/skills/worktrees
```

Or copy the folder to `~/.gemini/skills/worktrees` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/worktrees`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/richardgill/nix.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/worktrees &&
cp -R "$tmp/built/ai-agents/opencode/skills/worktrees" ~/.copilot/skills/worktrees &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/worktrees` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/richardgill/nix.git
```

Then copy `nix/built/ai-agents/opencode/skills/worktrees` into your agent's skills folder as `worktrees`. Agents that support SKILL.md read one folder per skill.

## FAQ

### When does Worktrees trigger?

It triggers on phrases such as create a worktree, new worktree, worktree for branch, spawn worktree, parallel branch, or work on branch in new session. It is not meant for regular git branching or checkout.

### What does Worktrees need to run?

It needs a git repository with a main worktree, tmux, and the worktree-branch script from the user's Scripts folder. The examples call the oc agent binary.

### Which base branch does Worktrees use?

By default it uses main, creating the new branch from local ./main HEAD unless an explicit source ref is given.

### Does Worktrees switch my tmux session to the new worktree?

No. The new session is created and marked recent but not switched to.

### How do I install Worktrees in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/worktrees to use it in all your projects, or to .claude/skills/worktrees in one project.

### Does Worktrees run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Worktrees?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Worktrees?

The closest alternatives to Worktrees are Worktrees, Git worktree, Create worktree, Tmux pi and Wt.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Worktrees](https://ai-powered.com/skills/worktrees): Worktrees is an open-source agent skill for developer tools.
- [Git worktree](https://ai-powered.com/skills/git-worktree): Git worktree is an open-source agent skill for developer tools.
- [Create worktree](https://ai-powered.com/skills/create-worktree): Create worktree is an open-source agent skill for developer tools.
- [Tmux pi](https://ai-powered.com/skills/tmux-pi): Tmux pi is an open-source agent skill for developer tools.
- [Wt](https://ai-powered.com/skills/wt-timvw): Wt is an open-source agent skill for developer tools.
- [Dmux workflows](https://ai-powered.com/skills/dmux-workflows-fmarzochi): Dmux workflows is an open-source agent skill for developer tools.
- [Harness read write base repo path in worktree stale tree](https://ai-powered.com/skills/harness-read-write-base-repo-path-in-worktree-stale-tree): Harness read write base repo path in worktree stale tree is an open-source agent skill for developer tools.
- [Initialize workspace](https://ai-powered.com/skills/initialize-workspace): Initialize workspace is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/worktrees-richardgill-4
