| name | rein-cleanup |
| description | Run a regression-tests-first cleanup/refactor workflow to reduce slop |
rein-cleanup
Reduce bloated, noisy, repetitive, or over-abstracted code with a regression-tests-first, smell-by-smell cleanup workflow that preserves behavior and raises signal quality.
When to Use
Use this skill when:
- A code path works but feels bloated, noisy, repetitive, or over-abstracted
- A user asks to "cleanup", "refactor", or "deslop" output
- Follow-up implementation left duplicate code, dead code, weak boundaries, missing tests, or unnecessary wrapper layers
- You need a disciplined cleanup workflow without broad rewrites
Scoped File Lists
- This skill can accept a file list scope instead of a whole feature area.
- When the caller provides a changed-files list, keep the cleanup strictly bounded to those files.
Procedure
-
Lock behavior with regression tests first
- Identify the behavior that must not change
- Add or run targeted regression tests before editing cleanup candidates
- If behavior is currently untested, create the narrowest test coverage needed first
-
Create a cleanup plan before code
- List the specific smells to remove
- Bound the pass to the requested files or scope
- If a file list scope is provided, keep the pass restricted to that changed-files list
- Order fixes from safest and highest-signal to riskiest
- Prefer deletion or local simplification before helper extraction
- Do not start coding until the cleanup plan is explicit
-
Categorize issues before editing
- Duplication: repeated logic, copy-paste branches, redundant helpers
- Dead code: unused code, unreachable branches, stale flags, debug leftovers
- Needless abstraction: pass-through wrappers, speculative indirection, single-use helper layers
- Boundary violations: hidden coupling, leaky responsibilities, wrong-layer imports or side effects
- Missing tests: behavior not locked, weak regression coverage, gaps around edge cases
-
Execute passes one smell at a time
- Pass 1: dead code deletion
- Pass 2: duplicate removal
- Before adding a helper or abstraction, confirm that deletion or local simplification is not enough
- Pass 3: naming and error handling cleanup
- Pass 4: test reinforcement
- Re-run targeted verification after each pass
- Avoid bundling unrelated refactors into the same edit set
- Do not use cleanup as permission for unrelated refactors or architectural rewrites
-
Run quality gates
- Regression tests stay green
- Lint passes
- Typecheck passes
- Relevant unit and integration tests pass
- Static or security scan passes when available
- Diff stays minimal and scoped
- No new abstractions unless they remove repeated real complexity
- No new dependencies unless explicitly required
-
Finish with an evidence-dense report
- Changed files
- Simplifications made
- Tests, diagnostics, or build checks run
- Remaining risks
- Residual follow-ups or consciously deferred cleanup
Output Guidance
Deliver the cleanup result as a normal agent response in natural language.
- Do not wrap the cleanup summary in a fenced markdown block unless the user explicitly asks for raw markdown.
- A short paragraph plus flat bullets is preferred over a rigid template.
- Cover:
- scope
- behavior lock
- cleanup plan
- passes completed
- quality gates
- changed files
- remaining risks
- Use explicit
PASS or FAIL labels only when they add clarity; otherwise speak plainly as the agent.
Scenario Examples
Good:
- The user says
continue after tests already lock behavior and the next smell pass is clear. Continue with the next bounded cleanup pass.
- The user narrows the scope to a specific file after planning. Keep the regression-tests-first workflow, but apply the new scope locally.
Bad:
- Start rewriting architecture before protecting behavior with tests.
- Collapse multiple smell categories into one large refactor with no intermediate verification.