worktree

worktree is a command for coding agents from MadAppGang/claude-code. It costs 21 tokens per session (1,770 once invoked), scanned C, original, MIT.

A command for managing Git worktrees, which are separate working directories connected to the same repository. It creates, lists, and cleans up isolated workspaces for branches.

In plain words
What is it for?
It is for starting branch-specific workspaces, preparing their dependencies, running baseline tests, and showing the resulting branch and directory details.
Why use it?
It avoids switching one directory back and forth between branches and helps keep parallel work separated. It also checks the workspace and project setup before handing over the new worktree.

Command

Part of the dev plugin — 47 skills, 12 commands, 14 agents shipped together

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/madappgang/claude-code/worktree
Clone the repo
git clone --depth 1 https://github.com/MadAppGang/claude-code

Or install dev, the plugin that ships this one along with the rest of its 47 skills, 12 commands, 14 agents.

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 worktree

README.md
[![agentmods](https://agentmods.dev/badge/commands/madappgang/claude-code/worktree.svg)](https://agentmods.dev/commands/madappgang/claude-code/worktree)
Your own site
<a href="https://agentmods.dev/commands/madappgang/claude-code/worktree"><img src="https://agentmods.dev/badge/commands/madappgang/claude-code/worktree.svg" alt="Measured on agentmods" height="20"></a>
Per session 21 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,770 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.00021 $0.01770
Opus 5 $0.00010 $0.00885
Sonnet 5 $0.00004 $0.00354
Haiku 4.5 $0.00002 $0.00177

Measured yesterday against content hash 310488fb6600, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

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

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 use `rm -rf` on worktree directories
plugins/dev/commands/worktree.md · 256 lines

How it starts

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

<user_request> $ARGUMENTS </user_request>

Create a new worktree following the dev:worktree-lifecycle skill phases 1-5.

Steps:
1. If branch-name not provided, ask user for branch name
2. Use AskUserQuestion to ask for worktree directory (or use .worktrees/ default)
3. Execute Phase 1: Pre-flight Checks
   - Verify git repository
   - Check branch availability
   - Check path availability
4. Execute Phase 2: Directory Selection (use provided or ask)
5. Execute Phase 3: Creation
   - Verify .gitignore
   - Create worktree with `git worktree add`
   - Store original CWD
6. Execute Phase 4: Setup
   - Detect stacks (nodejs, rust, golang, python, ruby)
   - Install dependencies for each stack
   - Run baseline tests
7. Execute Phase 5: Handoff
   - Display worktree information
   - Show path, branch, stacks, test results
8. Write worktree context marker for statusline persistence
   - Get Claude Code session ID (if available from environment or session context)
   - Write marker file to `~/.claude/.statusline-worktree-{SESSION_ID}`:
     ```json
     {
       "worktree_path": ".worktrees/{slug}",
       "branch": "{branch-name}",
       "worktree_name": "{slug}"
     }
     ```
   - This marker survives context compaction and ensures the statusline
     continues showing worktree info after long-running operations

Output format:
```
Worktree created successfully!

Path: .worktrees/{slug}
Branch: {branch-name}
Stacks: {detected-stacks}
Tests: {passing} passing, {failing} failing

To work in this worktree:
  cd .worktrees/{slug}

To clean up later:
  /dev:worktree cleanup .worktrees/{slug}
```
Show all active worktrees in this repository.

Steps:
1. Run `git worktree list --porcelain`
2. Parse output to extract:
   - Worktree path
   - Branch name
   - HEAD commit
   - Locked status
3. Format as table:

```
Active Worktrees:

Path                          Branch              Commit
────────────────────────────────────────────────────────────
/path/to/project              main                abc1234
/path/to/.worktrees/feature   feature/auth        def5678
/path/to/.worktrees/hotfix    hotfix/login        ghi9012
```

If no worktrees besides main:
```
No additional worktrees found.
Only main worktree is active.

Create a worktree with: /dev:worktree create [branch-name]
```
Remove a worktree following dev:worktree-lifecycle Phase 6.

Steps:
1. If path not provided, list available worktrees and ask which to clean up
2. Execute Phase 6 cleanup:
   - Return to original CWD if currently in worktree
   - Check for uncommitted changes
   - If uncommitted changes:
     Use AskUserQuestion:
       question: "Uncommitted changes found. How to proceed?"
       options:
         - Commit now
         - Stash changes
         - Discard changes
         - Abort cleanup
   - Remove worktree with `git worktree remove`
   - Remove statusline worktree marker: `rm -f ~/.claude/.statusline-worktree-*`
     (clean all markers for this project to avoid stale files)
   - Optionally delete branch (only if merged)

Read the full file on GitHub · 256 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. yesterday First seen · 256 lines · 21 tokens per session scan C 310488fb6600

Subscribe to this mod's changes

worktree is a command published in the GitHub repository MadAppGang/claude-code (279 stars, last pushed 5mo ago), licensed MIT. It adds 21 tokens to every session and 1,770 once invoked, about $0.0001 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-09-03.