本文へ移動
cccskills
無料GitHub で公開日本語紹介

cleanup-git-worktrees

Git worktreeを監査し、マージ済み・古いブランチや保護対象を分類して、安全に整理するための候補と確認点を示します。

原文原文の説明を見る

Use for stale-worktree, Git registration and branch audits. Managed removal uses the repo lifecycle.

lobehub/lobehubスター 83,500(GitHub 83,500 + cccskills 0)

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • 古いworktreeを整理したいとき
  • マージ済みブランチを確認したいとき
  • 未 push の作業を保護したいとき
  • 削除後の状態を確認したいとき

日本語での紹介

できること

Git worktreeとローカルブランチを監査し、状態に応じて削除候補、手動確認が必要な項目、保護対象に分類します。マージ済み、PRの状態、更新からの日数、未 push のコミット、作業ツリーの変更などを確認し、削除できる理由も示します。候補を確認してから、対象を指定したクリーンアップを実行し、もう一度監査して削除結果や残した作業を報告する流れを案内します。

こんなときに便利

長く使っていないworktreeを整理したいときや、PRをマージした後にローカルブランチを片付けたいときに役立ちます。変更中のファイルや未 push のコミットを誤って失わないよう、残す対象と削除候補を分けて確認できます。サービスなどをworktreeと一緒に管理するリポジトリでは、専用のライフサイクル手順を使う必要があることも把握できます。

使い方の例

  • 「このリポジトリのworktreeを監査して、削除候補と保護対象を理由つきで一覧にして」
  • 「マージ済みのPRブランチを確認し、未 push の作業が残るものは分けて」
  • 「承認したブランチを整理して、削除後の状態も報告して」

注意点

監査には付属の scripts/cleanup.sh を使います。PR状態の照会には認証済みの gh CLIを利用できます。削除は破壊的な操作として扱い、対象が明示されていない場合は候補を提示して承認を得てから進めます。登録済みworktreeに再帰削除を使わず、壊れた登録の残存ディレクトリを削除する場合は、パスを指定したうえで確認が必要です。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

資料チェック

SKILL.md の記述から、注意が要る操作と導入の前提を AI が確認しました。点数は実際に動かした結果(実行検証)だけで付けています。

安全面送信・削除・コマンド実行などの扱いが明示されているか
B一部不足削除前の承認を求めますが、別の承認済み方針では汚れたPR枝も削除可能です。
導入のしやすさ必要なツールや API キーが少ないか、書かれているか
B一部不足付属スクリプトと、PR照会に使う認証済み`gh` CLIが必要です。

点数には入れていません。 2026年10月26日 時点で AI(OpenAI Codex)が判定しました。目安なので、入れる前に原文も確認してください。

評価が違うと思ったら、見直しを依頼する

どの項目が、なぜ違うと思うかを書いてください。ログインは不要です。内容を SKILL.md と照らし合わせて評価を作り直し、この欄に反映します。

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

含まれるファイル(3)

  • SKILL.md10.9 KB
  • agents/openai.yaml241 B
  • scripts/cleanup.sh11.4 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Cleanup Git Worktrees

Use the bundled script to make classification deterministic. Treat cleanup as a destructive action: audit first, show the exact candidates grouped by why they are deletable, and obtain one explicit approval before applying deletion unless the user's current request already names the exact targets. Aim for a single approval round-trip, not a per-item Q&A.

