finish-branch-cleanup

finish-branch-cleanup is a command for Claude Code from axiomantic/spellbook. It costs 20 tokens per session (477 once invoked), scanned C, original, MIT.

A command for removing a Git worktree after a development branch has been merged or deliberately discarded. A worktree is a separate directory containing a checkout of a branch.

In plain words
What is it for?
Use it to clean up worktrees after local integration or discard, while leaving active or parked branch work in place.
Why use it?
It avoids deleting the wrong directory by checking the current worktree first, and warns about uncommitted changes before removal. Branches kept for pull requests or later work remain untouched.

Command for Claude Code

Written for Claude Code: a Claude Code command (commands/*.md).

Good fit Use it to clean up worktrees after local integration or discard, while leaving active or parked branch work in place.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/axiomantic/spellbook/finish-branch-cleanup
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/axiomantic/spellbook

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 finish-branch-cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/axiomantic/spellbook/finish-branch-cleanup/github.svg)](https://agentmods.dev/commands/axiomantic/spellbook/finish-branch-cleanup)
Your own site
<a href="https://agentmods.dev/commands/axiomantic/spellbook/finish-branch-cleanup"><img src="https://agentmods.dev/badge/commands/axiomantic/spellbook/finish-branch-cleanup/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 finish-branch-cleanup

Your own site · 80×15
<a href="https://agentmods.dev/commands/axiomantic/spellbook/finish-branch-cleanup"><img src="https://agentmods.dev/badge/commands/axiomantic/spellbook/finish-branch-cleanup.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 20 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 477 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.00020 $0.00477
Opus 5 $0.00010 $0.00238
Sonnet 5 $0.00004 $0.00095
Haiku 4.5 $0.00002 $0.00048

Measured 8d ago against content hash 2fd9b3306c11, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade C, and why

finish-branch-cleanup 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 8d 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.

- Force-removing a worktree (`git worktree remove --force`, `rm -rf`) without explicit user confirmation
commands/finish-branch-cleanup.md · 57 lines

What it actually says

Step 5: Cleanup Worktree

Invariant Principles

  1. Options 2, 3, and 4 mean hands off — pushed, mid-flight, and parked work keeps its worktree; cleanup runs only for Options 1 and 5
  2. Detect before deleting — Verify you are in a worktree before running removal commands
  3. Uncommitted changes are a red flag — Warn before removing a worktree with uncommitted changes

Applicability

Option Cleanup Worktree?
1. Merge locally Yes
2. Create PR NO — Keep worktree intact
3. Create PR + PR dance NO — Keep worktree intact
4. Keep as-is NO — Keep worktree intact
5. Discard Yes

Cleanup Procedure (Options 1, 5)

Detect if currently in a worktree:

git worktree list | grep $(git branch --show-current)

If output is empty: not in a worktree. Report: "No worktree detected. Nothing to remove."

If output is non-empty: the first field of the matching line is the worktree path. Remove it:

git worktree remove <worktree-path>

Report final state: "Worktree at <path> removed. Integration complete."

<FINAL_EMPHASIS> Clean integration means no surprises: detect before acting, warn on anomalies, never destroy work without permission. </FINAL_EMPHASIS>

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. 8d ago First seen · 57 lines · 20 tokens per session scan C 2fd9b3306c11

Subscribe to this mod's changes

finish-branch-cleanup is a command published in the GitHub repository axiomantic/spellbook (10 stars, last pushed yesterday), licensed MIT. It adds 20 tokens to every session and 477 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.