git-cleanup

A command that scans a Git repository for stale worktrees, local branches, and optionally remote-tracking references. It reports candidates before asking what to remove.

In plain words
What is it for?
Use it to inspect repository clutter, review stale items, and clean selected local or remote-tracking Git references after approval.
Why use it?
It helps identify old Git state while requiring confirmation before cleanup actions that could remove branches or worktrees.

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/damusix/atomic-claude/git-cleanup
Clone the repo
git clone --depth 1 https://github.com/damusix/atomic-claude
Per session 63 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,719 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.00063 $0.02719
Opus 5 $0.00032 $0.01359
Sonnet 5 $0.00013 $0.00544
Haiku 4.5 $0.00006 $0.00272

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

Security

Grade C, and why

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

printf '%s\n' "$live" | grep -qx "$name" || rm -rf "$dir"
context/commands/git-cleanup.md · 241 lines

How it starts

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

You orchestrate git cleanup. A generic subagent runs atomic prompt git-cleanup (read-only scan). You present the report. The user picks. You execute.

Pre-flight

  1. Verify inside a git repo: git rev-parse --is-inside-work-tree. If not: refuse with not in a git repo. and stop.
  2. Determine base branch (used by scout):
    BASE=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null \
      || git config init.defaultBranch \
      || echo main)
    
  3. Determine the orchestrator's current worktree path: git rev-parse --show-toplevel. Scout must skip this from candidates.

Step 1 — Resolve staleness threshold

Default: 30 days.

Check user memory for an override. The auto-memory system stores user preferences. Look for a memory entry whose description mentions "worktree", "branch", or "staleness" threshold. If found and it specifies a different value, use it. Otherwise, use 30.

If during execution the user says something like "remember N days as my staleness threshold" or "I prefer N days", save that as a feedback-type memory before continuing. Future runs pick it up automatically.

Step 2 — Determine scope

If $ARGUMENTS is non-empty: target = .claude/worktrees/<$ARGUMENTS>/ (the specific worktree). Branch + worktree inspected together. Skip step 3 (single-target runs don't need the remote question).

If $ARGUMENTS is empty: target = all. Continue to step 3.

Step 3 — Ask about remote scope

Prompt via AskUserQuestion:

Question: Include remote branches in the staleness scan?
Options:
  - Local only (recommended) — scan .claude/worktrees/* and local branches
  - Local + remote — also fetch and flag stale remote branches (no remote deletion)

Default to local-only if the user is ambiguous.

Step 4 — Dispatch read-only scan subagent

Dispatch a generic subagent via the Agent tool (omit subagent_type or use general-purpose).

Prompt the subagent with:

Run `atomic prompt git-cleanup` and follow the brief it prints exactly.
Scan params for this run:
  staleness_days: <N>
  target: all | .claude/worktrees/<name>/
  include_remote: true | false
  base_branch: <base>
  current_worktree_path: <absolute path>

Apply these params as the brief's staleness/scope/base-branch settings.
Return the full indexed candidate table (worktree candidates + branch candidates
+ summary). Do not execute any git mutations — scan only.

Read the full file on GitHub · 241 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 · 241 lines · 0 tokens per session scan C 9152680fdfe3

Subscribe to this mod's changes

git-cleanup is a command published in the GitHub repository damusix/atomic-claude (83 stars, last pushed 8d ago), licensed MIT. It adds 63 tokens to every session and 2,719 once invoked, about $0.0003 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.