Worktree Clean Check
Use this skill to list local worktrees, surface clean or dirty state, and judge whether selected committed branch code has already landed in origin/x by actual code content, not by merge commits alone.
Rules
- Always start by listing every local worktree with numeric choices.
- Ask the user to reply with
1, 2,4, or A.
- Always fetch the latest
origin/x before running the check.
- Use commit graph data only to locate branch-side candidate files. Final judgment must come from content equality between the selected worktree snapshot and
origin/x.
- Surface metadata that helps cleanup decisions: last commit time, upstream branch, PR status, and whether the worktree is nested under another linked worktree.
- PR status is best-effort only. Use
gh when available; if auth or network is unavailable, report that explicitly and continue the local git-based check.
- If a worktree is dirty, report that separately and make it clear the committed-branch result does not cover uncommitted local edits.
- After the check result, always surface cleanup candidates:
- stale directories that exist under
.worktree/ but are no longer registered by git worktree list
- selected worktrees that are
MERGED_TO_ORIGIN_X_BY_CODE or NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE, clean, and are neither the main worktree nor the current worktree
- After surfacing cleanup candidates, always ask whether the user wants to remove stale directories, removable worktrees, both, or neither.
- Never auto-delete anything before the user explicitly confirms the cleanup action.
Step 1: List Local Worktrees
Run:
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh list
Then present the choices to the user and append:
请回复编号,例如 `1`、`2,4` 或 `A`。
List output should include, for each worktree:
- path
- branch
- clean/dirty state
- upstream branch
- last commit time
- PR status
- nested worktree status
Step 2: Sync Remote X
Run:
rtk git fetch origin x
If sandboxing blocks the fetch, request approval and rerun it.
Step 3: Check Selected Worktrees
Run one of:
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check 1
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check 1,3
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check A
Step 4: Surface Cleanup Candidates And Ask
Run the matching cleanup-candidate command with the same selection:
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates 1
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates 1,3
rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates A
Then summarize:
- stale directory count and paths
- removable worktrees with the reason (
MERGED_TO_ORIGIN_X_BY_CODE or NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE)
- skipped removable worktrees with the reason when applicable
- For removable/skipped worktrees, keep the metadata visible: upstream, last commit time, PR status, and nested worktree status
If there is at least one cleanup candidate, append:
如需继续清理,请回复:
`stale`:只删残留目录
`merged 2,4`:只删这些可移除且 clean 的 worktree
`all`:两类都清理
`no`:不清理
If there are no cleanup candidates, say so explicitly.
Step 5: Delete Only After Confirmation
If the user confirms cleanup:
- Remove removable worktrees with:
rtk git worktree remove <path>
- Remove stale directories with:
rtk proxy rm -rf <path>
- If sandboxing blocks either command, request approval and rerun it.
- When deleting removable worktrees, keep reporting path, branch, and removable reason so the user can verify scope before the command runs.
How To Interpret The Result
MERGED_TO_ORIGIN_X_BY_CODE: every branch-side candidate file now matches origin/x.
NOT_FULLY_MERGED_TO_ORIGIN_X_BY_CODE: at least one branch-side candidate file still differs from origin/x.
NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE: the worktree has no committed branch-only code delta relative to the common base with origin/x. If it is also clean and is neither the main worktree nor the current worktree, treat it as a removable cleanup candidate.
Working tree: dirty: show the dirty files and state that current local edits still need separate review.
Output Contract
- Give a short summary first for all selected worktrees: merged, not merged, or no delta.
- For each worktree, include path, branch, clean/dirty state, upstream branch, last commit time, PR status, nested/non-nested status, candidate file count, and the unmatched file list when present.
- When the result is merged, explicitly say
已合并到远端 x(按代码内容判断).
- When the result is
NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE, explicitly say it has no committed branch delta relative to origin/x, and that it is removable when it is also clean and not the main/current worktree.
- After the check summary, give a cleanup follow-up: stale directories, removable worktrees, and whether the user wants to delete them.
- If PR status cannot be determined, say that clearly instead of guessing.
- Never conclude purely from “this commit was merged” or “this branch is ahead/behind”.
1---2name: 1k-worktree-clean3description: Use when the user wants to audit local git worktrees against origin/x, choose by number or A, and decide whether stale worktree directories, already-merged worktrees, or no-delta worktrees can be cleaned up. Triggers on "worktree clean", "worktree 合并到 x", "检测哪些 worktree 已进 x".4---56# Worktree Clean Check78Use this skill to list local worktrees, surface clean or dirty state, and judge whether selected committed branch code has already landed in `origin/x` by actual code content, not by merge commits alone.910## Rules1112- Always start by listing every local worktree with numeric choices.13- Ask the user to reply with `1`, `2,4`, or `A`.14- Always fetch the latest `origin/x` before running the check.15- Use commit graph data only to locate branch-side candidate files. Final judgment must come from content equality between the selected worktree snapshot and `origin/x`.16- Surface metadata that helps cleanup decisions: last commit time, upstream branch, PR status, and whether the worktree is nested under another linked worktree.17- PR status is best-effort only. Use `gh` when available; if auth or network is unavailable, report that explicitly and continue the local git-based check.18- If a worktree is dirty, report that separately and make it clear the committed-branch result does not cover uncommitted local edits.19- After the check result, always surface cleanup candidates:20 - stale directories that exist under `.worktree/` but are no longer registered by `git worktree list`21 - selected worktrees that are `MERGED_TO_ORIGIN_X_BY_CODE` or `NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE`, `clean`, and are neither the main worktree nor the current worktree22- After surfacing cleanup candidates, always ask whether the user wants to remove stale directories, removable worktrees, both, or neither.23- Never auto-delete anything before the user explicitly confirms the cleanup action.2425## Step 1: List Local Worktrees2627Run:2829```bash30rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh list31```3233Then present the choices to the user and append:3435```text36请回复编号,例如 `1`、`2,4` 或 `A`。37```3839List output should include, for each worktree:4041- path42- branch43- clean/dirty state44- upstream branch45- last commit time46- PR status47- nested worktree status4849## Step 2: Sync Remote X5051Run:5253```bash54rtk git fetch origin x55```5657If sandboxing blocks the fetch, request approval and rerun it.5859## Step 3: Check Selected Worktrees6061Run one of:6263```bash64rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check 165rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check 1,366rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh check A67```6869## Step 4: Surface Cleanup Candidates And Ask7071Run the matching cleanup-candidate command with the same selection:7273```bash74rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates 175rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates 1,376rtk proxy bash .skillshare/skills/1k-worktree-clean/scripts/1k-worktree-clean.sh cleanup-candidates A77```7879Then summarize:8081- stale directory count and paths82- removable worktrees with the reason (`MERGED_TO_ORIGIN_X_BY_CODE` or `NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE`)83- skipped removable worktrees with the reason when applicable84- For removable/skipped worktrees, keep the metadata visible: upstream, last commit time, PR status, and nested worktree status8586If there is at least one cleanup candidate, append:8788```text89如需继续清理,请回复:90`stale`:只删残留目录91`merged 2,4`:只删这些可移除且 clean 的 worktree92`all`:两类都清理93`no`:不清理94```9596If there are no cleanup candidates, say so explicitly.9798## Step 5: Delete Only After Confirmation99100If the user confirms cleanup:101102- Remove removable worktrees with:103104```bash105rtk git worktree remove <path>106```107108- Remove stale directories with:109110```bash111rtk proxy rm -rf <path>112```113114- If sandboxing blocks either command, request approval and rerun it.115- When deleting removable worktrees, keep reporting path, branch, and removable reason so the user can verify scope before the command runs.116117## How To Interpret The Result118119- `MERGED_TO_ORIGIN_X_BY_CODE`: every branch-side candidate file now matches `origin/x`.120- `NOT_FULLY_MERGED_TO_ORIGIN_X_BY_CODE`: at least one branch-side candidate file still differs from `origin/x`.121- `NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE`: the worktree has no committed branch-only code delta relative to the common base with `origin/x`. If it is also `clean` and is neither the main worktree nor the current worktree, treat it as a removable cleanup candidate.122- `Working tree: dirty`: show the dirty files and state that current local edits still need separate review.123124## Output Contract125126- Give a short summary first for all selected worktrees: merged, not merged, or no delta.127- For each worktree, include path, branch, clean/dirty state, upstream branch, last commit time, PR status, nested/non-nested status, candidate file count, and the unmatched file list when present.128- When the result is merged, explicitly say `已合并到远端 x(按代码内容判断)`.129- When the result is `NO_BRANCH_CODE_DELTA_FROM_COMMON_BASE`, explicitly say it has no committed branch delta relative to `origin/x`, and that it is removable when it is also `clean` and not the main/current worktree.130- After the check summary, give a cleanup follow-up: stale directories, removable worktrees, and whether the user wants to delete them.131- If PR status cannot be determined, say that clearly instead of guessing.132- Never conclude purely from “this commit was merged” or “this branch is ahead/behind”.