Simplify code. Preserve behavior.
When to Use
- Code was recently edited.
- Logic works but reads harder than needed.
- Nesting, repetition, or indirection grew during implementation.
- User asks for cleanup without behavior change.
Goal
Make code easier to read, debug, and maintain. Do not change outputs, side effects, APIs, or user behavior.
Scope
- Recently modified code only.
- Broader scope only when explicitly requested.
Rules
- Preserve features, outputs, side effects, and public behavior.
- Prefer guard clauses over nested branches.
- Prefer clear names over comments.
- Remove redundant abstraction.
- Keep useful abstraction.
- Cut needless nesting, repetition, and indirection.
- Avoid nested ternaries and clever one-liners.
- Do not merge unrelated concerns.
- Do not trade readability for fewer lines.
Flow
- Find touched code.
- Identify high-friction logic.
- Flatten control flow where safe.
- Remove duplication when it clearly helps.
- Rename unclear locals when useful.
- Keep behavior identical.
- Run relevant checks when feasible.
Output
## Simplified
- [changed area]
## Preserved
- [behavior kept]
## Verification
- [check run or reason not run]