worktree

A command for managing Git worktrees, which are separate working directories linked to one Git repository. It can create, list, switch between, and remove these directories.

In plain words
What is it for?
Use it to create an isolated workspace for a feature, view existing worktrees, switch between them, or remove one when the work is finished.
Why use it?
It keeps feature work isolated, allowing developers to work on separate branches without repeatedly changing the files in their main working directory.

Command

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 commands/lgbarn/shipyard/worktree
Clone the repo
git clone --depth 1 https://github.com/lgbarn/shipyard
Per session 8 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,602 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.00008 $0.01602
Opus 5 $0.00004 $0.00801
Sonnet 5 $0.00002 $0.00320
Haiku 4.5 $0.00001 $0.00160

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

commands/worktree.md · 275 lines

How it starts

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

/shipyard:worktree - Worktree Management

You are executing the Shipyard worktree management workflow. This provides explicit worktree lifecycle management for isolated feature development.

Step 1: Parse Arguments

Parse the subcommand from arguments:

  • create <name> — Create a new worktree for isolated development
  • list — Show all worktrees with status
  • switch <name> — Switch to a worktree directory
  • remove <name> — Remove a worktree after confirmation

If no subcommand is provided, default to list.

Step 2: Validate Git State

  1. Verify this is a git repository: git rev-parse --show-toplevel
  2. If not a git repo, tell the user: "Not a git repository. Initialize with git init first."

Subcommand: create

Step C1: Determine Branch Name

  • Use <name> as provided, or derive from phase context:
    • If .shipyard/STATE.json exists and has a current phase, suggest: phase-{N}-{name}
  • Verify the branch doesn't already exist: git branch --list <name>
  • If it exists, inform the user and ask for an alternative name.

Step C2: Select Worktree Directory

Follow the git-workflow skill's directory selection priority (checks existing dirs, CLAUDE.md prefs, then asks user):

  1. Check existing directories:

    ls -d .worktrees 2>/dev/null
    ls -d worktrees 2>/dev/null
    

    If found, use that directory. If both exist, .worktrees wins.

  2. Check CLAUDE.md:

    grep -i "worktree.*director" CLAUDE.md 2>/dev/null
    

    If preference specified, use it.

  3. Ask user:

    No worktree directory found. Where should I create worktrees?
    
    1. .worktrees/ (project-local, hidden)
    2. ~/.config/shipyard/worktrees/<project-name>/ (global location)
    
    Which would you prefer?
    

Step C3: Verify Safety

For project-local directories (.worktrees or worktrees):

git check-ignore -q <directory> 2>/dev/null

If NOT ignored:

  1. Add the directory to .gitignore
  2. Commit the change: shipyard: add worktree directory to .gitignore
  3. Proceed with creation

Read the full file on GitHub · 275 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 · 275 lines · 8 tokens per session scan A b871c067c540

Subscribe to this mod's changes

worktree is a command published in the GitHub repository lgbarn/shipyard (65 stars, last pushed 1mo ago), licensed MIT. It adds 8 tokens to every session and 1,602 once invoked, about $0.0000 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-30.