Skip to main content
ClaudeWave
Slash Command745 estrellas del repoactualizado 24d ago

worktree-cleanup

The worktree-cleanup slash command removes Git worktrees and their associated branches after pull requests are merged. Use this command from the main repository to safely delete feature branch worktrees, with built-in checks for unmerged PRs, uncommitted changes, and incomplete checklists before cleanup proceeds.

Instalar en Claude Code
Copiar
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/sangrokjung/claude-forge/HEAD/commands/worktree-cleanup.md -o ~/.claude/commands/worktree-cleanup.md
Después abre una sesión nueva de Claude Code; el slash command carga automáticamente.

worktree-cleanup.md

## Task

### 0단계: 환경 확인

```bash
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 상태 확인

```bash
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 [브랜치명]
```
→ 중단

**메인 레포에서 실행:**
```bash
# 워크트리 제거
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단계: 워크트리 통계 수집

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

```bash
# 워크트리 브랜치의 커밋 수
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 [경로]
```

**브랜치가 머지되지 않음 (삭제 실패):**
```
⚠️ 브랜치가 머지되지 않아 삭제하지 않았습니다.

워크트리만 삭제되었습니다.
브랜치 강제 삭제: git branch -D [브랜치명]
```

---

## 사용 예시

```bash
# 현재 워크트리 정리 (메인 레포에서)
/worktree-cleanup feature/auth

# 브랜치명으로 정리
/worktree-cleanup fix/login-bug

# 워크트리 목록 확인 후 정리
git worktree list
/worktree-cleanup [대상 브랜치]
```
architectSubagent

Software architecture specialist for system design, scalability, and technical decision-making. Use PROACTIVELY when planning new features, refactoring large systems, or making architectural decisions.

build-error-resolverSubagent

Build and TypeScript error resolution specialist. Use PROACTIVELY when build fails or type errors occur. Fixes build/type errors only with minimal diffs, no architectural edits. Focuses on getting the build green quickly.

code-reviewerSubagent

Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code. MUST BE USED for all code changes.

database-reviewerSubagent

PostgreSQL database specialist for query optimization, schema design, security, and performance. Use PROACTIVELY when writing SQL, creating migrations, designing schemas, or troubleshooting database performance. Incorporates Supabase best practices.

doc-updaterSubagent

Documentation and codemap specialist. Use PROACTIVELY for updating codemaps and documentation. Runs /update-codemaps and /update-docs, generates docs/CODEMAPS/*, updates READMEs and guides.

e2e-runnerSubagent

End-to-end testing specialist using Vercel Agent Browser (preferred) with Playwright fallback. Use PROACTIVELY for generating, maintaining, and running E2E tests. Manages test journeys, quarantines flaky tests, uploads artifacts (screenshots, videos, traces), and ensures critical user flows work.

plannerSubagent

Expert planning specialist for complex features and refactoring. Use PROACTIVELY when users request feature implementation, architectural changes, or complex refactoring. Automatically activated for planning tasks.

refactor-cleanerSubagent

Dead code cleanup and consolidation specialist. Use PROACTIVELY for removing unused code, duplicates, and refactoring. Runs analysis tools (knip, depcheck, ts-prune) to identify dead code and safely removes it.