worktree

A tool for managing Git worktrees, which are separate checkouts of one repository that let you work on several branches at once. It can create, list, remove, prune, and clean up worktrees and related branches.

In plain words
What is it for?
Use it to start parallel feature or bug-fix work, view active worktrees, remove finished ones, and clean up branches after merging.
Why use it?
It avoids repeatedly switching branches or stashing unfinished changes when developing in parallel.

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

Made for: Claude Code, Codex.

Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,390 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.00043 $0.02390
Opus 5 $0.00022 $0.01195
Sonnet 5 $0.00009 $0.00478
Haiku 4.5 $0.00004 $0.00239

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

Security

Grade A, and why

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

plugins/psd-coding-system/skills/worktree/SKILL.md · 231 lines

How it starts

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

Worktree Command

You manage parallel development using git worktrees. Worktrees let you work on multiple branches simultaneously without stashing or switching — each worktree is an independent checkout of the repo.

Arguments: $ARGUMENTS

Phase 1: Parse Arguments & Detect Intent

ARGS="$ARGUMENTS"

# Detect subcommand
case "$ARGS" in
  list|ls)
    SUBCOMMAND="list"
    ;;
  prune)
    SUBCOMMAND="prune"
    ;;
  clean|sweep|tidy)
    SUBCOMMAND="clean"
    ;;
  remove\ *|rm\ *)
    SUBCOMMAND="remove"
    TARGET=$(echo "$ARGS" | sed 's/^remove //;s/^rm //')
    ;;
  *)
    SUBCOMMAND="create"
    TARGET="$ARGS"
    ;;
esac

echo "Subcommand: $SUBCOMMAND"
echo "Target: ${TARGET:-N/A}"

Phase 2: Execute

If list:

echo "=== Active Worktrees ==="
git worktree list

echo ""
echo "=== Branches in Worktrees ==="
git worktree list --porcelain | grep "^branch" | sed 's/branch refs\/heads\//  /'

If prune (worktrees only — lightweight):

echo "=== Pruning stale worktrees ==="
git worktree prune --verbose

echo ""
echo "=== Remaining worktrees ==="
git worktree list

If clean (post-merge hygiene — restores what /clean-branch used to do):

Sweeps merged branches (local and remote, squash-merge-aware), stale worktrees, and issues that should be closed. Gather the candidates first; the destructive steps (remote-branch deletion, issue closing) are confirmed before running.

echo "=== /worktree clean — post-merge hygiene ==="
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name' 2>/dev/null || echo main)
if git ls-remote --exit-code --heads origin dev >/dev/null 2>&1; then BASE=dev; else BASE="$DEFAULT_BRANCH"; fi
CUR=$(git branch --show-current); PROT='^(main|master|dev|HEAD)$'

git fetch --prune origin --quiet 2>/dev/null || true   # drop tracking refs for branches already deleted on the remote

echo "--- 1. local branches whose work is merged (safe to delete) ---"
LOCAL_DELETE=""
for b in $(git for-each-ref --format='%(refname:short)' refs/heads/); do
  echo "$b" | grep -qE "$PROT" && continue
  [ "$b" = "$CUR" ] && continue
  # normal-merged into base, OR its PR is merged (covers squash merges, which change the SHA)
  if git merge-base --is-ancestor "$b" "origin/$BASE" 2>/dev/null \
     || [ -n "$(gh pr list --head "$b" --state merged --limit 1 --json number --jq '.[].number' 2>/dev/null)" ]; then
    LOCAL_DELETE="$LOCAL_DELETE $b"
  fi
done
echo "${LOCAL_DELETE:-(none)}"

echo "--- 2. worktrees (remove any on a merged/gone branch) ---"
git worktree list

echo "--- 3. remote branches whose PR is MERGED/CLOSED (dependabot excluded) ---"
REMOTE_DELETE=""
for rb in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | sed 's#^origin/##'); do
  echo "$rb" | grep -qE "$PROT" && continue
  echo "$rb" | grep -qE '^dependabot/' && continue     # Dependabot manages its own branches
  S=$(gh pr list --head "$rb" --state all --limit 1 --json state --jq '.[].state' 2>/dev/null)
  case "$S" in MERGED|CLOSED) REMOTE_DELETE="$REMOTE_DELETE $rb" ;; esac
done
echo "${REMOTE_DELETE:-(none)}"

echo "--- 4. issues still OPEN whose linked PR already merged ---"
ORPHANS=""
for pr in $(gh pr list --state merged --limit 30 --json number --jq '.[].number' 2>/dev/null); do
  for issue in $(gh pr view "$pr" --json closingIssuesReferences --jq '.closingIssuesReferences[].number' 2>/dev/null); do
    [ "$(gh issue view "$issue" --json state --jq '.state' 2>/dev/null)" = "OPEN" ] && ORPHANS="$ORPHANS #${issue}(PR#${pr})"
  done
done
echo "${ORPHANS:-(none)}"

Read the full file on GitHub · 231 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 · 231 lines · 43 tokens per session scan A fbddf2d14e1b

Subscribe to this mod's changes

worktree is a skill published in the GitHub repository psd401/psd-claude-plugins (2 stars, last pushed 9d ago), licensed MIT. It adds 43 tokens to every session and 2,390 once invoked, about $0.0002 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.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

agent-host-chat-contributions

Build and review cross-cutting agent-host chat behavior through lifecycle contributions. Use when adding turn lifecycle side effects, prompt or context injection, restored-history transformation, protocol-action observation, or when reviewing changes that add code to AgentSideEffects or AgentService.

microsoft/vscode · 56 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens