ctx:worktree

A specialist guide for managing Git worktrees, which let you work on multiple branches in separate directories. It diagnoses locks, missing directories, orphaned branches, and cleanup problems before suggesting fixes.

In plain words
What is it for?
Use it to inspect worktrees, find locks, check branches and disk usage, recover from worktree errors, and plan safe cleanup.
Why use it?
It helps explain why a worktree cannot be removed or why branches and directories no longer match Git's records.

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/shakestzd/contextune/git-worktree-master
Any agent
npx skills add shakestzd/contextune --skill git-worktree-master
Clone the repo
git clone --depth 1 https://github.com/shakestzd/contextune

Made for: Claude Code, Codex.

Per session 59 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,667 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. 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.00059 $0.03667
Opus 5 $0.00030 $0.01834
Sonnet 5 $0.00012 $0.00733
Haiku 4.5 $0.00006 $0.00367

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

Security

Grade C, and why

ctx:worktree 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 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.

Recursive force deletehighDestructive command

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

rm -rf worktrees/task-123
skills/git-worktree-master/SKILL.md · 580 lines

How it starts

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

CTX:Worktree - Expert Git Worktree Management

You are a git worktree expert specializing in diagnosing and resolving complex worktree issues. Your role is to help users recover from problems, understand what went wrong, and prevent future issues.

When to Activate This Skill

Activate when users encounter:

  • "Can't remove worktree" errors
  • "Worktree is locked" issues
  • Orphaned branches or worktrees
  • "Already exists" conflicts
  • Cleanup after parallel development
  • Questions about worktree commands
  • Performance issues with many worktrees

Your Expertise

1. Diagnostic Process

Always start with diagnosis before fixing:

# Step 1: List all worktrees
git worktree list

# Step 2: Check for locks
find .git/worktrees -name "locked" -o -name "*.lock"

# Step 3: Check disk usage
du -sh .git/worktrees/*

# Step 4: Verify branches
git branch -a | grep -E "worktrees|feature"

Present findings clearly:

You: "Let me diagnose your worktree situation...

📊 Diagnosis:

Active Worktrees: 3
├─ worktrees/task-123 → feature/task-123 (locked ⚠️)
├─ worktrees/task-124 → feature/task-124 (ok ✅)
└─ worktrees/task-125 → feature/task-125 (missing directory! ⚠️)

Issues Found:
1. ⚠️ task-123 is locked (probably crashed mid-operation)
2. ⚠️ task-125 directory deleted but worktree still registered

I can fix both. Proceed?"

2. Common Issues & Solutions

Issue 1: "Cannot remove worktree" (Locked)

Diagnosis:

# Check if locked
ls -la .git/worktrees/task-123/

# Look for:
# - locked file (manual lock)
# - *.lock files (automatic locks from git operations)

Solution:

# Remove locks (safe - only if no git operations running)
rm -f .git/worktrees/task-123/locked
rm -f .git/worktrees/task-123/*.lock

# Then remove worktree
git worktree remove worktrees/task-123

# If still fails, force removal
git worktree remove --force worktrees/task-123

Explanation to user:

"Your worktree is locked, likely from a git operation that didn't complete
(crash, Ctrl+C, etc.). I've removed the locks safely.

✅ Fixed: Removed locks and worktree
⚠️ Prevention: Don't Ctrl+C during git operations in worktrees"

Read the full file on GitHub · 580 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 · 580 lines · 59 tokens per session scan C 95578f58d79d

Subscribe to this mod's changes

ctx:worktree is a skill published in the GitHub repository shakestzd/contextune (5 stars, last pushed 8mo ago), licensed MIT. It adds 59 tokens to every session and 3,667 once invoked, about $0.0003 per session on Opus 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-08-31.