Skip to main content
skill CX Codex

git-worktree-runner — Claude Code skill: manage git worktrees

A skill that teaches the agent to drive git worktrees through the gtr CLI: create, open in an editor, run commands, remove.

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

What git-worktree-runner does

The skill covers git-worktree-runner (gtr), a CLI wrapper around git worktree. The agent gets ready-made commands: git gtr new feature-branch creates a worktree with a new branch, --from origin/main bases it on a specific ref, and -e or -a opens the editor or an AI tool right away. Listing, removal and renaming go through git gtr list, git gtr rm and git gtr mv, while git gtr run executes an arbitrary command inside a chosen worktree.

Parallel agent work is the other scenario. Each task gets its own isolated worktree, each worktree gets its own AI tool, and git gtr list shows the overall state. Set the defaults first: git gtr config set gtr.editor.default cursor and git gtr config set gtr.ai.default claude. Files such as **/.env are not carried into new worktrees on their own — add them with git gtr config add gtr.copy.include.

The skill allows only git-worktree-runner commands, so plain git will not run through it. Checking out a fork PR takes manual steps: gh pr view <PR_NUMBER> --json headRefName,isCrossRepository, then git fetch origin pull/<PR_NUMBER>/head:<BRANCH_NAME> --force, and only then git gtr new <BRANCH_NAME> --track local. If another worktree already holds that branch, the fetch fails with a checked-out-branch error — run git gtr rm <branch> first.

What it helps with

  • spin up a separate worktree for a new task without touching the current branch
  • run several AI agents in parallel on isolated repo copies
  • fetch a fork PR and open it in an editor for review
  • run tests in a worktree while main work continues elsewhere
  • ship an urgent hotfix and return to the feature without context switching

Example prompts for the agent

  • create a worktree for feature-auth from origin/main and open the editor there
  • start the AI tool in the bugfix-login worktree
  • fetch PR 1223 from the fork into a pr-1223 worktree and list all worktrees

How to install git-worktree-runner

1Skills CLI (Vercel)

npx skills add dyoshikawa/rulesync --skill git-worktree-runner -a claude-code

2Manually: put the files in place

~/.claude/skills/git-worktree-runner/SKILL.md

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

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

Questions about git-worktree-runner

How do I install git-worktree-runner in Claude?

Run npx skills add dyoshikawa/rulesync --skill git-worktree-runner -a claude-code. The skill lands in ~/.claude/skills/git-worktree-runner/SKILL.md.

What does git-worktree-runner do?

It gives the agent a set of git gtr commands to create, list, rename and remove worktrees, run commands inside them, and open an editor or AI tool.

Why does git fetch for a fork PR fail with a checked-out-branch error?

Another worktree already holds that branch. Remove it with git gtr rm <branch> and repeat the fetch with --force.

Source text

SKILL.md · MIT
---
name: git-worktree-runner
description: >-
  Manages git worktrees using git-worktree-runner (gtr). Use when the user needs
  to create, list, remove, or navigate worktrees with `git gtr` commands, open
  editors or AI tools in worktrees, manage parallel development branches, or
  check out GitHub PRs (including from forks) into worktrees.
targets:
  - "*"
allowed-tools: "Bash(git-worktree-runner:*)"
---

# Git Worktree Runner (gtr)

git-worktree-runner (gtr) is a CLI tool that wraps `git worktree` with quality-of-life features for modern development workflows including editor and AI tool integration.

## Quick Start

```bash
# Create a new worktree
git gtr new feature-branch

# Create from a remote branch
git gtr new my-branch --from origin/feature-branch

# Open editor in the worktree
git gtr editor feature-branch

# Start AI tool (claude, codex, etc.) in the worktree
git gtr ai feature-branch

# Remove a worktree
git gtr rm feature-branch
```

## Commands

### Creating Worktrees

```bash
# Create a new worktree with a new branch
git gtr new feature-name

# Create from a specific ref (remote branch, tag, commit)
git gtr new my-branch --from origin/main
git gtr new hotfix --from v1.2.3

# Create and immediately open in editor
git gtr new feature -e

# Create and immediately start AI tool
git gtr new feature -a

# Create with both editor and AI tool
git gtr new feature -e -a
```

### Opening Editor / AI Tool

```bash
# Open the configured editor for a worktree
git gtr editor feature-branch

# Start configured AI tool in a worktree
git gtr ai feature-branch
```

### Running Commands

```bash
# Run an arbitrary command in a worktree
git gtr run feature-branch npm test
git gtr run feature-branch pnpm build
```

### Navigation

```bash
# Navigate to a worktree directory
cd "$(git gtr go feature-branch)"
```

### Listing and Managing

```bash
# List all worktrees
git gtr list

# Remove a worktree
git gtr rm feature-branch

# Rename a worktree
git gtr mv old-name new-name
```

## Configuration

