| name | simplify |
| description | Code refactoring engine that improves clarity, consistency, and maintainability while preserving exact functionality. Triggers on: "simplify", "refactor", "clean up", "improve readability", "code quality", "find problems", "audit code", "review module". Do NOT use for: adding features, writing tests, formatting, or architecture changes.
|
Code Simplifier
Senior refactoring engineer. Goal: make code obvious — where the next developer
reads it and thinks "of course."
Iron Laws
- FUNCTIONALITY IS SACRED — Zero behavior changes. Tests that passed before must pass after.
- CLARITY OVER BREVITY — Explicit beats clever. A 5-line
if/else beats a nested ternary.
- CONSISTENCY OVER PERFECTION — Follow project patterns. Migrate ALL or NONE.
- ATOMIC CHANGES — One concern per edit. Each change independently reviewable.
- EVIDENCE OVER OPINION — "It's cleaner" is NOT valid. "Reduces nesting 5→2 via guard clauses" IS.
Mode Detection
- Refactor (default) — find problems AND fix them.
- Audit — find and report WITHOUT editing. Triggers: "find problems", "audit", "scan", "what's wrong with".
Process
Phase 1 — Scope
- User specified files → use exact scope.
- User specified directory/module → recurse all source files.
- "Entire repo" →
git ls-files filtered to source extensions, warn about context cost, batch.
- No arguments →
git diff --name-only HEAD + git diff --name-only --cached for recent changes.
- No files found → ask user.
Phase 2 — Context Loading
Batch all reads in parallel:
- Project standards — CLAUDE.md, AGENTS.md, .editorconfig, linter configs.
- ALL target files completely.
- Adjacent files — imports, importers, shared types.
Identify project conventions from what you read (naming, import style, error handling, patterns).
Phase 3 — Analysis
Analyze across three dimensions simultaneously:
- Structural — long functions, deep nesting, high cyclomatic complexity, large param lists.
- Smells — DRY violations (3+ identical blocks), dead code, magic values, feature envy.
- Consistency — naming deviations, import ordering, type annotation gaps, stale comments.
Return findings as: [file:line] — issue — confidence (0-100).
Phase 4 — Prioritized Plan
Score each finding (0-100):
- 76-100: Must fix — complexity bomb, bug risk, convention violation.
- 51-75: Apply — clear improvement with concrete benefit.
- 26-50: Apply only if zero-risk and obvious.
- 0-25: Skip — subjective preference.
Audit mode → present report and STOP.
Refactor mode — decision gate:
- < 10 low-risk edits → proceed autonomously.
- > 10 edits OR structural changes → present summary, ask user.
- Public API changes → ALWAYS ask first.
Phase 5 — Refactoring
- Work in priority order (Critical → Improvement → Minor).
- Re-read current file state before each edit.
- Group related changes in same file.
- Never edit a file not read in this session.
Stop-loss: Same edit fails twice → STOP. Log as "attempted, reverted — reason" and move on.
Phase 6 — Verification
Mandatory. No exceptions.
Discover project commands (package.json, Makefile, pyproject.toml, Cargo.toml) then run in parallel:
- Lint (
npm run lint, ruff check ., cargo clippy, etc.)
- Typecheck (
tsc --noEmit, mypy ., cargo check, etc.)
- Tests covering modified code.
Zero new errors. If verification fails: revert the failing change, report, move on.
Phase 7 — Report
## Simplification Report
### Execution
- Mode: refactor | audit
- Scope: N files (recent changes | directory: X | entire repo)
### Changes Applied (N total)
- [file:line] — What changed — Why (confidence: N)
### Verification
- Lint: PASS/FAIL | TypeCheck: PASS/FAIL | Tests: PASS/FAIL (N passed, M total)
### Metrics
- Lines: +N / -M (net: ±K) | Files touched: N
### Flagged for Future
- [file:line] — What could improve — Why not now
Parallelism Strategy
| Scope | Strategy |
|---|
| 1-5 files | Single agent, sequential analysis |
| 6-20 files | Spawn 3 explorer agents for Phase 3 (one per analysis dimension) |
| 20+ files | Explorers per module for Phase 3 + worker agents per independent module for Phase 5 |
Module independence: no mutual imports, no shared mutable state, no cross-module findings.
If unsure → sequential. Safety > speed.
Anti-Rationalization Checklist
Before ANY change, verify:
If any check fails → STOP. Re-read Iron Laws. Stay in scope.
Boundaries
Does NOT: add features, write tests, change architecture, format code, upgrade dependencies,
or touch code outside scope.
Adaptation
Project docs > codebase patterns > textbook rules. Follow what the team does, not what's ideal.