worktree-cleaner
Skill này làm gì
Skill này kiểm kê các git worktree trong một kho mã, cho biết mỗi cái chứa gì, và chỉ xóa những gì bạn đồng ý. Skill dành cho lập trình viên có dự án tích tụ nhiều worktree từ các tác vụ song song.
Khi nào nên dùng
- ✓Khi git worktree list đã dài và bạn muốn dọn dẹp lại.
- ✓Khi agent hoặc một quy trình song song đã tạo worktree cho mỗi tác vụ mà chưa cái nào được xóa.
- ✓Khi bạn muốn biết worktree nào đã được merge, đã cũ hoặc vẫn còn công việc chưa đẩy lên.
Liên kết skill
https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/worktree-cleaner/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Kho của tôi có hàng chục worktree còn sót lại. Cho tôi xem cái nào an toàn để xóa, và hỏi tôi trước khi xóa bất cứ thứ gì.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent thu thập bằng chứng cho từng worktree, như trạng thái merge, trạng thái pull request và thay đổi chưa commit, đề xuất những gì nên xóa, và chỉ thực hiện xóa sau khi bạn đồng ý từng bước.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
- Ask before every destructive command.
git worktree remove,git worktree prune,git worktree unlockandgit branch -d/-Deach need the user's approval for that worktree or that named group. Approval of one group does not carry to the next. - Never
--forceon 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. - 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.
- 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. - Deleting the local branch is a separate question, asked after the worktree is gone. Removing a worktree never deletes its branch.
- 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.
- 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 |
Câu hỏi thường gặp
Nó có xóa công việc của tôi không?
Skill xin phép trước mọi lệnh phá hủy, và hỏi riêng trước khi xóa bất kỳ thứ gì có thay đổi chưa commit hoặc commit chưa lưu.
Nó có xóa nhánh từ xa không?
Không. Skill coi nhánh từ xa nằm ngoài phạm vi, dù có thể nhắc đến các nhánh cũ trong báo cáo.
Nó có đụng đến worktree tôi đang dùng không?
Không. Skill không bao giờ chạm vào worktree chính, worktree nơi nó đang chạy, hay bất kỳ worktree nào có tiến trình đang hoạt động bên trong.
Chi tiết
Mô tả gốc của tác giả
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.
Độ phổ biến
- Sao GitHub
- 33k
- Vị trí xếp hạng
- #8856
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
owasp-security
33kDạy agent hướng dẫn bảo mật OWASP cho ứng dụng web, API, di động, container và agent AI, để nhận ra các điểm yếu phổ biến và gợi ý cách sửa.
agent-management
33kCho phép agent của bạn tạo, liệt kê, cho ngủ đông, đánh thức, đổi tên và xóa các agent AI bằng dòng lệnh AI Maestro, quản lý vòng đời của từng agent.
agent-messaging
33kCho phép agent của bạn gửi, nhận và trả lời tin nhắn có chữ ký giữa các agent AI, dùng Agent Messaging Protocol, chủ yếu trên máy của bạn.
docs-search
33kCho phép agent của bạn tìm trong tài liệu code được tạo tự động, như chữ ký hàm, định nghĩa lớp và chú thích, để kiểm tra API thật trước khi sửa code.
Skill tương tự
openclaw-update
394kGiúp agent của bạn cập nhật OpenClaw Gateway đang có, chọn cách cập nhật phù hợp với cách cài đặt và giữ phiên làm việc của bạn hoạt động.
diagnose-gateway
394kGiúp agent của bạn tìm hiểu vì sao OpenClaw Gateway bị lỗi bằng cách kiểm tra cài đặt, kênh và cổng mà không thay đổi gì.
crabbox-apps
394kGiúp agent của bạn mở và chạy một app trên máy đám mây tạm thời, rồi hiển thị giao diện của nó trong thanh bên của chat.