git-worktrees

git-worktrees is a skill for Claude Code, Codex from jnPiyush/AgentX. It costs 62 tokens per session (1,793 once invoked), scanned C, original, Apache-2.0.

A way to give separate agent sessions isolated working directories for the same Git repository. Git worktrees let multiple branches exist side by side without each session changing the primary checkout.

In plain words
What is it for?
Use it for prototypes, experiments, deploy builds, parallel branches, or comparing two implementations at once.
Why use it?
It prevents parallel experiments or long investigations from interfering with the main working directory.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it for prototypes, experiments, deploy builds, parallel branches, or comparing two implementations at once.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jnpiyush/agentx/git-worktrees
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add jnPiyush/AgentX --skill git-worktrees
Clone the repo
git clone --depth 1 https://github.com/jnPiyush/AgentX

Made for: Claude Code, Codex.

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/jnpiyush/agentx/git-worktrees/github.svg)](https://agentmods.dev/skills/jnpiyush/agentx/git-worktrees)
Your own site
<a href="https://agentmods.dev/skills/jnpiyush/agentx/git-worktrees"><img src="https://agentmods.dev/badge/skills/jnpiyush/agentx/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/jnpiyush/agentx/git-worktrees"><img src="https://agentmods.dev/badge/skills/jnpiyush/agentx/git-worktrees.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 62 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,793 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.00062 $0.01793
Opus 5.5 $0.00025 $0.00717
Sonnet 5.5 $0.00012 $0.00359
Haiku 4.5 $0.00006 $0.00179

Measured 20d ago against content hash d7af6aaba700, 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 20d 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.

Never `rm -rf` a worktree directory without `git worktree remove` first; orphaned worktree metadata produces confusing errors later.
.github/skills/development/git-worktrees/SKILL.md · 163 lines

How it starts

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

Git Worktrees

WHEN: An agent (or two agents) needs an isolated working directory on the same repository -- for a parallel branch, a deploy-prototype run, an experimentation-loop attempt, or a long investigation that should not touch the primary checkout's working tree.

When to Use This Skill

Load this skill when:

  • Two agents need to operate on the same repository in parallel
  • An experimentation-loop attempt needs its own working tree so the main checkout stays clean
  • A deploy / prototype build needs an isolated dist/ and node_modules without polluting the primary tree
  • A long debugging session needs to compare two branches side-by-side without stashing

Skip when:

  • The change is a single in-place edit on the current branch
  • The user has explicitly asked you to operate only inside the primary checkout
  • The repo contains active submodules that have not been audited for worktree safety

Prerequisites

  • git 2.5+ (worktree command), 2.20+ recommended for worktree remove
  • Write access to the worktrees parent directory
  • Knowledge of whether the repo uses submodules (worktrees + submodules need extra care)

Rationalization Table

Why agents reach for the wrong primitive.

Rationalization Reality
"I'll just git stash and switch branches." Stash loses untracked files, hides reproduction state, and conflicts when both agents want different branches at once. Worktree is cheaper.
"I'll clone the repo a second time." A second clone duplicates the entire object database, loses shared refs, and drifts from the primary remote config. Worktree shares the object store.
"I'll cd into a temp dir and create a sandbox." A copy is not a checkout. You lose history, hooks, and the ability to rebase / push. Use a worktree.
"Worktrees are scary, I'll just work on master." The fear is that a worktree corrupts the primary. It does not, if Step 0 is followed. The opposite -- working on the primary for everything -- is what actually corrupts state.
"I'll skip Step 0, this repo doesn't have submodules." Step 0 is one command. Run it. Future-you debugging an "I am already inside a worktree" failure will thank present-you.

Read the full file on GitHub · 163 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. 20d ago Changed d7af6aaba700
  2. 1mo ago Changed · -1 tokens per session 52e861e449d8
  3. 1mo ago First seen · 163 lines · 63 tokens per session scan C 511bebfd87d0

Subscribe to this mod's changes

git-worktrees is a skill published in the GitHub repository jnPiyush/AgentX (16 stars, last pushed 3d ago), licensed Apache-2.0. It adds 62 tokens to every session and 1,793 once invoked, about $0.0002 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-03.

Related

Other skills, from other repositories