# Git worktree

> Git worktree is an open-source agent skill for developer tools. Create, list, switch and clean up git worktrees with env and dev-tool setup. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/git-worktree
- **Repository:** https://github.com/wan-huiyan/agent-traffic-control
- **GitHub stars:** 5
- **License:** MIT
- **Skill name:** git-worktree
- **Collection:** https://github.com/wan-huiyan/agent-traffic-control
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

This skill gives the agent a bash manager script for working in a second, isolated checkout of a repository, useful for parallel feature work or reviewing a pull request without disturbing the current branch. The script creates worktrees under a .worktrees directory from a base branch, lists them, switches between them and interactively removes inactive ones.

Beyond plain git commands, the script copies common environment files such as .env and .env.local from the main repo into new worktrees, keeps the worktree directory listed in .gitignore, and trusts mise or direnv configs using branch-aware rules. Trusted base branches are compared against themselves, other branches against the default branch, and direnv auto-allow is skipped on non-trusted bases.

The skill is meant to replace direct git worktree add calls. It also includes a section on checking for duplicate clones and worktrees with unpushed commits, stashes or unmerged branches before deleting one. It expects bash and git, and it is shipped as part of a Claude Code plugin.

## When your agent uses it

> Create, list, switch and clean up git worktrees — a second isolated checkout for parallel work or a pull request review. Runs the bundled `skills/git-worktree/scripts/worktree-manager.sh`, which also copies `.env` in, gitignores the dir and trusts mise or direnv. Not a bare `git worktree add`.

## What it can access

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

- [Runs shell scripts](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/git-worktree)
- [No network calls found in its scripts](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/git-worktree)
- [License: MIT](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/git-worktree)

## Features

- **Create isolated worktrees:** Builds a new branch and worktree from a base branch, refreshing the base from the remote first.
- **Env file copying:** Copies .env, .env.local and similar files from the main repo into each new worktree.
- **Dev tool trust handling:** Trusts mise or direnv configs with safety rules that depend on the branch being checked out.
- **List and switch:** Shows existing worktrees with their branches and moves into a chosen one.
- **Interactive cleanup:** Asks for confirmation before removing inactive worktrees and empty directories.
- **Duplicate checkout audit:** Lists checks to confirm a worktree or clone holds no uncommitted, stashed or unpushed work before removal.

## Good for

- Set up a separate worktree to review a pull request without switching branches
- Start a parallel feature branch in its own checkout
- List which worktrees exist and which branch each one uses
- Clean up finished worktrees after a review or merge
- Copy missing .env files into a worktree created with raw git

## Install

### Claude Code

This skill ships in the `agent-traffic-control` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add wan-huiyan/agent-traffic-control
/plugin install agent-traffic-control@wan-huiyan-agent-traffic-control
```

Or copy only this skill to `~/.claude/skills/git-worktree`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/git-worktree &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-worktree" ~/.claude/skills/git-worktree &&
rm -rf "$tmp"
```

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

### Codex

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

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/git-worktree &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-worktree" ~/.agents/skills/git-worktree &&
rm -rf "$tmp"
```

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

### Cursor

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

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/git-worktree &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-worktree" ~/.cursor/skills/git-worktree &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/git-worktree` 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/wan-huiyan/agent-traffic-control.git --path plugins/agent-traffic-control/skills/git-worktree
```

Or copy the folder to `~/.gemini/skills/git-worktree` yourself.

### VS Code

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

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/git-worktree &&
cp -R "$tmp/plugins/agent-traffic-control/skills/git-worktree" ~/.copilot/skills/git-worktree &&
rm -rf "$tmp"
```

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

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git
```

Then copy `agent-traffic-control/plugins/agent-traffic-control/skills/git-worktree` into your agent's skills folder as `git-worktree`. Agents that support SKILL.md read one folder per skill.

## FAQ

### Does it replace git worktree add?

The skill says to use its manager script instead of calling git worktree add directly, because the script also copies env files, updates .gitignore and handles dev tool trust.

### Which commands does Git worktree provide?

create, list (or ls), switch (or go), cleanup (or clean) and copy-env, all run through the bundled worktree-manager.sh script.

### What does cleanup remove?

It lists inactive worktrees, asks for confirmation, removes the selected ones and cleans up empty directories. It will not remove the current worktree.

### Which base branches are trusted for direnv?

The content names main, develop, dev, trunk, staging and release/* as trusted bases, where direnv auto-allow applies.

### How do I install Git worktree in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/git-worktree to use it in all your projects, or to .claude/skills/git-worktree in one project. Or install the agent-traffic-control plugin, which includes it: /plugin marketplace add wan-huiyan/agent-traffic-control, then /plugin install agent-traffic-control@wan-huiyan-agent-traffic-control.

### Does Git worktree run scripts?

Yes. It runs shell scripts. No network calls were found in its 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 Git worktree?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Git worktree?

The closest alternatives to Git worktree are Worktrees, Harness read write base repo path in worktree stale tree, Git clean worktrees, Create worktree 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.
- [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.
- [Git clean worktrees](https://ai-powered.com/skills/git-clean-worktrees): Git clean worktrees 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.
- [Wt](https://ai-powered.com/skills/wt-timvw): Wt is an open-source agent skill for developer tools.
- [Worktrees](https://ai-powered.com/skills/worktrees-richardgill-4): Worktrees is an open-source agent skill for developer tools.
- [Cross worktree spec handoff via checkout paths](https://ai-powered.com/skills/cross-worktree-spec-handoff-via-checkout-paths): Cross worktree spec handoff via checkout paths is an open-source agent skill for developer tools.
- [Concurrent session checkout clobbers shared worktree](https://ai-powered.com/skills/concurrent-session-checkout-clobbers-shared-worktree): Concurrent session checkout clobbers shared worktree is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/git-worktree
