git-worktrees

git-worktrees is a skill for Claude Code from sailingnaturali/claude-skills. It costs 124 tokens per session (1,285 once invoked), scanned C, original, MIT.

A guide to using Git worktrees when several coding sessions need the same repository at once. Each worktree is a separate directory with its own branch and files, while the repository's stored history is shared.

In plain words
What is it for?
Use it to create branch-specific directories outside the main checkout, share fetched Git history, keep separate installs and build output, and safely remove unused worktrees.
Why use it?
It avoids repeatedly switching branches, stashing changes, or mixing build files and dependencies between sessions. This keeps a review, build, feature, or fix isolated from the others.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is git worktree add ../myrepo-featurex -b featurex origin/main.

Part of the git-worktrees plugin — 1 skill shipped together

Good fit Use it to create branch-specific directories outside the main checkout, share fetched Git history, keep separate installs and build output, and safely remove unused worktrees.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/sailingnaturali/claude-skills
agentmods
npx agentmods add skills/sailingnaturali/claude-skills/git-worktrees

Made for: Claude Code.

Or install git-worktrees, the plugin that ships this one along with the rest of its 1 skill.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for git-worktrees

README.md
[![agentmods](https://agentmods.dev/badge/skills/sailingnaturali/claude-skills/git-worktrees/github.svg)](https://agentmods.dev/skills/sailingnaturali/claude-skills/git-worktrees)
Your own site
<a href="https://agentmods.dev/skills/sailingnaturali/claude-skills/git-worktrees"><img src="https://agentmods.dev/badge/skills/sailingnaturali/claude-skills/git-worktrees/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for git-worktrees

Your own site · 80×15
<a href="https://agentmods.dev/skills/sailingnaturali/claude-skills/git-worktrees"><img src="https://agentmods.dev/badge/skills/sailingnaturali/claude-skills/git-worktrees.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 124 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,285 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00124 $0.01285
Opus 5.5 $0.00050 $0.00514
Sonnet 5.5 $0.00025 $0.00257
Haiku 4.5 $0.00012 $0.00128

Measured 1mo ago against content hash be9047047d12, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade C, and why

git-worktrees scanned grade C with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

description: Use when multiple sessions work the same repo in parallel — several agent/dev sessions, a long-running review or build that must not be disturbed, or a quick look at another branch or PR. git worktree gives
git-worktrees/skills/git-worktrees/SKILL.md · 94 lines

How it starts

The opening of the file, as written. The whole thing — 94 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Parallel branches with git worktrees

One working copy can have one checked-out branch. The moment a second session needs the same repo — another agent working a second task, a background review or build you must not disturb, a quick fix while a feature is mid-flight — you either wait, stash-juggle, or silently fight: a checkout under a running process, node_modules half-rebuilt for the other branch, test output from a mix of both. git worktree ends that: extra working directories over the same repository, each with its own branch, files, and installs.

The rules that matter

  • Create a sibling directory, named <repo>-<topic>:

    git worktree add ../myrepo-featurex -b featurex origin/main
    

    The path lives outside the main checkout. Everything git-tracked appears there; the object store, branch and remote-tracking refs, and stashes stay shared — a git fetch in any worktree is visible in all of them — while each worktree keeps its own HEAD and index. Disk cost is one checkout plus its installs, not a second clone.

    The last argument is the start point, and it has to be a ref that exists locally. A plain clone has only origin, so origin/main is the safe default; on a fork you also have upstream, and branching off the true upstream (upstream/main) rather than your fork's stale mirror is usually what you want. Substitute the remote and the default branch to match the repo — git remote and git branch -r tell you what exists. A start point that does not resolve fails the command outright with fatal: invalid reference: <remote>/<branch>, so this is a typo you find immediately, not one that silently branches off the wrong base.

  • One branch ↔ one worktree, enforced. Checking out a branch that another worktree holds fails: fatal: '<branch>' is already used by worktree at '<path>'. That refusal is the feature — it turns two-sessions-on-one-branch from a silent fight into a loud error (--force can override it; don't, for exactly that reason). To inspect the same commit twice, use a detached worktree instead:

Read the full file on GitHub · 94 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 94 lines · 124 tokens per session scan C be9047047d12

Subscribe to this mod's changes

git-worktrees is a skill published in the GitHub repository sailingnaturali/claude-skills (3 stars, last pushed 14d ago), licensed MIT. It adds 124 tokens to every session and 1,285 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it C with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-07.