Workflow

  1. Run the audit from any worktree in the repository:

    bash .agents/skills/cleanup-git-worktrees/scripts/cleanup.sh audit --fetch --gh --stale-days 15 --base origin/canary
    
    • --fetch: prune the remote first. Omit only when offline and say so.
    • --gh: look up each branch's PR (number, state, head SHA) with the gh CLI. This is what turns [gone] into a verified merge; use it whenever gh is authenticated. It costs roughly one second per branch, so run it in the background on large repos.
    • --stale-days N: mark clean branches idle longer than N days with nothing unpushed as candidate-stale. The repository default the user has approved is 15 days.
    • --noise REGEX: untracked paths that never count as dirt (default node_modules|\.goal-tracing/).
  2. Interpret classifications:

    ClassificationMeaningAction
    protected-branchmain, canary, or the base refnever
    protect-currentthe worktree running the commandnever
    protect-dirtytracked modifications, or untracked files outside the noise regexkeep; list the files
    candidate-mergedtip is an ancestor of the basedelete
    candidate-pr-mergedPR state MERGED and local tip == PR head SHAdelete
    candidate-pr-closedPR CLOSED and tip == PR head or nothing unpusheddelete
    candidate-goneupstream pruned and nothing unpusheddelete after confirming PR state
    candidate-staleolder than --stale-days, clean, nothing unpusheddelete
    review-pr-merged-aheadPR merged but local tip has extra commitscheck the extra commits by subject (below)
    review-gone-unpushedupstream pruned but local-only commits existkeep; deleting loses work
    review-no-upstreamno upstream, not mergedkeep unless the user names it
    review-detacheddetached HEAD worktreekeep; show its dirty files
    broken-registration(...)registration whose gitdir is gonesee below
    activeeverything elsekeep

    Columns worth reading: dirty (real dirt), noise (ignorable untracked), age_days, unpushed (commits no remote ref reaches), pr / pr_state / tip_eq_pr.

  3. Present one compact table split into three groups: deletable now (all candidate-*), needs a manual check (review-*), and protected. Keep candidate-merged separate from candidate-gone, and never describe [gone] alone as proof of merge.

  4. After approval, use the repository's worktree lifecycle workflow when it manages services or other resources alongside a checkout; the Git-only script does not tear those down. For plain Git worktrees, pass exact branch names and the same classification flags used for the audit:

    bash .agents/skills/cleanup-git-worktrees/scripts/cleanup.sh clean \
      --gh --stale-days 15 --base origin/canary \
      --branch feat/example \
      --branch fix/example \
      --apply
    

    Without --apply, cleanup is a dry run. The script re-classifies every target immediately before deletion and refuses anything that is not candidate-*. Worktrees whose only dirt is noise are removed with git worktree remove --force; everything else uses the plain, refusing form.

    Removing a worktree that still holds node_modules can take several minutes each. Run large batches in the background and report progress rather than waiting on a single foreground call.

  5. Run the audit again and report:

    • removed worktrees and branches, with the SHA each branch pointed at (the script prints it; reflog keeps it for 90 days);
    • retained dirty / unpushed / detached targets and why;
    • remaining worktree and local-branch counts;
    • any partial deletion or Git error.

Proving a merge

Squash and rebase merges leave no ancestry, so git merge-base --is-ancestor and git cherry say "not merged" for branches whose PR landed. Use this ladder instead:

  1. --gh reports pr_state=MERGED and tip_eq_pr=eq: the local tip is exactly what GitHub merged. Done.
  2. review-pr-merged-ahead (tip moved past the PR head): list the extra commits with git log <pr-head>..<branch> and search the base for each subject: git log origin/canary --oneline -F --grep="<subject>". A hit on the PR's squash commit means the commit was part of the PR. A miss means the commit is unmerged; check which live branch still contains it with git branch --contains <sha> before deleting.
  3. Branches named after a PR (pr-18412, codex/pr-18497-fix) are local review copies; verify the PR by number with gh pr view N --json state,headRefOid and compare subjects as above.
  4. Do not judge by git diff origin/canary <branch> -- <files>: on an old branch the diff is dominated by later changes on the base.

Zero unpushed means every local commit is reachable from some remote ref, so deleting the local branch loses nothing even when the PR is still OPEN; the user has approved deleting such branches once they pass the stale threshold.

Repo-approved deletion policy

The repository owner has approved the following for this repo, so a cleanup run does not need to re-ask per item. It is the sanctioned exception to the safety rules below; state it in the report and say plainly whenever uncommitted work is being discarded.

  • Dirt equal to the base is not dirt. A tracked file listed as modified whose content is byte-identical to the base (git diff --quiet <base> -- <file>) is stale residue of a branch that is simply behind. When presenting, do not count it as a real change: list such files in their own group so the genuine modifications stay visible.
  • Merged / closed PR branches are disposable together with their local commits. When a branch's PR is MERGED or CLOSED, its worktree and local branch may be removed even when unpushed > 0 or the tree is dirty. Record every branch SHA before deleting (reflog keeps them ~90 days) and state in the report that uncommitted edits are not recoverable.
  • Local scratch does not block removal. Untracked *.probe.test.ts, spike scripts under scripts/, and untracked screenshots (*.png) are disposable; do not raise them as blockers.
  • Still never delete: main, canary, the base ref, and the worktree running the command. A branch whose PR is OPEN is kept while it still holds local-only work (dirty files or unpushed > 0); a clean, fully-pushed branch with an open PR is the redundant local copy the stale rule already covers.

