Blog /

How Do You Verify AI-Generated Code Before Using It? Before Merge and After Deploy

How to verify AI-generated code: read the diff, run tests and scans, vet dependencies, watch for skipped tests, then check the deployed app.

verify AI codeAI code reviewAI coding agents

To verify AI-generated code before using it, check it in layers, and never let the agent that wrote it be the only judge: read the diff, run types, lint, tests and security scans, confirm new dependencies exist, look for deleted or skipped tests, run the changed journey in a browser, then check the deployed app as a user.

Popular advice on how to verify AI-generated code usually stops at the merge. Code review, unit tests and static scans catch bad syntax and broken logic inside a repository, yet none of them shows what a real user gets once the build ships. Skipping the post-deploy layer leaves live sign-in, environment variables and redirects unchecked.

Developers are already wary. In Stack Overflow's 2025 Developer Survey, more respondents said they distrust the accuracy of AI tools (46%) than trust it (33%), and only 3.1% said they highly trust it. For a team of one to ten people shipping a live web app with Claude Code, Cursor or Codex, and nobody whose job is testing, treating agent output as an unverified draft is what keeps broken code out of production.

How do you verify AI-generated code before using it?

Split verification into two halves: pre-merge checks that inspect the code, and post-deploy checks that use the live app. Each layer has a narrow job and a clear owner who decides pass or fail. Taking the coding agent's "done" at face value skips both halves.

A developer with a magnifying glass examining code next to a robot and software check-list icons.

Seven Verification Steps From Prompt to Production

Running these seven layers in order stops bad changes early, when fixes are cheap, and catches deploy-only failures before users report them.

  1. Write down what "done" means before the agent starts. Name the user-visible outcome, the files allowed to change, and the exact commands that must pass before the task counts as finished. Clear boundaries keep an agent from rewriting half a module to fix a two-line bug.

    • Catches: Scope drift and vague completion claims.

    • Misses: Requirements that were wrong from the start.

  2. Read the diff for intent and scope. Compare every modified file with the original request, looking for stray refactors, changed defaults or edits outside the target feature. A structured code review checklist helps catch side effects before merging.

    • Catches: Unrelated edits, unrequested behavior changes, files touched outside the task.

    • Misses: Runtime behavior that only shows up when the app runs.

  3. Run types, lint, tests, static analysis and security scans. Run the type checker, linter and test suite, and use scanners such as CodeQL and Dependabot, as GitHub's tutorial on reviewing AI-generated code recommends: "Use tools like CodeQL and Dependabot to catch vulnerabilities and dependency issues." CI jobs enforce this on every commit without relying on memory.

    • Catches: Compile errors, type mismatches, known vulnerability patterns.

    • Misses: Wrong business behavior that compiles cleanly and passes existing assertions.

  4. Confirm every new dependency exists, is maintained and carries a compatible license. Check each new package in the manifest and lockfile against its registry page, release history and license. GitHub's tutorial tells reviewers to "Watch out for hallucinated or suspicious packages (such as packages that don't actually exist)".

    • Catches: Invented package names, abandoned libraries, incompatible licenses.

    • Misses: Malicious or compromised packages that really exist in a registry.

  5. Inspect the test diff for silenced checks. Never trust a green CI badge without reading what changed in the test directory. GitHub's guidance puts it plainly: "Watch for tests that are deleted or skipped, instead of fixed." A commented-out spec or a relaxed assertion also turns a red run green.

    • Catches: Deleted tests, skipped specs, weakened assertions.

    • Misses: New tests that pass trivially without asserting meaningful behavior.

  6. Run the changed user journey in a real browser. Exercise the changed screen and flow with Playwright Test, which the Playwright documentation describes as "an end-to-end test framework for modern web apps". Running the flow against a local or preview server exposes broken selectors, failed client routing and form bugs that unit tests cannot see.

    • Catches: Broken UI interactions, client-side routing bugs, form failures.

    • Misses: Production-only configuration, missing secrets, live third-party integrations.

  7. Check the deployed app after release with something that didn't write the code. Once the build is live, have the critical user journeys walked on the live URL by a check that holds no context from the coding session, and compare the page the user ends up on with what should happen.

    • Catches: Deploy-only failures such as broken redirects, permission errors and misconfigured environment variables.

    • Misses: Code paths the chosen journeys never walk.

