← All commands
✦
Development · /refactor

Refactor

Improve code structure and readability while preserving behavior.

When to use it

Use this when you want to improve readability or changeability without altering behavior.

Useful inputs

  • Code to refactor
  • Behavior that must stay
  • Tests and technical constraints

Instruction

Propose a small-step refactor that preserves behavior. Explain changes and regression risks.

Example input

Code: [Four report branches in one method]. Constraint: API responses must not change. Suggest a small refactor and regression checks.

Example result

1. Add tests that capture each current report response.
2. Move shared validation into a separate method.
3. Extract a small handler for each report type.
4. Verify response bodies and status codes remain unchanged.

Common pitfall

Do not mix a new feature or behavior change into a refactor.