Proving a merge when the repo squash-merges. This repo squash-merges, so a landed PR leaves the squash commit on the base but none of the branch's own commits. Searching the base for an individual commit subject therefore fails for every squashed branch — do not read that as "unmerged". Decide review-pr-merged-ahead by the PR's state plus commit dates instead: if the branch tip is not newer than mergedAt, the branch is pure pre-merge history whose content is already on the base (verify the PR's mergeCommit with git merge-base --is-ancestor <mergeCommit> origin/canary). Only commits dated after mergedAt are candidate unmerged work — keep the branch and list them.

The bundled script still refuses anything outside candidate-*, so these removals are done manually: wt_path=$(git worktree list --porcelain …) → record git rev-parse <branch> → git worktree remove --force → git branch -D. Keep the run in the background; removals that hold node_modules take minutes each.

Broken registrations

git worktree list --porcelain marks an entry prunable when its gitdir file points nowhere (typically after a partial removal). The audit reports these as broken-registration(directory-present|missing; reason) instead of crashing on them.

  • git worktree prune drops only the registration. It never touches the directory or the branch, so it is safe to run before re-auditing.
  • A leftover directory has no .git, so its dirty state cannot be checked. Show its size and file count and ask before deleting it with rm -rf; that is the one place recursive deletion is acceptable, and only on a path the user named.

Safety rules

  • Never discard dirty worktrees merely because their branch is merged, [gone], or old; noise-only dirt (the --noise regex) does not count. The one exception is a worktree whose branch's PR is MERGED or CLOSED, per the repo-approved deletion policy above.
  • Never delete a branch with unpushed > 0 through this script; list it and let the user decide. Same exception: a MERGED/CLOSED PR branch may be removed under the owner's standing approval, with its SHA recorded first.
  • Never use recursive deletion on a registered worktree. If Git partially removes a directory, stop and inspect the exact path before deciding how to recover.
  • Never delete main, canary, or the base branch.
  • Preserve unrelated user changes and concurrent worktrees. The user's other sessions may be working in them.
  • When writing ad-hoc verification loops, run them under bash, not the interactive zsh: zsh does not word-split $var in for/argument positions, so file lists collapse into one argument and checks silently pass.

Script

Use scripts/cleanup.sh; do not recreate its parsing and guard logic ad hoc unless the repository layout makes it unusable. It is set -euo pipefail; helper functions that pipe through grep wrap it in || true so an empty match is "clean", not an abort.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

acceptance

無料概要あり

実際の製品を操作して、利用者が確認できる動作証拠を集め、検証計画に沿った受け入れレポートとして公開するスキルです。

  • 変更後の製品動作を実地で検証したいとき
  • 画面キャプチャなどの証拠を集めたいとき
  • 検証計画とレポートを作成したいとき
lobehub/lobehub8.4万2026年10月26日 更新

add-model-provider

無料概要あり

LobeHubにAIモデルプロバイダーを追加し、実行時連携からモデル表示、設定、ブランド表記、文書化、動作確認まで進めるスキルです。

  • 新しいAIモデルプロバイダーを追加したいとき
  • プロバイダーの設定手順や説明文を更新したいとき
  • 既存プロバイダーへのモデル追加要件を見極めたいとき
lobehub/lobehub8.4万2026年10月26日 更新

add-setting-env

無料概要あり

ユーザー設定の初期値をサーバー側の環境変数で切り替えるため、型定義や設定の組み立て、ユーザーストアへの反映、環境変数の例と説明書きを追加する手順です。

  • 設定の初期値を環境変数で変えたいとき
  • 設定項目をサーバー設定に追加したいとき
  • 環境変数の例と説明を更新したいとき
lobehub/lobehub8.4万2026年10月26日 更新

agent-runtime-hooks

無料概要あり

エージェント実行中の各段階をフックで監視し、ツール呼び出しの模擬・制御や人の承認、圧縮、サブエージェント処理に介入する仕組みを扱います。

  • エージェントの実行状況を記録したいとき
  • ツール結果をテスト用に模擬したいとき
  • Webhookでツール実行を許可・拒否したいとき
lobehub/lobehub8.4万2026年10月26日 更新

agent-signal

無料概要あり

イベントを起点にエージェントのバックグラウンド処理を組み立て、ソース・シグナル・アクション・ポリシーの役割分担や非同期連携を実装するためのスキルです。

  • イベント起点の処理を追加したいとき
  • バックグラウンド処理を非同期化したいとき
  • 重複実行を防ぐ仕組みを整えたいとき
lobehub/lobehub8.4万2026年10月26日 更新

agent-testing-bot

無料概要あり

DiscordやSlackなどの実際のチャットアプリでボットにメッセージを送り、応答を画面で確認する受け入れテストを行うスキルです。

  • 実際のDiscordでボット応答を確かめたいとき
  • SlackやTelegramの会話経路をテストしたいとき
  • macOSアプリ上の操作結果を画面で記録したいとき
lobehub/lobehub8.4万2026年10月26日 更新

lobehub のスキルをすべて見る

このスキルの問題を報告する