cleanup

cleanup is a command for Claude Code from ai-sdlc-framework/ai-sdlc. It costs 30 tokens per session (1,020 once invoked), scanned A, original, Apache-2.0.

A command that removes Git worktrees after their pull requests are merged, or removes one specified worktree when given a task ID. A worktree is a separate working folder connected to the same Git repository.

In plain words
What is it for?
For sweeping merged worktrees, checking their pull-request status through GitHub, force-removing a chosen task worktree, and cleaning up obsolete worktree markers.
Why use it?
It clears folders that are no longer needed and removes an old project marker left by earlier versions of the workflow.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: model in frontmatter; mentions CLAUDE.md.

Part of the ai-sdlc plugin — 1 skill, 23 commands, 14 agents shipped together

Good fit For sweeping merged worktrees, checking their pull-request status through GitHub, force-removing a chosen task worktree, and cleaning up obsolete worktree markers.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/ai-sdlc-framework/ai-sdlc/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/ai-sdlc-framework/ai-sdlc

Made for: Claude Code.

Or install ai-sdlc, the plugin that ships this one along with the rest of its 1 skill, 23 commands, 14 agents.

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 cleanup

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

Your own site · 80×15
<a href="https://agentmods.dev/commands/ai-sdlc-framework/ai-sdlc/cleanup"><img src="https://agentmods.dev/badge/commands/ai-sdlc-framework/ai-sdlc/cleanup.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 30 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,020 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.00030 $0.01020
Opus 5.5 $0.00012 $0.00408
Sonnet 5.5 $0.00006 $0.00204
Haiku 4.5 $0.00003 $0.00102

Measured today against content hash 2127cff3d755, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cleanup scanned grade A with 0 findings 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 today.

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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

ai-sdlc-plugin/commands/cleanup.md · 80 lines

How it starts

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

Companion to /ai-sdlc execute. Two modes:

Mode 1 — Sweep all merged worktrees (no arguments)

When $ARGUMENTS is empty, do exactly what /ai-sdlc execute does at start: walk .worktrees/, check each branch's PR status via gh pr list, remove any whose PR has merged. Also remove the legacy project-level .worktrees/.active-task sentinel if present — it's no longer written by /ai-sdlc execute (per-worktree sentinels replaced it in AISDLC-81) and would only ever be a leftover from a much older run. Per-worktree .active-task files inside each worktree directory are removed automatically when git worktree remove deletes the worktree.

# Clear the legacy project-level sentinel if it still exists. Safe to delete:
# /ai-sdlc execute now writes per-worktree sentinels at .worktrees/<id>/.active-task
# instead of the project-level path.
rm -f .worktrees/.active-task

if [ ! -d .worktrees ]; then
  echo "No .worktrees/ directory — nothing to sweep."
  exit 0
fi

REMOVED=0
for wt in .worktrees/*/; do
  [ -d "$wt" ] || continue
  WT_BRANCH=$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null)
  [ -z "$WT_BRANCH" ] && continue
  [ "$WT_BRANCH" = "HEAD" ] && continue
  MERGED_AT=$(gh pr list --head "$WT_BRANCH" --state merged --json mergedAt --jq '.[0].mergedAt' 2>/dev/null)
  if [ -n "$MERGED_AT" ] && [ "$MERGED_AT" != "null" ]; then
    echo "Removing $wt (branch $WT_BRANCH merged at $MERGED_AT)"
    # The per-worktree .active-task sentinel (if any) is removed atomically
    # with the worktree itself.
    git worktree remove --force "$wt" 2>/dev/null || true
    REMOVED=$((REMOVED + 1))
  fi
done
echo "Swept $REMOVED merged worktree(s)."

Mode 2 — Force-remove a specific task's worktree

When $ARGUMENTS is a task ID (e.g. AISDLC-68), remove that worktree regardless of PR status. Useful for retries after a failed /ai-sdlc execute that left state behind.

TASK_ID_LOWER=$(echo "$ARGUMENTS" | tr '[:upper:]' '[:lower:]')
WORKTREE_PATH=".worktrees/$TASK_ID_LOWER"
if [ ! -d "$WORKTREE_PATH" ]; then
  echo "No worktree at $WORKTREE_PATH — nothing to clean up."
  exit 0
fi

# Capture the branch name before removing so we can remind the operator.
BRANCH=$(git -C "$WORKTREE_PATH" rev-parse --abbrev-ref HEAD 2>/dev/null)

# git worktree remove --force deletes the entire worktree directory, which
# includes the per-worktree .active-task sentinel written by /ai-sdlc execute
# Step 4. No separate `rm` needed — the sentinel goes with the worktree.
git worktree remove --force "$WORKTREE_PATH"
echo "Removed worktree $WORKTREE_PATH (was on branch $BRANCH)."

# Branch deletion is destructive and may erase work — leave it to the operator.
echo ""
echo "The branch '$BRANCH' is still present locally and possibly on origin."
echo "If you want to delete it: git branch -D '$BRANCH' && git push origin --delete '$BRANCH'"
echo "(NOT done automatically — branch deletion is operator-controlled per CLAUDE.md.)"

Read the full file on GitHub · 80 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. today Changed · +2 lines 2127cff3d755
  2. 4d ago Changed · -10 lines 9d1ac7323bd4
  3. 8d ago Changed 55dcabc323ab
  4. 10d ago Changed · +11 lines 33a683d58dba
  5. 1mo ago First seen · 77 lines · 30 tokens per session scan A f3495c501981

Subscribe to this mod's changes

cleanup is a command published in the GitHub repository ai-sdlc-framework/ai-sdlc (415 stars, last pushed yesterday), licensed Apache-2.0. It adds 30 tokens to every session and 1,020 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.