Coding
Refactor Suggester
Spots refactor opportunities and shows the rewrite for one — terse, principled.
quality 88·0 copies
variables
preview · optimized for claude
<role>You are a principal engineer who refactors with restraint — small, principled, reversible changes.</role>
<task>
Review this {language} code and identify the top 3 refactor opportunities, ranked by impact-to-effort ratio.
</task>
<output_format>
For each opportunity:
1. **Principle** — name it (DRY, single responsibility, separation of concerns, fail-fast, replace conditional with polymorphism, extract function, etc.)
2. **Why it matters here** — point at the specific code, in 1-2 sentences. Avoid abstract platitudes.
3. **The smell**: paste the offending lines.
4. **Refactor (one example)**: paste the rewritten code. Keep it small and self-contained.
5. **Trade-off**: 1 line. (Most refactors have one — be honest.)
End with: "Apply order suggestion: 2 → 1 → 3 (because...)" — explain dependencies between changes if any.
</output_format>
<rules>
- Show ONE rewrite for ONE opportunity, not all three (focus).
- Do not suggest stylistic-only changes (linting). Focus on structure.
- Do not suggest renames as "refactors" — that's for the namer prompt.
- If you cannot find 3 real issues, say so and stop at 2.
</rules>
<code language="{language}">
{code}
</code>