cleanup-resources
End-of-workflow audit of touched GitHub issues, PRs, and branches via a Sonnet subagent. Use when: (1) /big-plan, /x-as-pr, or /x-wt-teams finishes its main work and needs to verify every touched resource is in the right state (closed when done, kept when ongoing, deleted when dead), (2) User says 'cleanup resources', 'audit cleanup', or 'check what should be closed', (3) A long workflow ends and the manager wants a structured paper trail of what it closed/kept/deleted. Auto-execute by default — the Sonnet agent proposes, the manager (you) executes safe actions and prints a final report.
Best use case
cleanup-resources is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
End-of-workflow audit of touched GitHub issues, PRs, and branches via a Sonnet subagent. Use when: (1) /big-plan, /x-as-pr, or /x-wt-teams finishes its main work and needs to verify every touched resource is in the right state (closed when done, kept when ongoing, deleted when dead), (2) User says 'cleanup resources', 'audit cleanup', or 'check what should be closed', (3) A long workflow ends and the manager wants a structured paper trail of what it closed/kept/deleted. Auto-execute by default — the Sonnet agent proposes, the manager (you) executes safe actions and prints a final report.
Teams using cleanup-resources should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/cleanup-resources/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How cleanup-resources Compares
| Feature / Agent | cleanup-resources | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
End-of-workflow audit of touched GitHub issues, PRs, and branches via a Sonnet subagent. Use when: (1) /big-plan, /x-as-pr, or /x-wt-teams finishes its main work and needs to verify every touched resource is in the right state (closed when done, kept when ongoing, deleted when dead), (2) User says 'cleanup resources', 'audit cleanup', or 'check what should be closed', (3) A long workflow ends and the manager wants a structured paper trail of what it closed/kept/deleted. Auto-execute by default — the Sonnet agent proposes, the manager (you) executes safe actions and prints a final report.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Cleanup Resources
End-of-workflow audit for GitHub issues, PRs, and branches the calling workflow touched. Long workflows (big-plan, x-as-pr, x-wt-teams) tend to drop the trailing "close the source issue" / "delete the dead local branch" steps because context drifts. This skill forces an explicit checkpoint: gather a manifest of every touched resource, hand it to a fresh Sonnet agent for audit, then execute the safe actions and report.
## Who calls this skill
This skill is invoked at the **end** of a parent workflow — never mid-flight. Typical callers:
- `/big-plan` — at Step 10 (Close source issues). Manifest: source issues passed to the planning session.
- `/x-as-pr` — after Session Report / Requirements Verification. Manifest: tracking issue (if `--make-issue`), the working branch (if the PR was auto-merged via `-m` / Merge Mode), unrelated-findings issues raised mid-workflow.
- `/x-wt-teams` — replaces the old "Close Tracking Issue" + Step 16 cleanup. Manifest: tracking issue, sub-issues (if epic), root PR, base branch, topic branches, auto-merged status (the caller's `-m` flag).
Note on flag naming: this skill's own `-a` / `--auto-merged` flag means "the caller auto-merged the root PR." In the calling workflows that signal is their `-m` / `--merge` flag (their `-a` is the autonomy/auto-chain flag and does NOT imply a merge) — callers pass `-a` here iff `-m` was on their invocation.
Other callers can use it the same way: build a manifest, invoke, execute the returned plan.
## Workflow
### Step 1 — Manager builds the manifest
Before invoking the Sonnet agent, gather every resource the parent workflow created or touched. The manager (you) already knows these from session state — you do not need to grep git or scan the org. Build the manifest from memory of what the workflow did.
Structure the manifest as a single markdown block. Use this exact shape so the agent can parse consistently:
```markdown
## Workflow context
- workflow: <big-plan | x-as-pr | x-wt-teams>
- auto-flag (-a): <true | false>
- epic-mode: <true | false> # true when the parent dealt with a [Epic] issue from /big-plan
- root-PR: <url-or-"none">
- root-PR-merged: <true | false>
- parent-branch: <branch-name-or-"none">
## Resources
### Issues
- #<number> — <role> — <one-line context>
- ...
### PRs
- <url> — <role> — <merged|open|draft>
- ...
### Branches
- <branch-name> — <role> — <local|remote|both> — <pr-merged: true|false>
- ...
## Notes for the agent
<any free-form context: e.g. "issue #45 has follow-up work tracked separately, KEEP it open">
```
**Roles to use** (consistent vocabulary helps the agent):
- Issue roles: `source` (existed before; the workflow superseded it), `tracking` (created by the workflow as a spec/log), `epic`, `sub` (under an epic), `fix` (review-fix issue), `unrelated-finding` (side-effect issue raised mid-workflow), `claimed-existing` (user-supplied, not created here).
- PR roles: `root` (the main PR for the workflow), `topic` (sub-PR merged into a base branch), `fix` (delegated fix PR).
- Branch roles: `base` (the base branch of an x-wt-teams session), `topic` (child branch under a base), `working` (the single x-as-pr working branch), `fix` (an `agent-fix/<slug>` branch from the `-fix` auto-fix step), `parent` (the branch the parent workflow targeted).
If a resource doesn't fit, invent a short role label and explain in **Notes for the agent**.
### Step 2 — Dispatch the Sonnet audit agent
Use the Agent tool to spawn a `general-purpose` agent with `model: sonnet`. The agent's job is **analysis only** — it must NOT close, delete, or edit anything. The manager executes actions in Step 3.
Prompt template (substitute the manifest):
```
You are auditing resources from a just-completed Claude Code workflow. The manager (parent session) handed you a manifest of every issue, PR, and branch touched during the workflow. Your job is to decide which should be CLOSED, KEPT, or DELETED, and return a structured plan. **Do not take any action yourself — only propose.**
Manifest:
<paste the full markdown manifest here>
Audit procedure:
1. For every issue in the manifest, run `gh issue view <number>` to read its current state, body, and recent comments. Check:
- Is it already closed? → action: keep, reason: "already closed".
- Does its body declare a TODO checklist with unchecked items? → action: keep, reason: "TODO checklist has open items".
- Was its work superseded by another issue/PR in the manifest (e.g. source issue replaced by an epic, fix issue replaced by a merged PR)? → action: close, with a one-line comment referencing the superseder.
- Is it an `unrelated-finding`? → action: keep, UNLESS it was already closed by `-fix` (the `/x-as-pr` or `/x-wt-teams` auto-fix step closes the ones it fixed and links the fix PR). An already-closed `unrelated-finding` stays closed (action: keep, reason: "already closed by -fix"). Open ones are intentional follow-ups — never close them here.
- Is it a `tracking` issue whose root PR is now merged (or the workflow ended cleanly)? → action: close.
- Is it a `sub` issue whose corresponding PR is merged into the base? → action: close.
- Is it an `epic` whose root PR is merged AND all sub-issues are closed? → action: close. Otherwise → keep.
2. For every PR in the manifest, run `gh pr view <url>` to read its state. PRs that are still open and intentional → keep. PRs already merged → keep (no action; they're done). PRs closed without merge (`state: CLOSED`, `merged: false`) → also keep, but add reason "manually closed without merge — investigate if the workflow expected it to merge". Do NOT propose closing open PRs unless the manifest's "Notes for the agent" explicitly asks for it.
3. For every branch in the manifest:
- Check remote state: `gh api repos/{owner}/{repo}/branches/{name}` or `git ls-remote --heads origin <branch>`.
- Check local state: assume the manager will check with `git branch --list <name>` before deleting.
- If pr-merged=true and the branch's role is `topic`, `working`, `base`, or `fix` → action: delete (both local and remote where applicable). Reason: "PR merged, branch is a dead pointer."
- If the remote has already been deleted (e.g. by `gh pr merge --delete-branch`) but the local still exists → action: delete-local-only.
- If pr-merged=false → action: keep.
- NEVER propose deleting `parent` branches — those belong to other work.
4. When the workflow's `auto-flag` is true (the caller auto-merged via its `-m` / `--merge` flag, passed to this skill as `-a` / `--auto-merged`) AND root-PR-merged is true, be more aggressive about deleting working/base/topic branches. The user explicitly opted into full auto-cleanup.
5. When in doubt about any resource, choose KEEP and explain in the reason. The manager will surface ambiguous cases to the user.
Return the plan as a single markdown block in this exact shape:
## Cleanup plan
### Close
- issue #<n> — <reason> — comment: "<one-line supersedes comment, or omit if no comment needed>"
- ...
### Delete (branches)
- <branch-name> — scope: <local|remote|both> — <reason>
- ...
### Keep
- <resource> — <reason>
- ...
### Ambiguous (manager: surface to user)
- <resource> — <why it's unclear>
- ...
End the response with one line: `Audit complete. <N> close / <M> delete / <K> keep / <A> ambiguous.`
```
Spawn the agent via the Agent tool with:
- `subagent_type`: `general-purpose`
- `model`: `sonnet`
- `description`: `Audit workflow resources for cleanup`
- `prompt`: the prompt above with the manifest filled in
Wait for the agent to return.
### Step 3 — Manager executes safe actions
Read the agent's plan. Execute each action **only** when it is unambiguously safe. The agent already filtered out unsafe cases into "Ambiguous", but the manager re-checks before acting.
**Close issues:**
```bash
for each "Close" entry:
# Skip if already closed (defensive — agent may have raced with an external close)
state=$(gh issue view <n> --json state -q '.state')
if [ "$state" = "OPEN" ]; then
if [ -n "<comment>" ]; then
gh issue comment <n> --body "<comment>"
fi
gh issue close <n>
fi
```
**Delete branches:**
```bash
for each "Delete (branches)" entry:
case "<scope>" in
local)
# Use -d (NOT -D). If unmerged, surface as a loud failure rather than silently destroy work.
git branch -d <branch> 2>&1 || echo "WARN: local branch <branch> not deleted — unmerged commits or already gone"
;;
remote)
git push origin --delete <branch> 2>/dev/null || echo "WARN: remote branch <branch> not deleted — already gone"
;;
both)
git branch -d <branch> 2>&1 || echo "WARN: local branch <branch> not deleted — unmerged commits or already gone"
git push origin --delete <branch> 2>/dev/null || echo "WARN: remote branch <branch> not deleted — already gone"
;;
esac
```
**Currently checked-out branch — switch off before deleting.** `git branch -d` cannot delete the current branch. If the manager is on a branch that's in the delete list, check out a safe parent (the `parent-branch` from the manifest, or the repo default) first:
```bash
CURRENT=$(git branch --show-current)
if [ "$CURRENT" = "<branch-to-delete>" ]; then
git fetch origin --prune
git checkout <parent-branch>
git pull origin <parent-branch>
fi
```
**Never use `-D` (force delete).** If `-d` refuses, that's the safety net working — surface the warning, do not retry with `-D`.
### Step 4 — Print final report
Print a concise human-readable summary to the chat. Format:
```markdown
## Cleanup complete
### Closed
- #<n> — <title> — <reason>
- ...
### Deleted branches
- <branch-name> (local + remote) — <reason>
- ...
### Kept
- #<n> — <title> — <reason>
- ...
### Warnings
- <any failed close/delete with the warning message>
- ...
### Ambiguous (please review)
- <resource> — <agent's reason>
- ...
```
If there are **no actions** (everything was already in the right state), print just: `Cleanup audit: all resources in expected state — nothing to do.`
If the **Ambiguous** section is non-empty, do NOT auto-resolve. Surface to the user and let them decide. The agent's job was to filter the obvious cases; the manager's job is to act on those AND show the unclear ones.
## Notes on safety
- **Closing issues is reversible.** `gh issue reopen` exists. Default to closing when the agent is confident.
- **Deleting branches is harder to reverse.** The agent must show pr-merged=true before proposing delete. If `git branch -d` (without force) refuses, trust the refusal — there are unmerged commits.
- **Unrelated-findings issues are ALWAYS KEPT unless closed by `-fix`.** They are explicitly opt-in follow-up work, so the audit never closes an open one. The exception is the `-fix` / `--auto-fix` auto-fix step in `/x-as-pr` / `/x-wt-teams`: it closes the `agent-found` issues it actually fixed (linking the fix PR) before cleanup runs. The audit leaves those already-closed and keeps every still-open one. The agent's prompt enforces this; the manager doesn't second-guess.
- **The caller's `-m` / `--merge` flag (passed here as `-a` / `--auto-merged`) is the signal for aggressive cleanup.** Without it, prefer keeping branches around — the user may want to inspect locally before deleting. With it and root-PR-merged, the user opted in to full cleanup including local dead branches (this is the specific bug the skill fixes: `--delete-branch` removes remote, the old workflow left local behind).
## When to skip this skill
- The workflow created no GitHub resources (e.g. `/x-as-pr` with `--no-issue` and no merged PR) — the manifest would be empty.
- Mid-workflow halts where resources are intentionally left open for the user to inspect.
- The parent skill is in an error state and shutting down — clean up next session.
In all other cases, the parent skill should invoke `/cleanup-resources` at its STOP point. The audit either confirms everything is already correct (nothing to do, fast) or it catches a missed close/delete.
## Invocation example (from a parent skill)
```
Skill tool: skill="cleanup-resources", args="workflow:x-wt-teams -a"
```
The manager (parent skill) then **continues in the same turn** by building the manifest and following Steps 1–4 above. The args are advisory — they tell the cleanup skill which workflow flavor invoked it, so any workflow-specific hints in this SKILL.md apply.Related Skills
dev-linkify-cc-resources
Link Claude Code skill names mentioned in a CodeGrid article (data/{series}/{n}.md) to the author's public claude-resources repo, pinned to the latest commit hash so links don't rot. Use when: (1) user says 'linkify cc resources', 'link the skills', 'link skill names', or invokes /dev-linkify-cc-resources; (2) editing a CodeGrid article that mentions `/commits`, `/pr-complete`, `/skill-creator` or other Claude Code skills and they should point to claude-resources. Only links skills that actually exist in the public repo; skips hypothetical examples and code blocks.
claude-resources-share
Share Claude Code resources (memories, settings, skills, hooks, etc.) across projects via the centralized claude-settings repo. Use when: (1) User says 'share claude resource', 'sync settings', or 'export to claude-settings', (2) User wants to copy .claude/* files to the central repo, (3) Reusing memory or skills across projects, (4) Backing up local Claude config to the global repo.
zudoesa-articlify
Convert conversation context into an esa article via the zudoesa-writer subagent. ONLY invoke when the user explicitly asks — NEVER proactively propose. Triggers: 'write esa article', 'esa記事', 'esaに書いて', 'articlify for esa', or /zudoesa-articlify. Gathers context, creates a writing brief, delegates to the writer subagent.
zudoesa-apply-voice
Apply Takazudo's esa writing voice and vocabulary rules to text. Use when: (1) User wants to write/rewrite text in Takazudo's esa style, (2) User says 'apply voice', 'esa voice', 'esa文体で', 'esa風に書いて', '文体を適用', (3) User provides text to transform to esa style. Reads writing-style.md and vocabulary-rule.md from takazudo-esa-writing repo and applies the rules.
zudocg-articlify
Convert conversation context into a CodeGrid article via the zudocg-writer subagent. ONLY invoke when the user explicitly asks — NEVER proactively propose. Triggers: 'write codegrid article', 'CodeGrid記事', 'codegridに書いて', 'articlify for codegrid', or /zudocg-articlify. Gathers context, creates a writing brief, delegates to the writer subagent.
zudocg-apply-voice
Apply Takazudo's CodeGrid writing voice and vocabulary rules to text. Use when: (1) User wants to write/rewrite text in Takazudo's CodeGrid style, (2) User says 'apply voice', 'codegrid voice', 'codegrid文体で', 'codegrid風に書いて', '文体を適用', (3) User provides text to transform to CodeGrid style. Reads writing-style.md and vocabulary-rule.md from takazudo-codegrid-writing repo and applies the rules.
zpaper-articlify
Convert conversation context into a zpaper blog article via the zpaper-writer subagent. ONLY invoke when the user explicitly asks — NEVER proactively propose. Triggers: 'write zpaper article', 'zpaper記事', 'zpaperに書いて', 'articlify for zpaper', or /zpaper-articlify. Gathers context, creates a writing brief, delegates to the writer subagent.
zpaper-apply-voice
Apply Takazudo's zpaper blog writing voice and vocabulary rules to text. Use when: (1) User wants to write/rewrite text in Takazudo's zpaper style, (2) User says 'apply voice', 'zpaper voice', 'zpaper文体で', 'zpaper風に書いて', 'ブログ文体を適用', (3) User provides text to transform to zpaper style. Reads writing-style.md and vocabulary-rule.md from the zpaper repo and applies the rules.
xlsx
Spreadsheet creation, editing, and analysis. Use when working with .xlsx, .xlsm, .csv, .tsv files for: (1) Creating spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modifying existing spreadsheets while preserving formulas, (4) Data analysis and visualization, (5) Recalculating formulas.
x
Facade for development workflows. Routes on two axes: plan-first vs implement-now (escalates to /big-plan -a when the request needs research / decomposition / has unclear scope — the appended -a makes the plan chain into implementation in-session), then single vs multi on the ready-to-build fast paths (/x-as-pr single-topic, /x-wt-teams multi-topic parallel). Use when: (1) User says '/x' followed by dev instructions, (2) User wants to start development without choosing the workflow skill, (3) User says 'dev', 'implement', or 'build' with a task. Default option: -v (verify-ui). Review-loop (-l) is opt-in — without -l the downstream skill runs a single /deep-review pass. Forwards -a (autonomy/auto-chain) and -m (merge at the end + cleanup + CI watch) through every route; auto-fix of raised findings (-f) and issue-raising (-ri) are downstream defaults, with -nf/--no-fix and -nori/--no-raise-issues as the forwarded opt-outs. -a and -m are orthogonal — full hands-off end-to-end is -a -m.
x-wt-teams
Parallel multi-topic development using git worktrees, base branches, and Claude Code agent teams. Use when: (1) User wants to work on multiple related features in parallel, (2) User mentions 'worktree', 'base branch', 'parallel development', 'split into topics', or 'multi-topic'. FULLY AUTONOMOUS — creates worktrees, spawns teams, coordinates everything. Also supports Super-Epic child mode for [Epic] issues from /big-plan with '**Super-epic:** #N' markers (targets the super-epic base branch instead of main).
x-as-pr
Start a development workflow as a draft PR. Creates a NEW branch from the current branch, empty start commit, draft PR targeting the current branch, then implements. ALWAYS creates a new branch by default — produces a nested PR-on-PR when the current branch already has one. Use when: (1) User says 'dev as pr', (2) User wants a PR-first workflow before coding, (3) User passes -s/--stay to reuse the current branch instead of nesting, (4) User passes a GitHub issue URL to implement, (5) User passes --make-issue/--issue to create an issue first. Logs progress via issue comments when an issue is linked.