CommandMate: Command for Claude Code

.claude/commands/worktree-cleanup.md

worktree-cleanup is a command for Claude Code from Kewton/CommandMate. It costs 0 tokens per session (2,727 once invoked), scanned A, original, MIT.

A cleanup command for removing the working environment linked to one or more GitHub Issues. It checks the issue numbers, stops issue-specific servers, and performs the documented worktree cleanup and synchronization steps.

In plain words
What is it for?
Use it to clean up one or several issue worktrees and their running servers by supplying their issue numbers.
Why use it?
It helps remove leftover processes and separate working folders after issue work is finished.

Command for Claude Code

Written for Claude Code: installed under .claude/. Also seen: mentions CLAUDE.md; positional $N argument.

This is Kewton/CommandMate's own configuration. It tells Claude Code how to work on CommandMate 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 CommandMate configures →

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is WORKTREE_DIR="../commandmate-issue-${ISSUE_NO}".

Reuse

Borrowing it

Nothing to install: this file belongs to Kewton/CommandMate. 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/Kewton/CommandMate/main/.claude/commands/worktree-cleanup.md
Clone the repo
git clone --depth 1 https://github.com/Kewton/CommandMate

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

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

Your own site · 80×15
<a href="https://agentmods.dev/commands/kewton/commandmate/worktree-cleanup"><img src="https://agentmods.dev/badge/commands/kewton/commandmate/worktree-cleanup.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 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,727 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 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.00000 $0.02727
Opus 5.5 $0.00000 $0.01091
Sonnet 5.5 $0.00000 $0.00545
Haiku 4.5 $0.00000 $0.00273

Measured 1mo ago against content hash bc0c153fa878, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

worktree-cleanup scanned grade A 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 1mo 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.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

curl -s -X POST http://localhost:${CM_PORT:-3000}/api/repositories/sync
.claude/commands/worktree-cleanup.md · 289 lines

How it starts

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

Worktree Cleanup スキル

概要

指定したIssue番号に対応するGit Worktree環境をクリーンアップするスキルです。

使用方法

/worktree-cleanup [Issue番号...]

例:

/worktree-cleanup 135
/worktree-cleanup 187 188 191 193

実行内容

あなたはWorktree環境クリーンアップの専門家です。以下の手順でWorktree環境を安全にクリーンアップしてください。 複数のIssue番号が指定された場合は、各Issueに対してPhase 1〜5を順番に繰り返し実行します。

パラメータ

  • issue_numbers: 対象Issue番号(必須、1つ以上、スペース区切り、各番号は正の整数)

削除しない worktree

CLAUDE.md の「恒久 worktree(クリーンアップ対象外)」に載っている worktree とブランチ (../commandmate-main / main、../commandmate-agent-health / agent-health-runner)は、 このコマンドでも、Issue 番号を指定しない「worktree をまとめて片付けて」という依頼でも、削除・停止しない。 git worktree list から片付け対象を選ぶときは、先にこの一覧を除く。


実行フェーズ

複数Issue指定時: 以下のPhase 1〜6を各Issueに対して順番に実行します。 Phase 7(Worktree同期)は全Issue完了後にまとめて1回実行します。

Phase 1: 入力検証

  1. Issue番号が正の整数であることを確認
  2. Issue番号が1〜2147483647の範囲内であることを確認
# 共通バリデーション関数を読み込み
# Synced with: src/cli/utils/input-validators.ts MAX_ISSUE_NO
source "$(dirname "$0")/../lib/validators.sh"

# Issue番号の検証
if ! validate_issue_no "$ISSUE_NO"; then
  echo "Error: Invalid issue number"
  exit 1
fi

Phase 2: サーバー停止

  1. Issue専用サーバーが起動中か確認(PIDファイルベース)
  2. ポートベースでサーバーを検出(フォールバック)
  3. 起動中の場合は停止
# プロセス管理ユーティリティを読み込み
source "$(dirname "$0")/../lib/process-utils.sh"

# Worktreeの絶対パスを取得
WORKTREE_DIR="../commandmate-issue-${ISSUE_NO}"
WORKTREE_ABS=$(cd "$WORKTREE_DIR" 2>/dev/null && pwd)

# Step 1: PIDファイルベースの検出(既存ロジック)
PID_FILE=~/.commandmate/pids/${ISSUE_NO}.pid

if [ -f "$PID_FILE" ]; then
  PID=$(cat "$PID_FILE")
  if kill -0 "$PID" 2>/dev/null; then
    echo "Stopping server for Issue #${ISSUE_NO} (PID: $PID)..."
    kill "$PID"
    sleep 3
    # 強制終了(必要な場合)
    kill -0 "$PID" 2>/dev/null && kill -9 "$PID"
  fi
  rm -f "$PID_FILE"
fi

# Step 2: ポートベースの検出(フォールバック)
# npm run devで直接起動したサーバーはPIDファイルがないため、ポートで検出
if check_lsof_available && [ -n "$WORKTREE_ABS" ]; then
  # 検出対象ポートの配列を構築
  PORTS_TO_CHECK=(3000)  # デフォルトポート

  # Issue専用ポート(4桁以下のIssue番号のみ)
  # ポート番号上限65535のため、3{issueNo}形式は1-9999まで
  if [ "$ISSUE_NO" -le 9999 ]; then
    PORTS_TO_CHECK+=("3${ISSUE_NO}")
  fi

  # 各ポートをチェック
  for PORT in "${PORTS_TO_CHECK[@]}"; do
    stop_server_by_port "$PORT" "$WORKTREE_ABS" "$ISSUE_NO"
  done
fi

Read the full file on GitHub · 289 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. 1mo ago Changed · +10 lines bc0c153fa878
  2. 1mo ago First seen · 279 lines · 0 tokens per session scan A ee4eeecf7911

Subscribe to this mod's changes

worktree-cleanup is a command published in the GitHub repository Kewton/CommandMate (44 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,727 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.