Verification rule: Every step targets a different failure mode. Stopping at step five or six leaves production unverified.

Why Pre-Merge and Post-Deploy Need Different Owners

Code-level checks run on source files inside a workspace or CI container. They confirm that syntax, types and mocked interactions match the repository's expectations, which makes them fast and repeatable for small teams.

Live checks run on the shipped build behind real DNS, cookies, proxies and external APIs. Separating who builds the change from who verifies the live result removes the blind spot an agent creates when it writes both the feature and its own tests.

Which Layer Catches What, and Who Decides Pass

Small teams move faster when everyone knows what each check protects and who signs off. The table maps the layers from pre-merge review to the live app.

Layer
Code review
What it catches
Intent, scope, unclear logic, unrelated edits
What it misses
Runtime behavior and deployed configuration
Who decides pass
A person who owns the merge; a fresh-context reviewer can go first
Layer
Types and lint
What it catches
Type mismatches, unused code, style breaks
What it misses
Wrong behavior that type-checks cleanly
Who decides pass
The CI job; a red run blocks merge
Layer
Unit tests
What it catches
Logic errors in isolated functions; fastest feedback for pure logic
What it misses
Integration, sign-in flows, deployed config
Who decides pass
The test suite in CI; the best choice for pure logic
Layer
Static and security scans (CodeQL, Dependabot)
What it catches
Known vulnerability patterns and vulnerable dependencies
What it misses
Logic flaws outside known patterns
Who decides pass
The repository owner, who reviews each finding
Layer
End-to-end tests in CI (Playwright)
What it catches
Broken user flows in a real browser before merge
What it misses
Production data, live third-party services, production config
Who decides pass
The CI run; the best choice before merge for user flows
Layer
The agent checking in its own browser (Playwright MCP or Claude in Chrome)
What it catches
Fast feedback while the agent works
What it misses
The agent's own blind spots, including tests it wrote
Who decides pass
The agent's result, which a person must still accept
Layer
Independent check of the live app
What it catches
Failures users hit after deploy: sign-in, redirects, permissions
What it misses
Defects with no user-visible path; a check reports only what it saw on that run
Who decides pass
Something that didn't write the code, with evidence a person can open

Where Each Tool Works Best

No single tool replaces the rest, and the wrong layer wastes build minutes or creates false confidence.

  • Unit tests: The best choice for business logic, date math, parsers and pricing calculations: they run fast and pinpoint exact regressions.

  • Playwright in CI: The best choice before merge for multi-step user flows, because it renders the real page and catches UI regressions before code reaches the main branch.

  • Playwright MCP or Claude in Chrome: The best choice during active editing, when the agent needs quick visual feedback in a browser. See Playwright MCP vs Claude in Chrome for how they differ.

  • Fresh-context code review: A fast first pass on large diffs that flags unrelated edits and missing edge cases before a person reads every line.

Passing tests also do not prove quality. A 2025 quantitative analysis of AI-generated code ran static analysis on output from 4,442 Java coding assignments and found no direct correlation between a model's functional performance and the quality and security of its code.

The Post-Deploy Gap Most Guides Skip

Most guides on verifying AI-generated code stop at the merge: code review, unit tests and static scans. None of those layers looks at the deployed application, so only a check of the live app shows whether users can complete the changed journey after release.

Make the Agent Run the Checks It Cannot Skip

Asking a coding agent to "double-check its work" rarely holds. A polite request still lets the model summarize what it expects to happen instead of running the suite. Deterministic commands turn verification from a habit into a gate.

Enforcing Verification Inside Claude Code