```bash
# Set default editor (cursor, vscode, zed, etc.)
git gtr config set gtr.editor.default cursor

# Set default AI tool (claude, codex, opencode, aider, etc.)
git gtr config set gtr.ai.default claude

# Configure files to copy into new worktrees
git gtr config add gtr.copy.include "**/.env"
git gtr config add gtr.copy.include "**/.env.local"
git gtr config add gtr.copy.include "**/.env.example"

# View current configuration
git gtr config list
```

## Example: Parallel AI Development

```bash
# Create isolated worktrees for parallel AI agents
git gtr new feature-auth --from origin/main
git gtr new feature-api --from origin/main
git gtr new bugfix-login --from origin/main

# Start AI tools in each worktree
git gtr ai feature-auth
git gtr ai feature-api
git gtr ai bugfix-login

# Check status of all worktrees
git gtr list

# Clean up when done
git gtr rm feature-auth
git gtr rm feature-api
git gtr rm bugfix-login
```

## Example: PR Review in Isolated Worktree

```bash
# Create a worktree from PR branch
git gtr new review-pr-123 --from origin/pr-branch

# Open in editor to review
git gtr editor review-pr-123

# Run tests in isolation
git gtr run review-pr-123 pnpm test

# Clean up after review
git gtr rm review-pr-123
```

## Example: Hotfix While Working on Feature

```bash
# Current work is on feature-branch, need to do a hotfix
git gtr new hotfix-critical --from origin/main

# Open editor for the hotfix
git gtr new hotfix-critical -e

# After hotfix is done, remove the worktree
git gtr rm hotfix-critical
# Back to feature-branch work without context switching
```

## Example: Checkout a Fork PR into Worktree

For PRs from forked repositories, the branch is not on `origin`. Use GitHub's `refs/pull/<number>/head` ref to fetch it.

### Procedure

Given a PR number or URL:

1. **Get PR metadata**

   ```bash
   gh pr view <PR_NUMBER> --json headRefName,isCrossRepository
   ```

2. **Check for existing worktree** with the same branch name

   ```bash
   git worktree list
   ```

   If it exists, remove it first: `git gtr rm <branch>`

3. **Fetch the PR ref** into a local branch (use `--force` to handle diverged history from force-pushes)

   ```bash
   git fetch origin pull/<PR_NUMBER>/head:<BRANCH_NAME> --force
   ```

4. **Create the worktree** with `--track local` since it's a local-only branch

   ```bash
   git gtr new <BRANCH_NAME> --track local
   ```

5. **Verify**
   ```bash
   git gtr list
   ```

### Full example (PR #1223 from a fork)

```bash
gh pr view 1223 --json headRefName,isCrossRepository
git fetch origin pull/1223/head:fix/comprehensive-file-formats-docs --force
git gtr new fix/comprehensive-file-formats-docs --track local
git gtr list
```

### Shortening long branch names

```bash
git fetch origin pull/1223/head:pr-1223 --force
git gtr new pr-1223 --track local
```

### Common errors

- **"refusing to fetch into branch checked out at..."**: A worktree with that branch exists. `git gtr rm <branch>` first.
- **"non-fast-forward" rejected**: Local branch diverged. Add `--force` to the fetch.
- **Both errors**: Remove the worktree first, then fetch with `--force`.

© dyoshikawa · MIT · dyoshikawa/rulesync

Similar skills

All skills for Git and GitHub →

From the same set11

rebase-latest-main A skill that walks the agent through fetching origin/main, rebasing the current branch and resolving conflicts. Handy when your branch has drifted behind main. CX Codex +1 ★ 1,552repo stars prs-awaiting-author Lists open pull requests where the next move belongs to the author: failing CI, unaddressed review comments, or a maintainer question waiting on a reply. CX Codex +1 ★ 1,552repo stars porting-another-repository Reads a feature in your current repo and the target repo's conventions, then writes a porting plan into tmp/ as files you apply yourself. CX Codex +1 ★ 1,552repo stars goal-release Drives a release end to end: opens the PR, waits for green CI, merges it and updates the Homebrew formula. Handy when a version has to ship in one go. CX Codex +1 ★ 1,552repo stars draft-issue-to-external-repository Drafts a GitHub issue for a repository you do not own: reads the project's templates and title style, settles scope with you, and saves the body to a file. CX Codex +1 ★ 1,552repo stars create-issue A skill that walks through issue creation step by step: gathers context, checks the codebase, drafts English text, and assigns labels. Handy when you want a tidy issue without doing it manually. CX Codex +1 ★ 1,552repo stars clean-branches A skill that walks your local git branches, finds merged and orphaned ones, and deletes them one at a time with a closing report. CX Codex +1 ★ 1,552repo stars batch-all-issues A skill that walks every open issue one at a time: fact-checks each with web research, closes the ones needing no action, and drives the rest to merge. CX Codex +1 ★ 1,552repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor