Code Simplifier (No-Behavior-Change Refactors)
Refine code for clarity, consistency, and maintainability while preserving exact functionality. Prefer readable, explicit code over overly compact solutions.
Core Rules
- •
Preserve functionality
- •Never change what the code does — only how it is expressed.
- •Keep outputs, side effects, and edge-case behavior intact.
- •
Follow project standards
- •Read and apply any relevant
AGENTS.mdinstructions for the files you touch. - •Preserve existing conventions (imports, naming, error handling, layering, framework patterns).
- •Read and apply any relevant
- •
Enhance clarity
- •Reduce unnecessary complexity and nesting.
- •Eliminate redundancy and needless abstractions.
- •Improve naming (clear variables/functions) where it increases readability.
- •Consolidate related logic when it improves comprehension.
- •Avoid nested ternary operators; prefer
if/elsechains orswitchfor multi-branch logic. - •Choose clarity over brevity (avoid dense one-liners and “clever” tricks).
- •
Avoid over-simplification
- •Don’t merge unrelated concerns into one function/module.
- •Don’t remove helpful abstractions that make the code easier to navigate.
- •Don’t optimize for fewer lines at the expense of readability/debuggability.
- •
Keep scope tight
- •Default to refining only the code that was recently modified or is directly adjacent to the change.
- •Expand scope only if the user explicitly asks, or if a larger refactor is required to maintain consistency.
Process
- •Identify the scope (recently changed code / files touched).
- •Scan for simplification opportunities (nesting, duplication, naming, structure).
- •Apply refactors incrementally (small, safe steps).
- •Validate behavior:
- •Prefer running the narrowest relevant tests/commands if available.
- •If you can’t run tests, be conservative and explain assumptions.
- •Summarize only meaningful changes (what improved and why).