worktree.delete

worktree.delete is a command for Claude Code from jjmartres/ai-coding-agents. It costs 17 tokens per session (655 once invoked), scanned A, original, MIT.

A command that removes a Git worktree and its associated branch, either for one named worktree or for worktrees whose pull requests or merge requests are merged. A worktree is a separate folder linked to a repository branch.

In plain words
What is it for?
Use it to delete a specific worktree or clean up all eligible merged worktrees under .worktree/.
Why use it?
It clears finished parallel checkouts and reduces leftover folders and branches. The merged-cleanup mode helps avoid deleting active work by checking branch and review status first.

Command for Claude Code

Written for Claude Code: $ARGUMENTS substitution. Also seen: mentions OpenCode.

Good fit Use it to delete a specific worktree or clean up all eligible merged worktrees under .worktree/.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/jjmartres/ai-coding-agents/worktree.delete
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.

Clone the repo
git clone --depth 1 https://github.com/jjmartres/ai-coding-agents

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/jjmartres/ai-coding-agents/worktree.delete/github.svg)](https://agentmods.dev/commands/jjmartres/ai-coding-agents/worktree.delete)
Your own site
<a href="https://agentmods.dev/commands/jjmartres/ai-coding-agents/worktree.delete"><img src="https://agentmods.dev/badge/commands/jjmartres/ai-coding-agents/worktree.delete/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.delete

Your own site · 80×15
<a href="https://agentmods.dev/commands/jjmartres/ai-coding-agents/worktree.delete"><img src="https://agentmods.dev/badge/commands/jjmartres/ai-coding-agents/worktree.delete.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 17 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 655 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.00017 $0.00655
Opus 5.5 $0.00007 $0.00262
Sonnet 5.5 $0.00003 $0.00131
Haiku 4.5 $0.00002 $0.00065

Measured 18d ago against content hash a17c7da0dbc5, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

worktree.delete 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 18d 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.

shared/.ai-agents/commands/worktree.delete.md · 72 lines

How it starts

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

Worktree Delete Command

Removes an isolated git worktree from .worktree/ and deletes the associated branch. Supports deleting a specific worktree or auto-cleaning all worktrees whose PRs/MRs have been merged.

Instructions for Agent

  1. Parse Arguments:

    • Inspect $ARGUMENTS.
    • Supported modes:
      • Specific branch or folder: e.g. /worktree.delete feature-auth or /worktree.delete .worktree/feature-auth.
      • Merged cleanup: /worktree.delete --merged, /worktree.delete merged, or no argument if asking to prune merged trees.
  2. Handle Merged Worktrees Cleanup (--merged): When cleaning merged trees:

    • Identify default branch (e.g. main or staging): DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' || echo "main")
    • Update remote refs: git fetch --prune
    • Get list of merged branches:
      • Via git: git branch --merged origin/$DEFAULT_BRANCH
      • Via GitLab (if available): glab mr list --state merged
      • Via GitHub (if available): gh pr list --state merged
    • For every worktree located in .worktree/:
      • If its branch is merged:
        • If active OpenCode session is inside this worktree, move session to repository root first:

          await tools.opencode.session_move({ directory: "<repo-root>" });
          
        • Remove worktree: git worktree remove "<worktree-path>" --force

        • Delete local branch: git branch -d "<branch>" || git branch -D "<branch>"

    • Run git worktree prune.
    • Report all deleted worktrees to user.
  3. Handle Specific Worktree Deletion: When targeting a specific branch or directory:

    • Determine target path: .worktree/<branch> (or verify against git worktree list).
    • Check for uncommitted work: git -C "<worktree-path>" status --porcelain
      • If uncommitted changes exist, alert user with summary and confirm deletion.
    • Session Safety:
      • Check if current OpenCode working directory matches the target worktree.
      • If yes, MOVE THE SESSION TO REPOSITORY ROOT FIRST:

Read the full file on GitHub · 72 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. 18d ago First seen · 72 lines · 17 tokens per session scan A a17c7da0dbc5

Subscribe to this mod's changes

worktree.delete is a command published in the GitHub repository jjmartres/ai-coding-agents (49 stars, last pushed 7d ago), licensed MIT. It adds 17 tokens to every session and 655 once invoked, about $0.0001 per session on Opus 5.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-09-28.