clean-code

A command for rewriting existing source code to make it easier to read while preserving its behavior. It can improve names, simplify structure, and remove repetitive generated code.

In plain words
What is it for?
Use it to clean selected source files or directories, with validation such as tests, type checking, or linting. A dry-run option can show proposed changes first.
Why use it?
It addresses hard-to-maintain code without turning the task into a feature change. Checks before and after the rewrite help detect regressions.

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/acaprino/daodan/clean-code
Clone the repo
git clone --depth 1 https://github.com/acaprino/daodan
Per session 80 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,488 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.00080 $0.01488
Opus 5 $0.00040 $0.00744
Sonnet 5 $0.00016 $0.00298
Haiku 4.5 $0.00008 $0.00149

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

Security

Grade A, and why

clean-code 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.

exports/claude/plugins/clean-code/commands/clean-code.md · 159 lines

How it starts

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

Clean Code

Use the clean-code-agent to rewrite source code for readability without changing behavior.

Rules

  1. Validate before and after. Establish a baseline with type checker + tests + linter, then verify no regressions.
  2. If --dry-run, preview only. Show proposed changes without modifying files.
  3. Revert on failure. If any validation fails after a change, revert with git restore <file> immediately.
  4. Ask for confirmation at Steps 2 and 3, unless --yes flag is provided.
  5. Block without validation tools. If no tests AND no type checker exist, require --force to proceed.

Step 1: Identify Target

From $ARGUMENTS, determine files to clean:

  • If a file path: clean that file
  • If a directory: clean all source files in it
  • Filter out test files (unless they reference renamed symbols)

List the files to be cleaned and their language.

Step 2: Establish Validation Baseline

Detect available validation tools by inspecting project files:

Tool How to detect Command
Type checker tsconfig.json tsc --noEmit
mypy.ini, pyrightconfig.json, or mypy/pyright in pyproject.toml mypy . or pyright
Cargo.toml cargo check
go.mod go vet ./...
Test runner package.json npm test
pyproject.toml or setup.py pytest
Cargo.toml cargo test
go.mod go test ./...
Makefile with test target make test
Linter ruff.toml or ruff config in pyproject.toml ruff check
.eslintrc* or eslint.config.* eslint
Cargo.toml cargo clippy

Run all detected tools and capture both stdout and stderr. Record the baseline.

Hard gate: if NO tests AND NO type checker are found, stop and tell the user:

No tests or type checker found. Cannot validate that changes are safe.

1. Cancel -- set up tests or type checking first (recommended)
2. Proceed with --force -- I'll be careful but regressions may go undetected

Read the full file on GitHub · 159 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 · 159 lines · 80 tokens per session scan A 07ab7b124763

Subscribe to this mod's changes

clean-code is a command published in the GitHub repository acaprino/daodan (8 stars, last pushed 6d ago), licensed MIT. It adds 80 tokens to every session and 1,488 once invoked, about $0.0004 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.