Claude Code separates soft instructions from hard gates, and the Claude Code best-practices guide covers both.

  • Store exact commands in CLAUDE.md: List the project's real install, test, typecheck and lint commands so the agent doesn't guess script names or skip targeted tests.

  • Say what done looks like: Put the completion condition in the prompt, or set it with /goal, for example "all tests in tests/auth pass and lint is clean".

  • Block false completion with a Stop hook: A Stop hook runs a deterministic command before Claude is allowed to finish. In the documented example it runs pnpm tsc --noEmit 1>&2 || exit 2; exit code 2 blocks the stop and sends stderr back to Claude to fix.

  • Catch mistakes mid-edit: The Claude Code hooks reference documents PostToolUse hooks, which can run a test script after each file edit and return failures while Claude is still working.

  • Run the app with /verify: The commands reference describes /verify as a bundled skill to "Confirm a code change does what it should by building your project's app, running it, and observing the result, rather than relying on tests or type checks."

For a step-by-step setup, see how to make Claude Code validate its own work.

Persistent Rules for Cursor and Codex

Other coding agents need the same discipline, so verification doesn't disappear when someone opens a fresh chat.

In Cursor, put verification instructions in project rules under .cursor/rules/ or in an AGENTS.md file at the repository root. For Codex, put the same command list in AGENTS.md, which Codex reads for project instructions. In both, require the agent to run each command and show the output, and judge by exit codes and logs rather than by the agent's summary.

Every hook, rule file and local /verify run happens inside the coding environment. A green local typecheck proves the workspace compiles, not that the deployed page works.

Tests That Only Cover the Happy Path Miss the Bug

Suppose an agent is asked to add an endpoint that exports a team's invoices. It writes the handler and a unit test proving an admin can download a valid CSV, CI turns green, and it marks the task complete. If the route only checks that a session exists, not that the user is an admin, any member can download every invoice, and no test says so.

Happy-path tests confirm an allowed user can finish an action. They say nothing about whether the app blocks an unauthorized request or handles bad input safely.

Security research shows how often this happens. Veracode's research across more than 100 large language models found that the models introduced vulnerabilities in 45% of test cases, failed to defend against cross-site scripting (CWE-80) in 86% of cases and against log injection (CWE-117) in 88%. Code can look correct and pass its own tests while carrying weaknesses the happy path never exercises.

Three Negative Cases and Explicit Oracles

Every critical journey needs at least three automated negative test cases next to its happy path.

  • Signed-in user without permission: The test signs in as a regular member or another tenant and tries to load a restricted screen, change a protected record or call an admin endpoint.

  • Session expired mid-flow: The test expires the session halfway through a multi-step form or checkout, then submits the next step.

  • API returning an authorization error: The test makes the backend return 401 or 403 and asserts that the interface doesn't hang, retry forever or show stale data.

Before writing any negative case, define an oracle so pass or fail cannot be negotiated afterwards:

  1. Expected visible state: The exact redirect, message or locked screen the user must see.

  2. Authorization outcome: Access denied, with no leaked fields in the page or its data.

  3. HTTP status and body: The expected status (such as 403 Forbidden) and a safe error payload with no stack trace.

  4. Forbidden side effects: No database write, webhook, email or third-party change happened.

Assert on the network response, not only the screen: a component can show a generic error while the API answered 200 OK and returned private fields. Be wary of snapshot tests updated in the same pull request as the feature; they approve whatever the agent produced, with no independent standard.

Testing the Tests by Breaking a Rule on Purpose

Keep the list of negative cases next to the test suite so coding agents read it whenever they touch the feature. A person who didn't write the code should confirm the expected outcome of each case, because agents tend to redefine expectations to match whatever the code currently does.

Practical check: Pick one critical rule, such as an authorization guard, invert it on purpose, and run the suite. If it stays green, the tests aren't protecting that boundary.

This exposes suites that pass whatever the code does, usually because assertions check that a response exists rather than what it contains. For the wider picture of which layer to test first, see webapp testing for agent-built apps.

Check the Live App and Set the Release Gate

A merge review and a release gate answer different questions. The reviewer decides whether the change is safe to merge; a named release owner decides whether the deployed app is safe to call done. Repository checks read files. They do not see routing rules, CDN headers, cookies or production secrets once the app is live.

