사용 방법
- 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
- 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
- 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/salimhamed/claude-code-flow --skill wt-merge시작 전 확인
- 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
- 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.
Merge Worktree
Announce at start: "I'm using the wt-merge skill to squash-merge and clean up."
Context
- Current directory: !
pwd - Current branch: !
git branch --show-current - Worktrees: !
git worktree list --porcelain - Working tree status: !
git status --porcelain - Unpushed commits: !
git rev-list '@{u}..HEAD' 2>/dev/null || echo NO_UPSTREAM - PR info: !
gh pr view --json number,url,state,title 2>&1 || echo NO_PR
Decision Flowchart
flowchart TD
A[Preconditions] -- fail --> STOP
A -- pass --> B[Merge PR]
B --> C[Cleanup + update main]
C --> D[Report]Preconditions
Only two checks before proceeding — everything else fails naturally with clear errors from gh pr merge.
| Check | How to detect | Action |
|---|---|---|
| Uncommitted changes | Working tree status is non-empty | STOP — tell user to commit or stash |
| Unpushed commits | Output shows commit SHAs or NO_UPSTREAM | Run git push -u origin HEAD, then continue |
Variables
Extract from context above:
| Variable | Source |
|---|---|
{NUMBER} | PR number from PR info |
{MAIN_WORKTREE} | Path of the first entry in the worktree list (the main worktree) |
{WORKTREE_PATH} | Current directory (the feature worktree being removed) |
{BRANCH} | Current branch name |
Steps
Step 1: Merge
gh pr merge {NUMBER} --squashUse the PR number from context. Do NOT use --delete-branch (it tries to switch branches locally, which fails when the default branch is already checked out in the main worktree). Branch cleanup is handled in Step 2.
If this fails, STOP and show the error to the user.
Step 2: Cleanup + update main
CRITICAL: This MUST be a single Bash invocation. After worktree remove deletes {WORKTREEPATH}, the shell's CWD no longer exists and ALL subsequent Bash tool calls will fail. Every command uses `git -C` to operate from {MAINWORKTREE} regardless of the shell's CWD state.
Do NOT split these into separate Bash calls. Do NOT remove or reorder commands.
git -C {MAIN_WORKTREE} worktree remove --force {WORKTREE_PATH}; git -C {MAIN_WORKTREE} worktree prune; git -C {MAIN_WORKTREE} branch -D {BRANCH} 2>/dev/null; git -C {MAIN_WORKTREE} fetch --prune && git -C {MAIN_WORKTREE} pull --ff-only; echo "===REMAINING WORKTREES==="; git -C {MAIN_WORKTREE} worktree listCommands are joined with ; (continue regardless of errors) except fetch && pull which are dependent. Individual failures are tolerated — the branch or worktree directory may already be gone.
Step 3: Report
Parse the output from Step 2. Everything after ===REMAINING WORKTREES=== is the current worktree list.
Summarize:
- PR was squash-merged (include title and URL from context)
- Worktree was removed
- Main branch was updated (or note if ff-only failed based on Step 2 output)
- List remaining worktrees from Step 2 output
Then tell the user: "The current directory has been deleted. Please close this session and open a new one from a valid directory."
Do NOT run any further Bash commands or offer follow-up actions — the shell is broken because the CWD was deleted with the worktree.
Red Flags
Never:
- Remove a worktree without merging first
- Delete worktrees the user didn't confirm
- Split Step 2 into multiple Bash calls
- Run Bash commands after Step 2 completes (CWD no longer exists)
Always:
- Use
git -C {MAIN_WORKTREE}for all git commands (nevercd) - Keep all post-merge operations in a single Bash invocation
- Tolerate errors during cleanup (worktree remove, branch delete)




