cleanup-worktrees

cleanup-worktrees is a command for Claude Code from vishnu2kmohan/mcp-server-langgraph. It costs 12 tokens per session (971 once invoked), scanned A, original, MIT.

A command that manages Git worktrees created for Claude Code sessions. A worktree is a separate working directory connected to the same Git repository.

In plain words
What is it for?
Use it after a Claude Code session to list worktrees, review their branches and state, preview cleanup, or remove selected worktrees according to the cleanup option you choose.
Why use it?
It helps identify unused worktrees and separates safe cleanup from worktrees that still contain uncommitted changes.

Command for Claude Code

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/vishnu2kmohan/mcp-server-langgraph/cleanup-worktrees
Clone the repo
git clone --depth 1 https://github.com/vishnu2kmohan/mcp-server-langgraph

Made for: Claude Code.

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 cleanup-worktrees

README.md
[![agentmods](https://agentmods.dev/badge/commands/vishnu2kmohan/mcp-server-langgraph/cleanup-worktrees.svg)](https://agentmods.dev/commands/vishnu2kmohan/mcp-server-langgraph/cleanup-worktrees)
Your own site
<a href="https://agentmods.dev/commands/vishnu2kmohan/mcp-server-langgraph/cleanup-worktrees"><img src="https://agentmods.dev/badge/commands/vishnu2kmohan/mcp-server-langgraph/cleanup-worktrees.svg" alt="Measured on agentmods" height="20"></a>
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 971 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.1 $0.00012 $0.00971
Opus 5 $0.00006 $0.00485
Sonnet 5 $0.00002 $0.00194
Haiku 4.5 $0.00001 $0.00097

Measured 5d ago against content hash e9868a5a3e86, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

cleanup-worktrees 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 5d 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.

.claude/commands/cleanup-worktrees.md · 138 lines

How it starts

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

Cleanup Git Worktrees

Purpose: Manage and cleanup git worktrees created for Claude Code sessions.

When to use: After ending a Claude Code session to clean up old worktrees.


Instructions

You are helping the user cleanup git worktrees created by the start-worktree-session.sh script.

Phase 1: List Worktrees

  1. Run the cleanup script in dry-run mode to show what would be deleted:

    ./scripts/cleanup-worktrees.sh --dry-run
    
  2. Show the user:

    • Total number of worktrees
    • How many are clean (no uncommitted changes)
    • How many are dirty (have uncommitted changes)
    • Details about each worktree (branch, commit, creation date)

Phase 2: Ask User Preference

Ask the user how they want to proceed:

  • Option 1: Delete all clean worktrees automatically
  • Option 2: Interactively choose which worktrees to delete
  • Option 3: Delete ALL worktrees (even with uncommitted changes) - DANGEROUS!
  • Option 4: Keep all worktrees (no deletion)

Phase 3: Execute Cleanup

Based on user's choice:

Option 1 - Auto-delete clean:

./scripts/cleanup-worktrees.sh --auto

Option 2 - Interactive:

./scripts/cleanup-worktrees.sh

Option 3 - Delete all (DANGEROUS):

./scripts/cleanup-worktrees.sh --all --auto

Option 4 - No deletion: Skip execution and inform user that worktrees are preserved.

Phase 4: Summary

After cleanup, show:

  • Number of worktrees deleted
  • Number of worktrees kept
  • Remaining worktrees (if any)
  • Disk space reclaimed (optional)

Important Notes

  1. Clean worktrees: No uncommitted changes, safe to delete
  2. Dirty worktrees: Have uncommitted changes, should preserve unless user explicitly requests deletion
  3. Session worktrees: Only manages worktrees created by start-worktree-session.sh (matching pattern mcp-server-langgraph-session-*)
  4. Main repository: Never deletes the main repository

Examples

Example 1: User wants to cleanup after ending session

User: Cleanup my worktrees
Assistant: I'll check your worktrees and show what can be cleaned up.
[Runs: ./scripts/cleanup-worktrees.sh --dry-run]
[Shows: 3 clean worktrees, 1 dirty worktree]
[Asks: How would you like to proceed?]
[User chooses: Auto-delete clean worktrees]
[Runs: ./scripts/cleanup-worktrees.sh --auto]
[Shows: Deleted 3 worktrees, kept 1 dirty worktree]

Read the full file on GitHub · 138 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. 5d ago First seen · 138 lines · 12 tokens per session scan A e9868a5a3e86

Subscribe to this mod's changes

cleanup-worktrees is a command published in the GitHub repository vishnu2kmohan/mcp-server-langgraph (4 stars, last pushed 5d ago), licensed MIT. It adds 12 tokens to every session and 971 once invoked, about $0.0001 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.