A real case from CheckMyApp's why page: on JobLander, sign-in answered 200 and created a session, yet the user stayed on /login. Authentication succeeded; the expected redirect never happened. A green status on the sign-in request would not have shown it. Only a check that used the live app the way a user does saw it, and the fix was merged in PR #349.

A developer working at a desk surrounded by software development icons, monitoring code deployment and release processes.

Catching Blind Spots With Controlled Mutants

Coverage is a weak signal of what will break. A stronger one is mutation testing: make small deliberate changes to critical code and see which ones the suite catches.

  • Invert authorization checks so role checks let unauthorized users through.

  • Remove input validation on form fields and query parameters.

  • Shift boundary conditions such as pagination limits or quota caps.

  • Change timeout or retry behavior on external calls.

  • Swap a query or API parameter to see whether scoping holds.

  • Force payment or third-party failures to confirm the app recovers gracefully.

The mutation score is killed mutants divided by non-equivalent mutants. A high coverage number with surviving authorization mutants should fail the pre-merge review.

Four Live Journeys and the Evidence to Keep

After every production release, have a check walk four journeys on the live app:

  1. Sign-up: Registration, validation and onboarding under live settings.

  2. Sign-in: With a test account, ending on the expected signed-in page, not back on the login screen.

  3. One permission boundary: A restricted action with a lower-privilege test account, rejected cleanly.

  4. One core data or payment view: A main dashboard, report or checkout screen that depends on live queries and external services.

Keep evidence from every check: the steps walked, screenshots, which build was checked, and what failed. After the agent ships a fix, the next check confirms that journey on the live app. A check reports what it saw on that run; it is not a guarantee the app is free of defects. For when each check should run around deploys, see software deployment testing.

This is the layer CheckMyApp covers. Your agent says "done"; CheckMyApp uses your live app as a real user and tells your agent what broke. It connects to Claude Code, Cursor and Codex through MCP. Setup is on the install page.

A One-Minute Release Gate

A gate holds only if a small team can apply it in about a minute. Write these rules into the project instructions so the coding agent and the release owner judge by the same criteria:

  • CI is green: Typecheck, lint, unit tests and security scans pass with no ignored errors.

  • Test removals are justified: No deleted or skipped test lacks a reviewed explanation in the pull request.

  • New packages are vetted: Every new dependency is real, maintained and license-compatible.

  • Security mutants are killed: No unexplained surviving authorization mutant remains.

  • Live journeys pass with proof: The four critical journeys pass on the deployed app, and every failure comes with evidence.

Name one person who owns the release. On a two-person team, that name is what stops a broken deploy going out because each assumed the other had looked.

Common Questions About Verifying Agent Code

Can the agent verify its own code?

It can and should run checks while it works, so obvious errors fail fast. The Claude Code best-practices guide names the usual failure: "Claude said it was done and it wasn't quite, usually because it had no way to check its own work." Hooks and project rules give the agent real feedback, but it should not be the only judge: something that didn't write the change should look at the result and the live evidence before the release counts as done.

Are passing tests enough?

No. A green suite only proves the assertions in the repository passed. Tests catch a defect only when someone wrote an assertion for that failure, which leaves untested authorization rules and production configuration exposed. Pair tests with negative cases and an independent check of the live app after deploy.

What should be checked after deploy?

The journeys users depend on most: sign-up, sign-in, access boundaries, and the main data or billing screens. The check should confirm the page the browser actually lands on and the network response, then walk the same journey again after each fix reaches production.

Your agent says “done”. We check your app.

Code review and CI catch mistakes before merge; a check of the live app confirms what users get after deploy. Your agent says "done"; CheckMyApp uses your live app as a real user and tells your agent what broke, through MCP in Claude Code, Cursor and Codex.

claude mcp add --scope user --transport http checkmyapp https://checkmyapp.dev/mcp

Free account: $3 of checks, no card · Cursor, Codex and the full install guide

This article was prepared with the help of AI. Found a mistake? Tell us.

More articles