cleanup-all

A command for cleaning every Lean source file in a project through separate worker agents. Lean is a programming language and proof system used to write software and formally check proofs.

In plain words
What is it for?
Use it to run a project-wide cleanup over Lean files while excluding build, dependency, and version-control directories.
Why use it?
It divides a large cleanup into smaller file-level tasks so the main session can coordinate the work without holding every file's details at once.

Command

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/cbirkbeck/mathlib-quality/cleanup-all
Clone the repo
git clone --depth 1 https://github.com/CBirkbeck/mathlib-quality
Per session 120 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,903 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.00120 $0.04903
Opus 5 $0.00060 $0.02452
Sonnet 5 $0.00024 $0.00981
Haiku 4.5 $0.00012 $0.00490

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

Security

Grade A, and why

cleanup-all 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 2d 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/cleanup-all.md · 489 lines

How it starts

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

/cleanup-all — Project-Wide Cleanup (Orchestrator Mode)

Run the full /cleanup workflow over every .lean file in the project, sustained across hours or days, without exhausting the orchestrator's context.

The trick: the main session is an orchestrator, not an implementer. The orchestrator dispatches batched Agent calls, each with a tight prompt and a concrete target, then narrates progress in one-line scoreboards between dispatches. The file reading, the LSP calls, the edits, and the per-declaration golf all happen in subagent contexts — each starts fresh, does its batch, returns a summary. The orchestrator never holds the work in its own context.

This pattern was observed in a real production session that ran for 28 days across 23 active days, dispatched 395 Agent calls, spawned 790 subagent contexts (workers spawning sub-workers), and survived 3 auto-compactions without losing the through-line. The mechanism is the orchestrator/worker split, not heroic context management.

Usage

/cleanup-all [directory]

If no argument, processes all .lean files under the project root (excluding .lake/, build/, .git/).


The orchestrator's role (binding)

You are the orchestrator. Your job is to dispatch and track. You do NOT:

  • Read project .lean files — workers do that, they need the fresh context for it
  • Run lean_diagnostic_messages, lean_goal, lean_multi_attempt, or any lean_* LSP query
  • Use Edit or Write on project files
  • Run lake build yourself (workers do that as the first check of every batch)
  • Spot-check the worker's diff or rerun their LSP queries

You DO:

  • Enumerate files (one find call, once)
  • Bucket files by size for batched dispatch
  • Dispatch Agent calls following the verbatim prompt template below
  • Maintain a one-line scoreboard between dispatches
  • Collect per-batch summaries from the workers' reports
  • Dispatch one final verification Agent at the end
  • Print the consolidated report at the very end

Read the full file on GitHub · 489 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. 2d ago First seen · 489 lines · 120 tokens per session scan A db7e5785d936

Subscribe to this mod's changes

cleanup-all is a command published in the GitHub repository CBirkbeck/mathlib-quality (32 stars, last pushed 14d ago), licensed MIT. It adds 120 tokens to every session and 4,903 once invoked, about $0.0006 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-30.