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.
npx agentmods add commands/brain-bootstrap/claude-code-brain-bootstrap/clean-worktreesgit clone --depth 1 https://github.com/brain-bootstrap/claude-code-brain-bootstrapWhat 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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00018 | $0.01221 |
| Opus 5 | $0.00009 | $0.00611 |
| Sonnet 5 | $0.00004 | $0.00244 |
| Haiku 4.5 | $0.00002 | $0.00122 |
Grade C, and why
clean-worktrees 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.
rm -rf "$path" 2>/dev/null || true How it starts
The opening of the file, as written. The whole thing — 170 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Clean Worktrees (Automatic)
Automatically remove all worktrees for branches merged into the default branch (main or master). No interaction required.
Usage
/clean-worktrees # Remove all merged worktrees
/clean-worktrees --dry-run # Preview what would be deleted
Implementation
Execute this script:
#!/bin/bash
set -euo pipefail
DRY_RUN=false
if [[ "${ARGUMENTS:-}" == *"--dry-run"* ]]; then
DRY_RUN=true
fi
# Detect default branch (main or master)
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|.*/||' || \
git branch --list main master 2>/dev/null | head -1 | xargs || \
echo "main")
echo "Cleaning Worktrees"
echo "=================="
echo "Default branch: $DEFAULT_BRANCH"
echo ""
# Step 1: Prune stale git references
echo "1. Pruning stale git references..."
PRUNED=$(git worktree prune -v 2>&1)
if [ -n "$PRUNED" ]; then
echo "$PRUNED"
echo "Stale references pruned"
else
echo "No stale references found"
fi
echo ""
# Step 2: Find merged worktrees
echo "2. Finding merged worktrees..."
MERGED_COUNT=0
MERGED_BRANCHES=()
CURRENT_DIR="$(pwd)"
while IFS= read -r line; do
path=$(echo "$line" | awk '{print $1}')
branch=$(echo "$line" | grep -oE '\[.*\]' | tr -d '[]' || true)
[ -z "$branch" ] && continue
[ "$branch" = "master" ] && continue
[ "$branch" = "main" ] && continue
[ "$path" = "$CURRENT_DIR" ] && continue
if git branch --merged "$DEFAULT_BRANCH" 2>/dev/null | grep -q "^[* ] ${branch}$"; then
MERGED_COUNT=$((MERGED_COUNT + 1))
MERGED_BRANCHES+=("$branch|$path")
echo " - $branch (merged)"
fi
done < <(git worktree list)
if [ $MERGED_COUNT -eq 0 ]; then
echo "No merged worktrees found"
echo ""
echo "Current worktrees:"
git worktree list
exit 0
fi
echo ""
echo "Found $MERGED_COUNT merged worktree(s)"
echo ""
if [ "$DRY_RUN" = true ]; then
echo "DRY RUN - No changes will be made"
echo ""
echo "Would delete:"
for item in "${MERGED_BRANCHES[@]}"; do
branch=$(echo "$item" | cut -d'|' -f1)
path=$(echo "$item" | cut -d'|' -f2)
echo " - $branch"
echo " Path: $path"
done
echo ""
echo "Run without --dry-run to actually delete"
exit 0
fi
# Step 3: Remove merged worktrees
echo "3. Removing merged worktrees..."
REMOVED_COUNT=0
for item in "${MERGED_BRANCHES[@]}"; do
branch=$(echo "$item" | cut -d'|' -f1)
path=$(echo "$item" | cut -d'|' -f2)
echo ""
echo "Removing: $branch"
if git worktree remove "$path" 2>/dev/null; then
echo " Worktree removed"
else
echo " Git remove failed, forcing..."
rm -rf "$path" 2>/dev/null || true
git worktree prune 2>/dev/null || true
echo " Worktree forcefully removed"
fi
if git branch -d "$branch" 2>/dev/null; then
echo " Local branch deleted"
else
echo " Local branch already deleted"
fi
if git ls-remote --heads origin "$branch" 2>/dev/null | grep -q "$branch"; then
echo " Remote branch exists: origin/$branch (not auto-deleted)"
fi
REMOVED_COUNT=$((REMOVED_COUNT + 1))
done
echo ""
echo "Cleanup complete"
echo ""
echo "Summary:"
echo " Removed: $REMOVED_COUNT worktree(s)"
echo ""
echo "Remaining worktrees:"
git worktree list
echo ""
WORKTREES_SIZE=$(du -sh .worktrees/ 2>/dev/null | awk '{print $1}' || echo "N/A")
echo "Worktrees disk usage: $WORKTREES_SIZE"
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.
- 2d ago First seen · 170 lines · 18 tokens per session scan C b7aa1940100b
clean-worktrees is a command published in the GitHub repository brain-bootstrap/claude-code-brain-bootstrap (11 stars, last pushed 4mo ago), licensed MIT. It adds 18 tokens to every session and 1,221 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.
Other commands, from other repositories
restart
Restart the claude-mnemonic worker process. Use this command when experiencing issues with the memory system.
git
Git operations with intelligent commit messages and workflow optimization.
checklist
Generate a custom checklist for the current feature based on user requirements.
clarify
Identify underspecified areas in the current feature spec by asking up to 5 highly targeted clarification questions and encoding answers back into the spec.
specify
Create or update the feature specification from a natural language feature description.
analyze
Perform a non-destructive cross-artifact consistency and quality analysis across spec.md, plan.md, and tasks.md after task generation.