/second-brain-skills:cleanup-after-commitfrom second-brain-skills
Removes merged temporary branches, stray worktree copies, and leftover scratch files after a PR merge or burst of commits. Audits branches before deleting and never touches unmerged work.
Ships in second-brain-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Branches pile up because nothing removes them, not because anyone is lazy. Fix the cause first, then sweep what is already there, and never delete work that exists nowhere else.
Turn on automatic deletion of head branches after a PR merges:
gh repo edit OWNER/REPO --delete-branch-on-merge
A mature platform setting beats a cleanup script. Check every repo you own:
gh repo list OWNER --json name,isArchived -q '.[]|select(.isArchived|not).name' then
gh api repos/OWNER/NAME -q .delete_branch_on_merge. Archived repos are read-only, skip them.
List non-default branches and judge each one. Delete nothing during the audit.
gh api repos/OWNER/REPO/branches --paginate -q '.[].name'
git fetch --prune origin
git for-each-ref --format='%(refname:short) %(committerdate:short)' refs/remotes/origin
Verdict per branch:
git rev-list --count origin/main..origin/BR is 0).gh pr list --head BR --state merged --json headRefOid,mergedAt).After a squash or rebase merge the branch commits are not in the default branch as-is, so "commits ahead"
stays above zero forever. Do not delete on "a merged PR exists": commits pushed to the branch after the
merge would be lost. Compare the branch tip SHA with the merged PR's head SHA. Only a match is proof.
To rescue a branch instead of deleting it, use git cherry origin/main origin/BR and merge.
git push origin --delete BR # one branch at a time
Write a restore file BEFORE deleting, one line per branch: BR <tip-sha>. Restoring is
git push origin <sha>:refs/heads/BR. Never delete protected names (main, master, gh-pages,
release*, production). If a sweep would remove ten or more branches, state the count and the restore
file path and get the owner's explicit yes first.
git branch --merged origin/main # merged local branches, safe to `git branch -d`
git worktree list # extra worktrees are usually leftovers
Use git branch -d (not -D): it refuses unmerged work. Remove a stale worktree with
git worktree remove PATH only after checking it has no uncommitted changes (git -C PATH status).
A branch created for one experiment, a throwaway workflow file, scratch output: remove it in the same pass instead of "later".
Like this skill? It is part of second-brain-starter-kit: the second brain we built for ourselves and run every day at Palo Alto AI Research Lab. Install the whole set with npx skills add tonydzi/second-brain-starter-kit. Everything is open source and free, so take what you need.
Flagships worth a look on their own: secondop-panel (a second opinion from a panel of external models), claude-memory-tidy (stop your agent's memory from rotting), telegram-mcp-kit (your own Telegram over MCP in about 15 minutes).
Author: Anton Dziatkovskii, Palo Alto AI Research Lab. Telegram @tonydzi - WhatsApp +1 341 222 9178 - X @Tony_Stef_
Engineers: want to test-drive this setup? Message me. I hand out free starter seeds to engineers who test and report back, and custom skill requests are welcome.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tonydzi/second-brain-starter-kit --plugin second-brain-skills248 skills in this plugin
/03Run an autonomous consensus round between agent peers on several machines: they negotiate a decision over a shared channel and execute it without a human relaying messages. Use when multiple machines must agree on a change. Triggers: "/03", "work it out among yourselves", "find consensus". Wakes the human only for irreversible actions or a deadlock./1Recover a session after a hard crash (app died, machine rebooted, context lost mid-work): replay the turn-state ledger for the last requests, files and decisions, run a green/red health ping over the system map, file sync and MCP connectors, then rebuild the previous session history for pickup. Triggers: "/1", "resume after crash", "wake"./agendaShow the operator's day: today's calendar plus what needs them personally (leads due, people awaiting a reply, deadlines), pulled from Calendar and Telegram and ranked. Read-only: sends and commits nothing. Triggers: "/agenda", "what's on today", "my agenda".Other plugins' skills for the same job