Stop Copy-Pasting Code Into ChatGPT: The Right Way to Use AI for Code Review
You know that feeling when you're knee-deep in a PR, and you need a second set of eyes? Yeah, AI can help with that. But most people are doing it wrong.
They paste random code into ChatGPT, get a generic response about "best practices," and then ignore it. That's not code review—that's theater.
Here's how to actually use AI to catch real bugs and surface actual improvements.
The Context Problem
AI can't review code in a vacuum. If you dump 200 lines of production code into a generic AI tool without context, it'll tell you to add docstrings and follow PEP-8. Useful? Maybe. Relevant to your actual codebase? Probably not.
Before you paste anything, ask yourself:
- What's this code actually doing?
- What's the one thing you're unsure about?
- What would break if this had a bug?
- Are there specific performance constraints?
That's your prompt. Not "review this code" — but "this function parses 50MB CSV files; does it leak memory?"
Real Example: The Memory Leak Nobody Noticed
I once had a data processing pipeline that loaded user records into memory. The code looked fine. Ran fine in testing. But processing 10 million records? It'd crash halfway through.
Instead of throwing it at an AI and hoping, I asked specifically: "This function keeps appending objects to a list. In production, we process 100,000s of records. Will this cause memory issues?"
Suddenly, the AI spotted the issue: the list was never garbage collected because a reference was held elsewhere in the module. Fix? Move the reset outside the loop.
That's the difference between generic feedback and actually useful review.
The Tools Matter (But Less Than You Think)
GitHub Copilot, Claude, GPT-4, Gemini—they're all fine. The real difference isn't the tool; it's how you frame the question.
Here's what actually works:
For spotting logic bugs: Ask for potential edge cases. "This function sorts user IDs and finds duplicates. What happens if the list is empty? Null values mixed in? Duplicates in the middle vs start/end?"
For performance issues: Be specific about the constraint. "This runs on user devices with 2GB RAM. Will iterating through this list twice matter?"
For security: Name the threat. "This endpoint takes a filename parameter. How could an attacker abuse that?"
For maintainability: Ask what future you will miss. "A junior dev joins in 6 months. What could they break in this function?"
Practical Workflow
Clone the context. Copy the function AND the code that calls it. Add a comment showing the expected input/output.
Ask one specific question. Not "is this good?" but "could this race condition happen if two requests hit this simultaneously?"
Evaluate the response. AI hallucinates. Check the fix against your actual codebase. Does it make sense? Run it locally.
Document the reason. If you implement a suggestion, leave a comment explaining why. Future you (and your team) will thank you.
Don't blindly trust it. AI is a thinking partner, not an oracle. You still have to understand what you're shipping.
When AI Code Review Actually Saves Time
- Catching off-by-one errors in loops
- Spotting missing null checks
- Finding unused variables and imports
- Suggesting better algorithm choices when you describe the problem
- Identifying inconsistent error handling
- Pointing out security issues in auth flows
When It Falls Flat
- Anything requiring knowledge of your business logic
- Code that depends on external APIs behaving in specific ways
- Optimization for your specific infrastructure
- Understanding why something was written that way (context that only humans have)
That's when you need a human reviewer. AI is the pre-flight check; your team is the safety inspector.
The Actual Workflow
Before you hit "Request Review" on that PR:
- Self-review your own code once (you'll catch 60% of issues)
- Ask AI one targeted question about the part you're least confident about
- Fix anything that makes sense
- Submit the PR with context in the description
Yeah, you might still get feedback from humans. But it'll be higher-level feedback about design, not "you forgot a semicolon."
Quick Wins to Start Today
- Paste your last 3 PRs into AI with this prompt: "What could go wrong if this code ran 1000x more often than expected?"
- For that function you wrote that feels "off": "Tell me three ways this could fail under load."
- Before deploying migrations: "What edge cases could break this schema change?"
One More Thing
If you're using AI for code review, you might also want to check out LearnAI Weekly newsletter for weekly breakdowns of AI tools that actually ship value, plus real examples from production codebases.
AI isn't magic. It's a tool that works best when you know exactly what you're asking. Treat it like a mentor who's always available but sometimes confidently wrong—ask good questions, verify the answers, and keep your brain in the loop.
Happy reviewing.
Top comments (0)