These code review and refactoring prompts help you review pull requests, spot bugs and security issues, improve readability, reduce duplication, modernise legacy code and refactor safely in small steps.
20 prompts on this page. Last updated: 4 December 2026. Written and tested by Saad Raza.
How to use these prompts
- Click Copy on any prompt.
- Paste it into ChatGPT, Claude, Gemini, Copilot or Perplexity.
- Replace everything in [square brackets] with your own details. The more specific you are, the better the answer.
- Read and edit the result before you use it. Add your own experience and check every fact, name and number.
Give the AI your language, version, framework and coding conventions, and paste the relevant code rather than describing it. Review, run and test every generated change before merging it, and never paste secrets, keys or private customer data into an AI tool.
Reviewing
1. Review a pull request
Review this diff as a senior [language] engineer: [paste]. Comment on correctness, edge cases, security, performance, readability and tests. Label each comment as blocking, suggestion or nitpick.
2. Security review
Review this code for security issues: injection, authentication and authorisation flaws, insecure data handling, secrets, and unsafe dependencies. Explain each risk and the fix: [paste].
3. Performance review
Review this code for performance: unnecessary loops, N+1 queries, blocking calls, memory use and caching opportunities: [paste].
4. Check error handling
Review how this code handles errors and failures: missing checks, swallowed exceptions, unclear messages and retries: [paste].
5. Review tests in a PR
Review the tests in this change. Do they cover the new behaviour and edge cases? What tests are missing? [paste].
6. Write review comments kindly
Rewrite these code review comments to be clear, specific and respectful, explaining the why: [paste comments].
Refactoring
7. Refactor for readability
Refactor this code for readability: clearer names, smaller functions, fewer nested conditions and comments only where needed. Keep behaviour identical: [paste].
8. Remove duplication
Find duplicated logic in these files and suggest a shared abstraction without over-engineering: [paste].
9. Apply a design pattern
Would [pattern, e.g. strategy, factory or repository] improve this code? If so, refactor it and explain the trade-offs: [paste].
10. Break up a large function
Split this long function into smaller, well-named functions with a single responsibility each: [paste].
11. Simplify complex conditionals
Simplify these nested if statements using guard clauses, lookup tables or polymorphism, keeping the same behaviour: [paste].
12. Improve naming
Suggest clearer names for the variables, functions and classes in this code: [paste].
13. Add types
Add type annotations or convert this [JavaScript or Python] code to [TypeScript or typed Python] without changing behaviour: [paste].
Legacy code
14. Understand legacy code
Explain what this legacy code does, its hidden assumptions and risky areas before I change it: [paste].
15. Plan a safe refactor
Plan a step-by-step refactor of [module] that keeps the code working at every step, with characterisation tests first: [describe code].
16. Modernise old code
Update this code to modern [language version] idioms and replace deprecated APIs: [paste].
17. Upgrade a dependency
I need to upgrade [library] from [version] to [version]. List breaking changes to check and update this code accordingly: [paste].
Standards
18. Write a code review checklist
Create a code review checklist for our [language or framework] team covering correctness, tests, security, performance, readability and documentation.
19. Write coding guidelines
Draft coding guidelines for our team in [language]: naming, structure, error handling, testing and comments, with short examples.
20. Measure technical debt
Here is a description of our codebase problems: [paste]. Group them into technical debt categories, estimate impact and suggest a plan to pay them down.
What are code review and refactoring prompts?
Code review and refactoring prompts help you review pull requests for bugs, security and performance, clean up code for readability, remove duplication, simplify conditionals, add types, modernise legacy code and write team review guidelines. AI code review is a fast first pass that complements, not replaces, human reviewers.
How to write better code review and refactoring prompts
- Review the diff in context: include related files when needed.
- Label comment severity: blocking, suggestion or nitpick.
- Refactor with tests: lock in behaviour before changing structure.
- Keep changes small: one refactor per pull request.
Best AI tools to use with these prompts
Use ChatGPT or Claude for focused reviews, AI review bots on GitHub or GitLab for automatic pull request comments, linters and formatters for style, and static analysis tools such as SonarQube or Semgrep for code quality and security.
Frequently asked questions
Can AI review code?
AI can catch many bugs, security issues and style problems quickly. Use it alongside human review, which understands the product context and design decisions.
How do I refactor safely?
Add tests that capture current behaviour first, change code in small steps, run tests after each step and avoid mixing refactoring with new features.
What should a code review focus on?
Correctness, edge cases, security, tests and readability come first. Style issues are best handled by linters and formatters.
Can AI review pull requests?
Yes. AI can catch bugs, security issues and readability problems quickly. Human reviewers still judge design and product decisions.
What is refactoring?
Changing the structure of code to make it clearer or easier to maintain without changing what it does.
More software development prompts
- Code Generation PromptsWrite functions, classes, scripts and boilerplate.
- Debugging PromptsFind and fix bugs, errors and performance problems.
- Software Testing PromptsUnit, integration and end-to-end tests.
- Technical Documentation PromptsREADMEs, API docs, comments and guides.
- SQL and Database PromptsQueries, schema design, indexes and optimisation.
- API Development PromptsDesign, build, secure and document APIs.
- DevOps PromptsCI/CD, Docker, cloud, monitoring and deployment.
- System Design and Architecture PromptsArchitecture, scaling, trade-offs and design reviews.
Back to all software development prompts or the full prompt library, including SEO prompts.
Great software deserves customers who can find it. Request a free audit and I will show you what to fix first.
Request received
Thank you! Saad will contact you within the next 24 hours.
Keep an eye on your phone and inbox.
