genstarters
Task New #coding#refactor#review

Code Refactor Helper

Refactors a function or file without changing behavior. Explains what changed and why, and flags any behavior it wasn't sure about.

The prompt

I'll paste code. Refactor it for clarity, then output THREE things:

1. **The refactored code** — same behavior, cleaner structure.
2. **Diff summary** — top 5 changes, one line each, why each matters.
3. **Behavior I'm unsure about** — any spot where the original was ambiguous and I made a call. Say what I assumed.

Rules:
- Do not change public API signatures unless I explicitly ask.
- Do not change behavior. If you're tempted to fix a bug, flag it in section 3 instead of silently changing.
- Prefer clarity over cleverness. Named variables over one-liners. Early returns over nested ifs.
- Keep the same language and framework.
- If the code is already good, say so and return it unchanged with one line explaining what's already right.

## How to use it

Paste this prompt, then paste your code (any language). Read section 3 before shipping — that's where the surprises live.

## Why it works

The "unsure about" section prevents the most common refactor bug: silently changing behavior. Every refactor has judgment calls; forcing Claude to surface them makes the review much faster.

How to use it

I’ll paste code. Refactor it for clarity, then output THREE things:

  1. The refactored code — same behavior, cleaner structure.
  2. Diff summary — top 5 changes, one line each, why each matters.
  3. Behavior I’m unsure about — any spot where the original was ambiguous and I made a call. Say what I assumed.

Rules:

  • Do not change public API signatures unless I explicitly ask.
  • Do not change behavior. If you’re tempted to fix a bug, flag it in section 3 instead of silently changing.
  • Prefer clarity over cleverness. Named variables over one-liners. Early returns over nested ifs.
  • Keep the same language and framework.
  • If the code is already good, say so and return it unchanged with one line explaining what’s already right.

How to use it

Paste this prompt, then paste your code (any language). Read section 3 before shipping — that’s where the surprises live.

Why it works

The “unsure about” section prevents the most common refactor bug: silently changing behavior. Every refactor has judgment calls; forcing Claude to surface them makes the review much faster.

✦ More like this

Related prompts