rtk: Command for Claude Code

.claude/commands/tech/remove-worktree.md

remove-worktree is a command for Claude Code from rtk-ai/rtk. It costs 13 tokens per session (1,115 once invoked), scanned C, original, Apache-2.0.

A command for removing one Git worktree, which is a separate working directory connected to a repository. It removes the directory and Git references and can optionally remove the branch.

In plain words
What is it for?
Cleaning up a named feature or fix worktree, such as one created for a new filter or a session bug. It also checks that the requested worktree exists before removing it.
Why use it?
A finished or abandoned worktree can leave files and branch references behind. This command provides checks so the main repository and protected branches are not removed.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter. Also seen: model in frontmatter; positional $N argument.

This is rtk-ai/rtk's own configuration. It tells Claude Code how to work on rtk itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything rtk configures →

About the project

rtk is a command-line proxy that filters and compresses output from development commands before it reaches an LLM's context. It is used with coding agents to reduce the tokens consumed by commands such as Git operations. The catalogue includes skills, commands, agents, and instructions for using rtk in agent workflows.

rtk-ai/rtk · 79,139 stars · on GitHub · rtk-ai.app

Reuse

Borrowing it

Nothing to install: this file belongs to rtk-ai/rtk. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/rtk-ai/rtk/develop/.claude/commands/tech/remove-worktree.md
Clone the repo
git clone --depth 1 https://github.com/rtk-ai/rtk

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 remove-worktree

README.md
[![agentmods](https://agentmods.dev/badge/commands/rtk-ai/rtk/remove-worktree.svg)](https://agentmods.dev/commands/rtk-ai/rtk/remove-worktree)
Your own site
<a href="https://agentmods.dev/commands/rtk-ai/rtk/remove-worktree"><img src="https://agentmods.dev/badge/commands/rtk-ai/rtk/remove-worktree.svg" alt="Measured on agentmods" height="20"></a>
Per session 13 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,115 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.00013 $0.01115
Opus 5 $0.00006 $0.00558
Sonnet 5 $0.00003 $0.00223
Haiku 4.5 $0.00001 $0.00112

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

Security

Grade C, and why

remove-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 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.

rm -rf "$WORKTREE_FULL_PATH"
.claude/commands/tech/remove-worktree.md · 156 lines

How it starts

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

Remove Worktree

Remove a specific worktree, cleaning up directory, git references, and optionally the branch.

Usage

/tech:remove-worktree feature/new-filter
/tech:remove-worktree fix/session-bug

Implementation

Execute this script with branch name from $ARGUMENTS:

#!/bin/bash
set -euo pipefail

BRANCH_NAME="$ARGUMENTS"

if [ -z "$BRANCH_NAME" ]; then
  echo "❌ Usage: /tech:remove-worktree <branch-name>"
  echo ""
  echo "Example:"
  echo "  /tech:remove-worktree feature/new-filter"
  exit 1
fi

echo "🔍 Checking worktree: $BRANCH_NAME"
echo ""

# Check if worktree exists in git
if ! git worktree list | grep -q "$BRANCH_NAME"; then
  echo "❌ Worktree not found: $BRANCH_NAME"
  echo ""
  echo "Available worktrees:"
  git worktree list
  exit 1
fi

# Get worktree path from git
WORKTREE_FULL_PATH=$(git worktree list | grep "$BRANCH_NAME" | awk '{print $1}')

# Safety check: never remove main repo
if [ "$WORKTREE_FULL_PATH" = "$(pwd)" ]; then
  echo "❌ Cannot remove main repository worktree"
  exit 1
fi

# Safety check: never remove master or main
if [ "$BRANCH_NAME" = "master" ] || [ "$BRANCH_NAME" = "main" ]; then
  echo "❌ Cannot remove $BRANCH_NAME (protected branch)"
  exit 1
fi

echo "📂 Worktree path: $WORKTREE_FULL_PATH"
echo "🌿 Branch: $BRANCH_NAME"
echo ""

# Check if branch is merged
IS_MERGED=false
if git branch --merged master | grep -q "^[* ] ${BRANCH_NAME}$"; then
  IS_MERGED=true
  echo "✅ Branch is merged into master (safe to delete)"
else
  echo "⚠️  Branch is NOT merged into master"
fi
echo ""

# Ask confirmation if not merged
if [ "$IS_MERGED" = false ]; then
  echo "⚠️  This will DELETE unmerged work. Continue? [y/N]"
  read -r confirm
  if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
    echo "Aborted."
    exit 0
  fi
fi

# Remove worktree
echo "🗑️  Removing worktree..."
if git worktree remove "$WORKTREE_FULL_PATH" 2>/dev/null; then
  echo "✅ Worktree removed: $WORKTREE_FULL_PATH"
else
  echo "⚠️  Git remove failed, forcing removal..."
  rm -rf "$WORKTREE_FULL_PATH"
  git worktree prune
  echo "✅ Worktree forcefully removed"
fi

# Delete branch
echo ""
echo "🌿 Deleting branch..."
if [ "$IS_MERGED" = true ]; then
  if git branch -d "$BRANCH_NAME" 2>/dev/null; then
    echo "✅ Branch deleted (local): $BRANCH_NAME"
  else
    echo "⚠️  Local branch already deleted or not found"
  fi
else
  if git branch -D "$BRANCH_NAME" 2>/dev/null; then
    echo "✅ Branch force-deleted (local): $BRANCH_NAME"
  else
    echo "⚠️  Local branch already deleted or not found"
  fi
fi

# Delete remote branch (if exists)
echo ""
echo "🌐 Checking remote branch..."
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
  echo "⚠️  Remote branch exists. Delete it? [y/N]"
  read -r confirm_remote
  if [ "$confirm_remote" = "y" ] || [ "$confirm_remote" = "Y" ]; then
    if git push origin --delete "$BRANCH_NAME" --no-verify 2>/dev/null; then
      echo "✅ Remote branch deleted: $BRANCH_NAME"
    else
      echo "❌ Failed to delete remote branch (may require permissions)"
    fi
  else
    echo "⏭️  Skipped remote branch deletion"
  fi
else
  echo "ℹ️  No remote branch found"
fi

echo ""
echo "✅ Cleanup complete!"
echo ""
echo "📊 Remaining worktrees:"
git worktree list

Read the full file on GitHub · 156 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. 8d ago First seen · 156 lines · 13 tokens per session scan C 30827642947b

Subscribe to this mod's changes

remove-worktree is a command published in the GitHub repository rtk-ai/rtk (79,139 stars, last pushed today), licensed Apache-2.0. It adds 13 tokens to every session and 1,115 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.