
- Updated
Make confusing code easy to read
This prompt rewrites hard-to-follow code so a new teammate can understand it quickly. It keeps the same inputs, outputs and side effects, and lists every change with a short reason.
Act as a senior developer who writes very readable code. Code: [PASTE] Rewrite it so a new team member can understand it quickly, without changing what it does. Use clear names, smaller functions, early returns instead of deep nesting, and remove clever tricks. Keep the same inputs, outputs and side effects. Show the new code, then list each change with a short reason, and point out anything whose behaviour you were unsure about.
Run your tests before and after. If there are no tests, ask for a few first so you know the rewrite did not change behaviour.
Get a better result
Your code rewritten for a newcomer, with clearer names, smaller functions and early returns, the same inputs, outputs and side effects, a list of each change with a reason, and notes on anything the AI was unsure about.
The prompt names the reader, a new team member, which sets the bar better than “clean code”. Keeping inputs, outputs and side effects fixed is the guard rail that turns a rewrite into a safe refactor. The list of changes and the “unsure” section make the result reviewable, so you can accept parts of it rather than all or nothing.
The rewrite quietly changes behaviour.
Fix: Run your tests before and after, as the tip says, and read the “unsure” list first. That is where a changed edge case hides.
- Small helpers are split out until the code is hard to follow. Ask it to extract a function only when it gets a name that explains something, and to keep short steps inline.
- It renames things that other files depend on. Say which names are public or used elsewhere, and ask it to keep those and only rename locals.
Paste a file your team thinks is well written and ask for the rewrite to follow its naming, comment style and error handling.
Split this rewrite into small steps, one change per commit, each with a commit message and a note on how to check it.
More chat & writing prompts
See all 465 →More like this
- Convert code from one language to anotherChatGPT · Gemini · Claude
- Refactor messy code safelyChatGPT · Gemini · Claude
- Write unit tests for your codeClaude · ChatGPT · Gemini
- Review code written by an AI before you trust itClaude · ChatGPT · Claude Code
- Find dead code and safe things to deleteClaude · ChatGPT · Claude Code



