How to review AI-written code before you keep it
AI coding agents can write a lot of code fast, and some of it will be wrong. Cursor's docs put it plainly: "AI-generated code can look correct but be subtly wrong. It might follow existing patterns, compile, and pass tests you wrote, but still miss edge cases, have security issues, or duplicate logic that exists somewhere else in your codebase." (checked Oct 2026) GitHub says the same about Copilot: "you should always validate the code it suggests." (checked Oct 2026)
This guide is a beginner checklist for reviewing an agent's changes, using Git and each tool's own review and undo features. It's quoted from Anthropic, OpenAI, Cursor, GitHub, VS Code, Git and OWASP docs, checked Oct 2026.
Not affiliated with or endorsed by Anthropic, OpenAI, Anysphere, GitHub, Microsoft or OWASP. Check their current docs before relying on these details.
Cursor also says: "Your standards for what gets merged should be the same whether the code was written by hand or by an agent." (checked Oct 2026)
Step 1: Commit before the agent starts
Git is your real safety net. OpenAI's Codex docs say "Create Git checkpoints before and after a task so you can revert changes" (checked Oct 2026), and "Commit frequently so you can roll back in small increments." (checked Oct 2026)
Before you ask for a change, save your current work:
git add -A
git commit -m "Before AI change"
git commit will "Create a new commit containing the current contents of the index and the given log message describing the changes." (checked Oct 2026)
Step 2: Look at every changed file
When the agent finishes, check what it touched:
git status
git diff
git status shows files that changed and "paths in the working tree that are not tracked by Git" (checked Oct 2026), meaning new files. git diff shows the "Changes in the working tree not yet staged for the next commit." (checked Oct 2026)
Our advice, not a vendor quote: read the whole list, not just the file you asked about. OWASP's AI coding cheat sheet warns: "Agents routinely touch files beyond the scope of the requested change: lockfiles, CI configurations, unrelated tests, formatting changes, and dependency updates. Reviewers anchored on the requested change miss these modifications." (checked Oct 2026)
VS Code's review docs say "Agents can change files through editing tools, terminal commands, scripts, and MCP tools" (checked Oct 2026), so check "changes that might not appear in a tool-specific list of edits." (checked Oct 2026)
Step 3: Watch for these warning signs
From OWASP's AI cheat sheet, look extra hard at:
- Weakened or deleted tests. "AI agents make CI green by deleting failing tests, weakening assertions, mocking the unit under test instead of fixing the code, or asserting the buggy behavior." (checked Oct 2026) Our advice, not a vendor quote: ask why any test was removed.
- Build and install scripts. OWASP's AI coding cheat sheet says to review AI changes to package.json scripts (like postinstall) and .github/workflows/*.yml files "with heightened scrutiny -- treat them as security-critical" (checked Oct 2026).
- Changes you didn't ask for. Our advice, not a vendor quote: look for changes you didn't ask for, like new dependencies or edits to unrelated files.
- New routes and queries. Our advice, not a vendor quote: check each one for a permission check, input validation and data it shouldn't return. OWASP's Authorization cheat sheet says "Permission should be validated correctly on every request" (checked Oct 2026) and "Access control checks must be performed server-side" (checked Oct 2026). Its SQL Injection cheat sheet says input validation "is also recommended as a secondary defense in ALL cases" (checked Oct 2026). The Authorization sheet also says to "Ensure sensitive information, such as system logs or debugging output, is not exposed in error messages." (checked Oct 2026)
- Deploys, migrations and production data. Our advice, not a vendor quote: don't let the agent do these on its own. OWASP's AI agent cheat sheet says to "Require explicit approval for high-impact or irreversible actions" (checked Oct 2026). It also says: "Require step-up authentication for critical actions such as account recovery, payment initiation, privilege changes, bulk deletion, or production deployment." (checked Oct 2026) See AI agent permissions for beginners.
GitHub also suggests you "Consider not just the functionality and security of the suggested code, but also the readability and maintainability of the code moving forward." (checked Oct 2026)
Step 4: Run the checks yourself
GitHub says "Use automated tests and tooling to check Copilot's work." (checked Oct 2026) Anthropic suggests you "Give Claude a check it can run: tests, a build, a screenshot to compare." (checked Oct 2026)
Our advice, not a vendor quote: don't rely only on tests the agent wrote. OWASP notes "A passing test suite generated by the same agent that produced the code provides no independent assurance." (checked Oct 2026)
Step 5: Check for secrets
Our advice, not a vendor quote: make sure the change didn't add a password, API key or token to your code. If your code is on GitHub, two of its features help. Secret scanning "scans your entire Git history on all branches of your repository for hardcoded credentials" (checked Oct 2026), and for public repositories it "runs automatically for free." (checked Oct 2026) Push protection "blocks pushes that contain secrets before they reach your repository." (checked Oct 2026)
For more, see our guide on keeping secrets safe with AI coding tools.
Step 6: Use your tool's own review and undo
Each tool has its own features, and each one has limits.
Claude Code: "Run /rewind, or press Esc twice when the prompt input is empty, to open the rewind menu." (checked Oct 2026) You can restore code, the conversation, or both. But "Checkpointing does not track files modified by Bash commands" (checked Oct 2026), and Anthropic says to "continue using version control, such as Git" (checked Oct 2026) for real history.
Codex CLI: run /review to "review any changes and find issues" (checked Oct 2026). OpenAI's docs don't describe a built-in undo, so use Git checkpoints. The docs say to "Treat Codex suggestions like any other PR: run targeted verification, review diffs, and document decisions in commit messages". (checked Oct 2026)
Cursor: "After the agent finishes a task, click Review then Find Issues to run a dedicated code review." (checked Oct 2026) To go back, "click any checkpoint in the chat timeline to preview your files at that point, then restore to revert all files to that state." (checked Oct 2026) Cursor says "Checkpoints are stored locally and separate from Git" (checked Oct 2026), so use Git too. For bigger tasks, Plan Mode "generates a reviewable plan you can edit before building." (checked Oct 2026)
GitHub Copilot in VS Code: "Inspect each pending edit in the editor. Use Keep to acknowledge it or Undo to revert it." (checked Oct 2026) Restore Checkpoint rolls back a request, but it "doesn't reverse terminal commands, network requests, deployments, or changes to external services." (checked Oct 2026)
Step 7: Keep it or throw it away
Our advice, not a vendor quote: if the change is good, commit it with a clear message. If it's not, Git can put files back. git restore will "Restore specified paths in the working tree with some contents from a restore source." (checked Oct 2026) For example:
git restore path/to/file
This throws away your uncommitted changes to that file. Our advice, not a vendor quote: be sure first.
Code review tools
Some tools review pull requests with AI. We have pages on CodeRabbit, Qodo and Greptile. Our advice, not a vendor quote: they don't replace your own review.
Next steps
- Set up your tool: Claude Code, Codex CLI, Cursor or Copilot in VS Code
- Write prompts that break less: prompts that stop AI breaking your code
Not affiliated with or endorsed by Anthropic, OpenAI, Anysphere, GitHub, Microsoft or OWASP. Check their current docs before relying on these details.