본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)33k · #8856

worktree-cleaner

하는 일

이 스킬은 저장소의 git 워크트리를 목록화하고, 각 워크트리가 무엇을 담고 있는지 보여준 뒤, 승인한 것만 제거합니다. 병렬 작업으로 워크트리가 많이 쌓인 개발자에게 맞습니다.

사용하는 경우

  • ✓git worktree list가 길어져서 정리하고 싶을 때.
  • ✓에이전트나 병렬 작업이 작업마다 워크트리를 만들고 아무것도 제거되지 않았을 때.
  • ✓어떤 워크트리가 병합되었고, 오래되었으며, 아직 푸시되지 않은 작업을 담고 있는지 알고 싶을 때.

스킬 링크

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/worktree-cleaner/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/worktree-cleaner/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“저희 저장소에 남은 워크트리가 수십 개입니다. 안전하게 지워도 되는 것을 보여주고, 삭제 전에는 물어봐 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 각 워크트리에 대해 병합 상태, 풀 리퀘스트 상태, 커밋되지 않은 변경 같은 증거를 모으고, 무엇을 제거할지 권고한 뒤, 승인한 단계에서만 제거를 실행합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Worktree Cleaner

Agents and parallel workflows create one git worktree per task, and nobody removes them. This skill finds them, shows the user what each one holds, and removes only what the user approves, checking the result after every step.

The user decides. You gather evidence, recommend, and execute exactly what was approved. Nothing is removed in bulk without the user seeing the list first.

Hard rules

  1. Ask before every destructive command. git worktree remove, git worktree prune, git worktree unlock and git branch -d/-D each need the user's approval for that worktree or that named group. Approval of one group does not carry to the next.
  2. Never --force on work that would be lost. If a worktree has uncommitted changes, untracked files, or commits that exist nowhere else, show the exact files and commits and ask a separate, explicit question ("remove it and lose these changes?"). A general "yes, clean everything" is not that confirmation.
  3. Never touch the main worktree, the worktree you are running in, or a worktree with live processes inside it (another Claude Code session, an editor, a dev server). Report them and move on.
  4. Never delete a remote branch (git push --delete, git push origin :branch, API calls). Remote branches are out of scope; mention them in the report if they look stale.
  5. Deleting the local branch is a separate question, asked after the worktree is gone. Removing a worktree never deletes its branch.
  6. Re-check right before acting. State changes while you talk to the user: re-run the inventory for that one path immediately before removing it, and stop if the verdict got worse.
  7. Verify after every action and report what you checked. If a check fails, stop and tell the user; do not retry with stronger flags.

Step 1: Inventory (read-only)

Run the bundled script from anywhere inside the repository. It changes nothing; --fetch only runs git fetch --prune so the merged/pushed checks use fresh remote refs. Ask before fetching if the user is offline or on a metered connection; otherwise fetch.

bash "${CLAUDE_SKILL_DIR}/scripts/worktree-inventory.sh" --fetch

If CLAUDE_SKILL_DIR is not set, the script is at .claude/skills/worktree-cleaner/scripts/worktree-inventory.sh (project install) or ~/.claude/skills/worktree-cleaner/scripts/worktree-inventory.sh (user install).

Flags: --path <worktree> reports a single worktree (use it for the re-check in rule 6; it exits 3 with an error when no worktree matches, so a typo never looks like an empty result), --no-gh skips the GitHub CLI PR lookup, --repo <dir> targets another repository. The fetch never prompts for credentials; if it cannot authenticate it reports fetch: FAILED.

It prints a header (default_branch, whether the fetch worked, whether gh and git merge-tree were available) and then one block per worktree. Key fields:

Field Meaning
modified_tracked, untracked_files, changed_paths Uncommitted work. git worktree remove refuses these without --force.
ignored_local_files Gitignored files and directories that are not regenerable artifacts (dependencies, build output and caches such as node_modules/, dist/, .venv/ are left out): .env, .dev.vars, local settings, keys, a whole secrets/ directory. git worktree remove deletes ignored files without warning, so these must be shown to the user.
commits_not_on_any_remote Commits reachable from this worktree's HEAD and from no remote-tracking ref. On a branch, removing the worktree keeps them on the branch, but deleting the branch afterwards loses them. On a detached worktree there is no branch: removing it makes them unreachable (the script marks it AT_RISK).
git_error git could not read the worktree (broken .git file, safe.directory ownership, permissions). Nothing else in the block is reliable.
head_merged_into_default HEAD is an ancestor of the default branch (merge or fast-forward).
content_already_in_default Merging HEAD into the default branch would change nothing (git merge-tree). This catches squash and rebase merges, where the commits differ but the content landed.
pr #N STATE url from gh, none, or unknown when gh is not available.
processes_inside Running processes whose working directory is inside the worktree.
claude_session_hours_ago Hours since a Claude Code
자주 묻는 질문

제 작업을 삭제하나요?

스킬은 모든 파괴적 명령 전에 승인을 요청하며, 커밋되지 않았거나 저장되지 않은 작업이 있는 워크트리는 별도로 묻습니다.

원격 브랜치도 삭제하나요?

아니요. 스킬은 원격 브랜치를 범위 밖으로 보며, 다만 보고서에 오래된 브랜치를 언급할 수는 있습니다.

내가 쓰고 있는 워크트리도 건드리나요?

아니요. 메인 워크트리, 스킬이 실행 중인 워크트리, 실행 중인 프로세스가 있는 워크트리는 건드리지 않습니다.

상세 정보

작성자의 원본 설명

Inventory the git worktrees of the current repository, classify each one with evidence (merged, PR state, uncommitted or unpushed work, locked, stale, in use by a running session) and remove them one at a time or by group, always asking the user first and verifying every removal. Use when worktrees have piled up (for example one per Claude Code task or thread), when `git worktree list` is long, or when the user asks to clean up, prune or tidy worktrees.

repo: davila7/claude-code-templates

인기도

GitHub 스타
33k
순위
#8856
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