ctx:cleanup

ctx:cleanup is a command for coding agents from shakestzd/contextune. It costs 11 tokens per session (1,455 once invoked), scanned A, original, MIT.

A guided command for cleaning up completed Git worktrees and branches. It checks which feature branches have already been merged into the main branch before preparing removals.

In plain words
What is it for?
Use it to identify merged parallel tasks, review a cleanup plan, and remove their worktrees and local or remote branches when appropriate.
Why use it?
It helps separate merged work that can be removed from unmerged or uncommitted work that should be kept.

Command

Part of the contextune plugin — 8 skills, 14 commands, 5 agents, 6 hooks, 1 MCP server shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/shakestzd/contextune/ctx-cleanup
Clone the repo
git clone --depth 1 https://github.com/shakestzd/contextune

Or install contextune, the plugin that ships this one along with the rest of its 8 skills, 14 commands, 5 agents, 6 hooks, 1 MCP server.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ctx:cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/shakestzd/contextune/ctx-cleanup.svg)](https://agentmods.dev/commands/shakestzd/contextune/ctx-cleanup)
Your own site
<a href="https://agentmods.dev/commands/shakestzd/contextune/ctx-cleanup"><img src="https://agentmods.dev/badge/commands/shakestzd/contextune/ctx-cleanup.svg" alt="Measured on agentmods" height="20"></a>
Per session 11 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,455 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00011 $0.01455
Opus 5 $0.00005 $0.00727
Sonnet 5 $0.00002 $0.00291
Haiku 4.5 $0.00001 $0.00145

Measured 4d ago against content hash 7ebae007f348, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ctx:cleanup scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/ctx-cleanup.md · 299 lines

How it starts

The opening of the file, as written. The whole thing — 299 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Parallel Cleanup - Remove Completed Worktrees

You are performing cleanup of completed parallel development work.

Contextune Integration: This command can be triggered via /contextune:parallel:cleanup or natural language like "clean up parallel worktrees", "remove completed tasks".


Execution Workflow

Step 1: Identify Merged Branches

Check which parallel branches have been merged to main:

# List all feature branches that are fully merged
git branch --merged main | grep "feature/task-"

Expected output:

  feature/task-0
  feature/task-2

Interpret:

  • Listed branches: Safe to delete (already in main) ✅
  • Not listed: Still has unmerged commits ⚠️

Step 2: Show Cleanup Plan (Ask User)

Before deleting anything, show what will be removed:

🧹 Cleanup Plan

**Will remove:**
✅ Worktree: worktrees/task-0 (merged to main)
✅ Local branch: feature/task-0 (merged)
✅ Remote branch: origin/feature/task-0 (if exists)

✅ Worktree: worktrees/task-2 (merged to main)
✅ Local branch: feature/task-2 (merged)
✅ Remote branch: origin/feature/task-2 (if exists)

**Will keep:**
⏳ Worktree: worktrees/task-1 (not merged - has uncommitted work)

Proceed with cleanup? (yes/no)

Ask user for confirmation before proceeding.


Step 3: Remove Merged Worktrees

For each merged branch, remove its worktree:

# Remove worktree for task-0
git worktree remove worktrees/task-0

# Remove worktree for task-2
git worktree remove worktrees/task-2

Expected output per removal:

✅ Removed worktree 'worktrees/task-0'

If removal fails:

Error: worktree has uncommitted changes

→ Skip this worktree, warn user


Step 4: Delete Local Merged Branches

Delete the local branches that were merged:

# Delete local branch
git branch -d feature/task-0

# Delete local branch
git branch -d feature/task-2

Expected output:

Deleted branch feature/task-0 (was abc1234).

Read the full file on GitHub · 299 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 299 lines · 11 tokens per session scan A 7ebae007f348

Subscribe to this mod's changes

ctx:cleanup is a command published in the GitHub repository shakestzd/contextune (5 stars, last pushed 8mo ago), licensed MIT. It adds 11 tokens to every session and 1,455 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.