worktree

worktree is a command for Claude Code from MadAppGang/magus. It costs 31 tokens per session (2,077 once invoked), scanned C, original, MIT.

A command for creating, listing, and cleaning up git worktrees, which are separate working folders for different branches.

In plain words
What is it for?
Setting up branch workspaces, installing dependencies, running baseline tests, and isolating schema changes.
Why use it?
It keeps parallel branch work isolated and can also prepare a separate database branch when the project uses a supported provider.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: names the AskUserQuestion tool.

Runs only inside its plugin — its command needs a path that Claude Code sets for a plugin’s own hooks and for nothing else. Install the plugin, not this.

Part of the dev plugin — 19 skills, 15 commands, 12 agents shipped together

Good fit Setting up branch workspaces, installing dependencies, running baseline tests, and isolating schema changes.

Compare 6 commands from other repositories ↓
Install

Getting it into your agent

This one installs as part of its plugin. Adding the marketplace and installing the plugin brings it with everything else the plugin ships.

Claude Code
/plugin marketplace add MadAppGang/magus
Claude Code
/plugin install dev

Made for: Claude Code.

Or install dev, the plugin that ships this one along with the rest of its 19 skills, 15 commands, 12 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/magus/worktree/github.svg)](https://agentmods.dev/commands/madappgang/magus/worktree)
Your own site
<a href="https://agentmods.dev/commands/madappgang/magus/worktree"><img src="https://agentmods.dev/badge/commands/madappgang/magus/worktree/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for worktree

Your own site · 80×15
<a href="https://agentmods.dev/commands/madappgang/magus/worktree"><img src="https://agentmods.dev/badge/commands/madappgang/magus/worktree.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,077 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00031 $0.02077
Opus 5.5 $0.00012 $0.00831
Sonnet 5.5 $0.00006 $0.00415
Haiku 4.5 $0.00003 $0.00208

Measured 22d ago against content hash 77f3f8a11951, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 22d 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.

- NEVER use `rm -rf` on worktree directories
plugins/dev/commands/worktree.md · 270 lines

How it starts

The opening of the file, as written. The whole thing — 270 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 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 3.5: Database Branch (if applicable)
   - Detect database provider from .env (neon.tech, turso.io, supabase.co)
   - If branchable provider detected, ask user if branch involves schema changes
   - If yes: create DB branch, get connection string, patch .env, write .db-branch.json
   - Follow `${CLAUDE_PLUGIN_ROOT}/skills/backend/db-branching/SKILL.md` (read the
     file) for the provider-specific procedure
7. Execute Phase 4: Setup
   - Detect stacks (nodejs, rust, golang, python, ruby)
   - Install dependencies for each stack
   - If Neon branch created: run schema push command against branch
   - Run baseline tests
8. Execute Phase 5: Handoff
   - Display worktree information
   - Show path, branch, stacks, test results
   - If Neon branch: show Neon branch ID and isolation status

Output format:
```
Worktree created successfully!

Path: .worktrees/{slug}
Branch: {branch-name}
Stacks: {detected-stacks}
Tests: {passing} passing, {failing} failing
Neon Branch: {branch-id} (from {parent}) | (none)
Database: Isolated | Shared (production)

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. For each worktree, check for `.db-branch.json` to detect Neon branches
4. Format as table:

```
Active Worktrees:

Path                          Branch              Commit    Neon Branch
──────────────────────────────────────────────────────────────────────────
/path/to/project              main                abc1234   production
/path/to/.worktrees/feature   feature/auth        def5678   br-dark-sky-a8xyz123
/path/to/.worktrees/hotfix    hotfix/login        ghi9012   (none)
```

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 the worktree-lifecycle skill's 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
   - Check for `.db-branch.json` in worktree root
   - If database branch exists, follow the cleanup in
     `${CLAUDE_PLUGIN_ROOT}/skills/backend/db-branching/SKILL.md`:
     - Ask user about schema migration (apply to production / discard / keep)
     - If applying: merge code first, then run schema push in main worktree
     - Delete database branch via provider-specific method (MCP or CLI)
   - Remove worktree with `git worktree remove`
   - Optionally delete branch (only if merged)

Read the full file on GitHub · 270 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. 22d ago Changed · -8 lines 77f3f8a11951
  2. 23d ago Changed · +1 lines bd5ca10ac85b
  3. 1mo ago First seen · 277 lines · 31 tokens per session scan C bee041263a37

Subscribe to this mod's changes

worktree is a command published in the GitHub repository MadAppGang/magus (13 stars, last pushed today), licensed MIT. It adds 31 tokens to every session and 2,077 once invoked, about $0.0001 per session on Opus 5.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-04.