git-worktrees

A Git workspace helper that creates an isolated copy of a repository for feature work. A Git worktree lets you work on another branch without changing the branch you currently have open.

In plain words
What is it for?
Use it before starting feature development that needs isolation. It detects existing isolation, uses available built-in workspace tools, and otherwise creates a Git worktree.
Why use it?
It keeps unfinished changes separate from the current working folder and avoids creating a second workspace when the environment already provides one.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/khaledsaeed18/dotclaude/git-worktrees
Any agent
npx skills add KhaledSaeed18/dotclaude --skill git-worktrees
Clone the repo
git clone --depth 1 https://github.com/KhaledSaeed18/dotclaude

Made for: Claude Code, Codex.

Per session 66 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,166 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00066 $0.01166
Opus 5 $0.00033 $0.00583
Sonnet 5 $0.00013 $0.00233
Haiku 4.5 $0.00007 $0.00117

Measured 2d ago against content hash 065ba2294bf5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

git-worktrees scanned grade A with 0 findings 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 2d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude-plugin/plugins/git/skills/git-worktrees/SKILL.md · 84 lines

How it starts

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

Make sure the work happens somewhere isolated, without fighting whatever isolation the environment already provides. The order matters: detect what you're already in, prefer native tooling, and only reach for raw git worktree as a last resort. Creating a worktree on top of an environment that already gave you one produces phantom state the harness can't see or clean up.

Step 0: Detect existing isolation first

Before creating anything, check whether you're already isolated.

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)

If GIT_DIR != GIT_COMMON, you're likely already in a linked worktree — but the same is true inside a git submodule, so rule that out first:

git rev-parse --show-superproject-working-tree 2>/dev/null

If that prints a path, you're in a submodule: treat it as a normal repo. Otherwise, GIT_DIR != GIT_COMMON means you're already in a worktree — skip creation and go straight to setup (Step 3). Report it: "Already in an isolated workspace at <path> on branch <name>" (or note a detached HEAD, which will need a branch created at finish time).

If GIT_DIR == GIT_COMMON (or you're in a submodule), you're in a normal checkout. Unless the user has already stated a worktree preference, ask before creating one:

"Want me to set up an isolated worktree? It keeps your current branch untouched while I work."

Honor an existing stated preference without re-asking. If the user declines, work in place and skip to Step 3.

Step 1: Create the isolated workspace

Two mechanisms, tried in this order.

1a. Native worktree tooling (preferred)

Do you already have a native way to create a worktree — a tool named something like EnterWorktree or WorktreeCreate, a /worktree command, a --worktree flag? If so, use it and skip to Step 3. Native tools handle placement, branch creation, and cleanup themselves; using raw git worktree add alongside them creates state the harness can't track. Only fall through to 1b if no native tool exists.

Read the full file on GitHub · 84 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. 2d ago First seen · 84 lines · 66 tokens per session scan A 065ba2294bf5

Subscribe to this mod's changes

git-worktrees is a skill published in the GitHub repository KhaledSaeed18/dotclaude (4 stars, last pushed 7d ago), licensed MIT. It adds 66 tokens to every session and 1,166 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.