git-worktree-remove

A safety-focused command for removing one Git worktree, which is a separate working folder connected to the same repository, along with its branch when appropriate. It checks protected branches, unmerged work, uncommitted changes, and related database resources.

In plain words
What is it for?
Removing a worktree, optionally deleting its local or remote branch, reminding you about database branch cleanup, and pruning stale Git references.
Why use it?
It reduces the risk of deleting active work or an important branch while cleaning up temporary development folders.

Command

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/florianbruniaux/claude-code-plugins/git-worktree-remove
Clone the repo
git clone --depth 1 https://github.com/FlorianBruniaux/claude-code-plugins
Per session 18 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,455 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.00018 $0.01455
Opus 5 $0.00009 $0.00727
Sonnet 5 $0.00004 $0.00291
Haiku 4.5 $0.00002 $0.00145

Measured 2d ago against content hash fa7c10769584, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

git-worktree-remove 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 2d 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.

**Using `rm -rf` instead of `git worktree remove`**
plugins/devops-pipeline/commands/git-worktree-remove.md · 190 lines

How it starts

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

Git Worktree Remove

Safely remove a single git worktree with branch cleanup, merge verification, and database branch teardown.

Core principle: Safety checks first, then clean removal of worktree + branch + DB resources.

Part of: Worktree Lifecycle Suite | /git-worktree | /git-worktree-status | /git-worktree-clean

Process

  1. Validate Target: Identify worktree to remove
  2. Safety Check: Protect main/develop branches
  3. Check Merge Status: Warn if branch has unmerged changes
  4. Check Uncommitted Changes: Warn if worktree has dirty state
  5. Remove Worktree: git worktree remove
  6. Delete Local Branch: git branch -d (or -D with confirmation)
  7. Delete Remote Branch: git push origin --delete (with confirmation)
  8. Database Cleanup Reminder: Suggest DB branch deletion if applicable
  9. Prune References: git worktree prune

Safety Checks

Protected Branches

# Never remove worktrees for these branches (configurable)
PROTECTED_BRANCHES="main master develop staging production"

if echo "$PROTECTED_BRANCHES" | grep -qw "$BRANCH"; then
  echo "BLOCKED: Cannot remove worktree for protected branch '$BRANCH'"
  echo "Protected branches: $PROTECTED_BRANCHES"
  exit 1
fi

Uncommitted Changes

cd "$WORKTREE_PATH"
if [ -n "$(git status --porcelain)" ]; then
  echo "WARNING: Worktree has uncommitted changes:"
  git status --short
  echo ""
  echo "Options:"
  echo "  1. Commit changes first"
  echo "  2. Force remove (--force)"
  echo "  3. Cancel"
  # Wait for user decision
fi

Merge Status

# Check if branch is merged into main
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')

if git merge-base --is-ancestor "$BRANCH" "$MAIN_BRANCH" 2>/dev/null; then
  echo "Branch '$BRANCH' is merged into $MAIN_BRANCH. Safe to delete."
  MERGED=true
else
  echo "WARNING: Branch '$BRANCH' is NOT merged into $MAIN_BRANCH."
  echo "You may lose work if you delete this branch."
  MERGED=false
fi

Read the full file on GitHub · 190 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. 2d ago First seen · 190 lines · 18 tokens per session scan C fa7c10769584

Subscribe to this mod's changes

git-worktree-remove is a command published in the GitHub repository FlorianBruniaux/claude-code-plugins (40 stars, last pushed 2mo ago), licensed MIT. It adds 18 tokens to every session and 1,455 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-08-30.