Senior-Level Code Review & Refactor Plan
Get a structured senior-engineer-style code review covering correctness, performance, security, and maintainability, ending in a prioritized refactor plan.
Developers and engineering leads who want a thorough, prioritized code review rather than a surface-level style pass, especially before a merge or release.
Act as a senior software engineer conducting a thorough code review. Review the following code written in {{programming_language}}. Structure your review in this exact order:
1. Correctness — identify any logical bugs, edge cases not handled, or incorrect assumptions.
2. Security — flag any vulnerabilities (e.g. injection risks, unsafe deserialization, missing input validation, secrets handling).
3. Performance — identify inefficiencies (e.g. unnecessary loops, N+1 queries, unneeded allocations) and estimate their real-world impact.
4. Maintainability — comment on naming, structure, duplication, and testability.
5. Prioritized refactor plan — list the top 5 changes ranked by impact vs. effort, and provide corrected code snippets for the top 2.
Do not rewrite the entire file. Focus on the highest-impact issues only.
Code:
```{{programming_language}}
{{code_block}}
```How to use
- Replace {{programming_language}} with the language of your code (e.g. Python, JavaScript, Go).
- Paste the specific function or module you want reviewed into {{code_block}} — keep it focused rather than pasting an entire large file.
- Read through the review in order; correctness and security issues should be fixed before performance or style issues.
- Apply the top 2 corrected snippets first, then address the remaining items in the prioritized list.
Example input
Act as a senior software engineer... Code:
```python
def get_user(user_id):
query = "SELECT * FROM users WHERE id = " + user_id
result = db.execute(query)
return result
```Example output
1. Correctness — the function assumes user_id is always a valid, existing ID; no handling for a missing user, which will silently return an empty result rather than raising a clear error.
2. Security — this is a SQL injection vulnerability; user_id is concatenated directly into the query string instead of using parameterized queries.
3. Performance — SELECT * retrieves all columns even if only a subset is needed downstream, increasing payload size unnecessarily.
4. Maintainability — no type hints or docstring; unclear what 'result' returns (single row vs list).
5. Prioritized refactor plan: (1) Fix SQL injection via parameterized query [highest impact, low effort], (2) Add explicit not-found handling, (3) Select only needed columns, (4) Add type hints and docstring, (5) Add unit test for missing user case.
Corrected code:
```python
def get_user(user_id: int) -> dict | None:
query = "SELECT id, name, email FROM users WHERE id = %s"
result = db.execute(query, (user_id,))
return result[0] if result else None
```Customization tips
- — Add context about the code's environment (e.g. 'this runs in a high-traffic production API') so performance and security assessments are calibrated correctly.
- — Ask for a stricter review if the code handles sensitive data (PII, payments, auth).
- — Request the review in a specific format (e.g. as inline comments) if you want to paste it directly into a pull request.
Tags
FAQ
What is this prompt for?
How much code should I paste in at once?
What's a limitation of this prompt?
How is this different from just asking 'review this code'?
Related Prompts
All Coding & Debugging prompts →Legacy Code Explainer & Refactor Planner
Explains what an unfamiliar or legacy piece of code actually does, then proposes a safe, incremental refactor plan instead of a risky full rewrite.
Code Review Simulator
Simulates a thorough senior engineer code review, flagging bugs, edge cases, readability issues, and security concerns with specific, actionable comments.
Root Cause Bug Investigator
Guides a systematic investigation of a bug from symptom to root cause, avoiding quick patches that mask the real problem, and produces a targeted fix.
Related Skills
Code Review & Refactor Assistant
Reviews a pasted code snippet for bugs, readability, and performance issues, then delivers a prioritized refactor with explanations for each change.
Engineering Judgment Coach
Makes an AI coding agent pause and reason like a senior engineer before writing code — right layer, reuse over rebuild, the right pattern, and honest refactor timing.
Code Refactor Advisor
Reviews a code snippet and returns a prioritized refactor plan — readability, structure, and performance issues, each with a concrete fix.
Related Articles
How to Test AI-Generated Code Before You Trust It
Learn how to review and test AI-generated code before using it in production, including functionality, security, edge cases, permissions, and regression checks.
Claude Code Security Concerns Highlight Agent Trust Risks
Claude Code’s recent security controversy shows that coding agents must be reviewed as installed software with trust, telemetry, and policy implications.
Coding Agent Benchmarks Are Moving Toward Task Types
AI coding agents are becoming measurable in real repositories and workplaces, making review practices and task-specific evaluation essential.