worktree-cleanup

worktree-cleanup is a command for Claude Code from sangrokjung/claude-forge. It costs 12 tokens per session (1,132 once invoked), scanned A, original, MIT.

A command for removing a Git worktree, which is a separate working folder linked to the same repository, after its pull request is merged.

In plain words
What is it for?
Use it to inspect worktrees, confirm pull-request status, remove a merged worktree, and delete its local and remote branch.
Why use it?
It helps prevent leftover worktree folders and branches from accumulating. It also checks for open pull requests and unfinished checklist items before cleanup.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the claude-forge plugin — 33 skills, 39 commands, 17 agents shipped together

Good fit Use it to inspect worktrees, confirm pull-request status, remove a merged worktree, and delete its local and remote branch.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/sangrokjung/claude-forge/worktree-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/sangrokjung/claude-forge

Made for: Claude Code.

Or install claude-forge, the plugin that ships this one along with the rest of its 33 skills, 39 commands, 17 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 worktree-cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/sangrokjung/claude-forge/worktree-cleanup.svg)](https://agentmods.dev/commands/sangrokjung/claude-forge/worktree-cleanup)
Your own site
<a href="https://agentmods.dev/commands/sangrokjung/claude-forge/worktree-cleanup"><img src="https://agentmods.dev/badge/commands/sangrokjung/claude-forge/worktree-cleanup.svg" alt="Measured on agentmods" height="20"></a>
Per session 12 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,132 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.00012 $0.01132
Opus 5 $0.00006 $0.00566
Sonnet 5 $0.00002 $0.00226
Haiku 4.5 $0.00001 $0.00113

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

Security

Grade A, and why

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

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.

commands/worktree-cleanup.md · 185 lines

How it starts

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

Task

0단계: 환경 확인

git rev-parse --git-dir
git worktree list
git branch --show-current
pwd

1단계: 정리 대상 결정

$ARGUMENTS 있으면:

  • 해당 브랜치의 워크트리 찾기

$ARGUMENTS 없으면:

  • 현재 디렉토리가 워크트리인지 확인
  • 메인 레포면:
    ❓ 정리할 워크트리를 지정하세요.
    
    현재 워크트리 목록:
    [git worktree list 결과]
    
    사용법: /worktree-cleanup feature/auth
    
    → 중단

2단계: PR 상태 확인

gh pr view --json state,mergedAt 2>/dev/null

PR이 머지됨: → 정리 진행

PR이 아직 열려있음:

⚠️ PR이 아직 머지되지 않았습니다.

PR 상태: [Open/Draft]
PR URL: [URL]

옵션:
1. "계속" - 강제 정리 (변경사항 유실 주의)
2. "취소" - PR 머지 후 다시 시도

PR 없음 (gh CLI 없거나 PR 미생성):

⚠️ PR 상태를 확인할 수 없습니다.

변경사항이 push 되었는지 확인하세요:
  git log origin/[브랜치]..HEAD

옵션:
1. "계속" - 강제 정리
2. "취소" - 확인 후 다시 시도

3단계: 워크트리 정리

현재 워크트리에서 실행 중이면:

⚠️ 현재 워크트리에서는 정리할 수 없습니다.

메인 레포로 이동 후 실행하세요:
  cd [메인 레포 경로]
  /worktree-cleanup [브랜치명]

→ 중단

메인 레포에서 실행:

# 워크트리 제거
git worktree remove [워크트리 경로]

# 머지된 브랜치면 삭제
git branch -d [브랜치명]

# 원격 브랜치도 삭제 (머지된 경우)
git push origin --delete [브랜치명] 2>/dev/null || true

3.5단계: 체크리스트 상태 정리

워크트리 내 .claude/web-checklist-state.json 확인:

파일 있으면:

  • 완료율 읽기
  • 미완료 항목 있으면 경고
📋 체크리스트 상태: [completion]% ([done]/[total])

미완료 항목이 있으면:

⚠️ 미완료 체크리스트 항목 [N]개:
  - [ID:N] [text]
  - [ID:N] [text]

워크트리 정리 후에는 복구할 수 없습니다.

4단계: 워크트리 통계 수집

워크트리 세션 동안의 작업 통계:

# 워크트리 브랜치의 커밋 수
git log --oneline [base]...[branch] | wc -l

# 변경 파일 수
git diff [base]...[branch] --stat | tail -1

5단계: 완료 안내

════════════════════════════════════════════════════════════════
✅ Worktree Cleanup Complete (v6)
════════════════════════════════════════════════════════════════

🗑️ 삭제: [워크트리 경로]
🌿 브랜치: [브랜치명] (deleted)

📊 워크트리 통계:
  커밋 수: [N]
  변경 파일: [N]
  추가/삭제: +[N] / -[N]

남은 워크트리:
[git worktree list 결과]

다음:
  /worktree-start [새 기능] | /next-task
════════════════════════════════════════════════════════════════

에러 처리

워크트리에 커밋되지 않은 변경사항:

❌ 커밋되지 않은 변경사항이 있습니다.

[git status 결과]

옵션:
1. 변경사항 커밋 후 다시 시도
2. 강제 삭제: git worktree remove --force [경로]

Read the full file on GitHub · 185 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 · 185 lines · 12 tokens per session scan A 5f50790dbbf0

Subscribe to this mod's changes

worktree-cleanup is a command published in the GitHub repository sangrokjung/claude-forge (824 stars, last pushed 4d ago), licensed MIT. It adds 12 tokens to every session and 1,132 once invoked, about $0.0001 per session on Opus 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.