How to Review AI-Generated Code for Bugs Before You Run It

How to Review AI-Generated Code for Bugs Before You Run It
About the Author

Sam Na writes practical guides on AI-assisted coding, safer digital workflows, and reliable personal automation. RoutineOS explores how to use AI tools without losing control of the data, decisions, and everyday systems those tools are meant to improve.

Author: Sam Na Contact: seungeunisfree@gmail.com Published: November 4, 2026 Updated: November 4, 2026
AI Code Review · Bug Detection · Safer Code Changes

Before you run AI-generated code, review what it actually changes, which data it can access, and what could happen if its assumptions are wrong. A focused AI code review can uncover subtle logic errors, unexpected side effects, and unsafe operations before they reach your files, accounts, or other people.

Imagine asking an AI coding assistant to prepare a small public project update from your task records. It returns a Python function in seconds, complete with readable variable names and a short explanation. At first glance, the code appears to do exactly what you requested.

Then you notice something easy to miss. The condition that selects public records also allows certain private records through. The returned objects include a field containing internal notes. If the function feeds a sharing or publishing workflow, that mistake could expose information you never intended to distribute.

Nothing in the snippet needs to throw an exception for the result to be harmful. A successful execution may be precisely what makes the mistake consequential. Once data has been uploaded, emailed, or published, finding the problem afterward may be too late to prevent disclosure.

This is why learning to review AI-generated code before execution matters. You are not merely looking for syntax errors. You are checking whether the proposed implementation matches the request, respects data boundaries, and avoids operations that were never authorized.

The question to ask before execution is not simply "Does this code look correct?" It is "What will this code read, change, send, or expose if I allow it to run?"

Codex, Claude Code, GitHub Copilot, Cursor, Qodo, and CodeRabbit provide different ways to inspect code changes and identify potential problems. Some can review local changes, while others specialize in pull requests. Their findings are useful evidence, but they do not replace your responsibility to understand the intended behavior.

We will begin with a practical pre-run review process, inspect a flawed Python function without executing its unsafe version, and examine a separate JavaScript example involving asynchronous operations. Then we will look at where each review tool fits and how to decide whether a proposed change is ready for testing.

Understand what to review before running AI code

Code review and debugging answer different questions. Debugging usually begins with a failure you have observed. Reviewing newly generated code begins before you know whether the implementation will behave correctly in your environment.

You examine the proposed changes against a set of expectations and constraints. The objective is to recognize problems that can be identified from the code, its surrounding context, and the intended behavior before granting it access to real systems.

Define the task the code was actually authorized to perform

Start with the original request. If you asked an assistant to format a collection of records for display, did you also authorize it to save a file, install a dependency, or send information to an external service?

AI coding agents may propose additional work because it seems convenient or necessary to finish the task. A broader solution is not always a better one. Every additional operation should be justified by the user's actual goal.

Write the intended behavior in ordinary language before reviewing the code. For a public project update, the requirement might be to include only active records explicitly approved for sharing. The output should contain a title and status, not private notes or internal contact information.

That statement creates a standard against which the code can be judged. Without it, a review assistant may praise a function for collecting all relevant records while overlooking the fact that some of those records must remain private.

Define the review contract
What must this change accomplish?

Required behavior: Identify the exact output or action the user requested.

Prohibited behavior: Identify data that must not be exposed and operations that must not occur.

Existing behavior: Identify contracts that should remain unchanged.

Unanswered questions: Record assumptions that need confirmation before the code can be approved.

Identify the data and permissions the code can reach

A script that performs arithmetic on supplied numbers has a smaller impact than one that reads private documents, updates a database, or sends messages. The same coding error can have very different consequences depending on the system surrounding it.

Look for file operations, network clients, database connections, access tokens, environment variables, and functions that trigger external actions. These are not automatically problems. They tell you where a wrong assumption could have effects beyond the function.

Check whether the requested task requires each capability. A report preview does not normally need write access to a production database. A filename generator does not need to delete existing files. A code review request does not need to deploy an application.

Permissions also matter when an agent is allowed to run commands. Reading a source file and changing its contents are separate activities. A review-only task should not silently become an implementation or execution task.

Read-only review
Inspect without changing the environment

Examine source code, proposed diffs, relevant configuration, and documented requirements using appropriately restricted access.

Review findings can be reported without accepting edits, running the application, or contacting production services.

Executable workflow
Changes can affect real state

Shell commands, scripts, file writes, migrations, and service requests can modify systems while the task is underway.

These operations need a separate authorization and verification decision, especially when sensitive data is involved.

Know which conclusions static review can support

Static review means examining code without executing the program being reviewed. It can reveal a condition that plainly violates a requirement, an unguarded destructive operation, or an external request to a destination you did not authorize.

It can also identify possible problems that require additional context. An unfamiliar function call might be safe because another component validates its arguments. A suspicious default might be an intentional part of the application's contract. The reviewer should distinguish confirmed defects from questions.

Static inspection cannot prove that a program works in every environment. It may not reveal behavior hidden inside dependencies, remote services, runtime configuration, or code that was not included in the review.

The purpose is therefore to reduce foreseeable risk before controlled verification begins. A clean review means no supported issue was found within the inspected scope. It does not mean that execution is guaranteed to be safe or correct.

Key Takeaway

Start by defining what the code is allowed to do and which resources it can affect. Review-only access should remain separate from permission to execute or modify a system. Treat static findings as evidence within a clearly defined scope.

Inspect diffs, dependencies, and changed behavior

When an AI coding agent modifies an existing project, inspect the change rather than reading only the final explanation. An assistant may describe the work as a small improvement while its proposed diff changes several files or alters a public interface.

A diff shows what was added, removed, and replaced. It helps you separate the intended change from unrelated modifications that require further explanation.

Start with the file list and review every meaningful change

Before reading individual lines, look at which files were changed. A request to correct a display label may reasonably affect a UI component and its related configuration. It deserves closer attention if the assistant also modifies authentication settings, environment files, or deployment scripts.

In a Git-based project, the status and diff commands can show local changes. For a review of uncommitted work, read-only Git inspection commands may help you identify the changed files and inspect the patch.

git status --short

git diff --stat

git diff --no-ext-diff

These commands are intended to inspect the working tree. The ordinary diff does not display every untracked file or every staged change, so examine those separately when relevant. A review that ignores newly created files may miss the part of a change that introduces the real risk.

Read the file list first, then inspect the changed functions and their callers. Pay particular attention to removed validation, renamed fields, altered return values, and changes that affect how data moves between components.

1
Identify affected files
Look for unexpected changes to configuration, credentials, deployment scripts, and shared application modules.
2
Read the actual diff
Check additions, removals, and changed conditions rather than trusting the assistant's summary.
3
Inspect affected callers
Determine whether existing components still receive the values and behavior they expect.
4
Record unexplained changes
Request justification for modifications that extend beyond the original task.

Look for changes to interfaces and data meaning

A function can remain syntactically valid while changing a contract that other code relies on. Renaming a response field, changing a default value, or returning a different data structure may break callers that were not included in the generated patch.

Suppose a function previously returned a list of objects. An AI assistant changes it to return a dictionary keyed by ID because that structure seems more efficient. The new implementation may be reasonable in isolation, but every caller expecting a list now needs attention.

The same concern applies to error behavior. A function that previously raised an exception might begin returning an empty object. That can make a calling process treat failure as legitimate empty data.

Ask which documented behaviors change and which consumers depend on them. A reviewer should not dismiss a compatibility change merely because the edited function appears simpler afterward.

Interface risk
Changed return structure

A function returns a different type or renames a field that existing callers still expect.

Check consumers before accepting the change.

Data-handling risk
New default or filtering rule

Missing data is silently accepted, or the selection condition includes records outside the intended scope.

Compare the new rule with the actual requirement.

Dependency risk
Unexpected package or version change

Generated code introduces an additional library or alters dependency constraints without a clear need.

Check the package source, purpose, and compatibility.

Operational risk
New file or network side effect

A previously local operation begins writing files, calling a service, or changing stored state as part of its execution.

Confirm the operation was requested and authorized.

Distinguish unnecessary complexity from necessary safeguards

AI-generated code can become more complicated than the task requires. The assistant might introduce several helpers, a configuration layer, and a new abstraction for a one-time data transformation.

Complexity matters because every additional branch and dependency gives the reviewer more behavior to understand. A larger design can also make future changes difficult for someone who did not participate in the original AI conversation.

Still, shorter code is not automatically safer. Validation and explicit permission checks may require more lines than an unsafe shortcut. The question is whether the added code has a clear responsibility.

Review abstractions in context. Can the same requirement be met with fewer moving parts without losing important safeguards? If a helper is necessary, does its name describe what it really does? Can an unfamiliar reader follow the data through it?

Treat unexplained changes as questions, not automatic defects. Ask which requirement each change serves and what would stop working if it were removed. The answer often reveals whether the complexity is necessary.

Key Takeaway

Inspect the full change surface, including untracked files, dependencies, public interfaces, and possible side effects. A narrow-looking patch can affect behavior far beyond the lines it modifies.

Find hidden bugs in an AI-generated Python function

Let us review a deliberately flawed Python function before allowing it to feed a public project dashboard. The intended task is simple: create a list of active project cards that have been explicitly marked public.

Each returned card should contain only a title and status. Records marked private must stay out of the output. Archived records should also be excluded, even when they were previously public.

This is an instructional example, not a real private dataset. We can determine several defects by reading the code and comparing it with those requirements.

Inspect the generated selection logic without executing it

Imagine an assistant proposing the following function. The comprehension is concise, and the variable names are familiar. That makes the code seem reassuring at a glance.

def public_cards(records):
    return [
        {
            "title": row["title"],
            "status": row["status"],
            "private_notes": row.get("private_notes", ""),
        }
        for row in records
        if (
            row.get("visibility") == "public"
            or row.get("status") == "active"
        )
    ]

The problem lies in the relationship between the selection condition and the output fields. We do not need to execute this function to see that its behavior differs from the stated contract.

The condition uses or. A record is included whenever it is public, even if it is archived. It is also included whenever it is active, even if its visibility is private.

The contract requires both properties to be true. A record must be explicitly public and active. The generated condition permits either property to be sufficient on its own.

A second problem appears in the returned object. It contains private_notes, even though the public card is supposed to contain only a title and status.

That field is not needed for the requested display. Including it creates a disclosure risk if the output is passed to an API, public page, or shared export without further filtering.

Record the findings with a concrete failure condition

A useful code review does not merely say that the function is "insecure" or that its filtering needs improvement. It explains exactly which input would expose the problem.

An active private record satisfies the generated condition because its status is active. A public archived record also satisfies the condition because its visibility is public.

Neither record belongs in the output. The incorrect result follows directly from the Boolean expression. This makes the finding more useful than a vague warning about possible filtering mistakes.

Finding 1 · High impact
Private active records can be selected

Evidence: The condition accepts an active record even when its visibility is private.

Impact: Records excluded by the sharing requirement can enter the public result.

Required change: Require both public visibility and active status.

Finding 2 · High impact
Private notes are included in the output

Evidence: The returned dictionary explicitly includes the private_notes field.

Impact: Internal information may be passed to a sharing or publishing component.

Required change: Return only the approved public fields.

Finding 3 · Behavior defect
Archived public records remain eligible

Evidence: Public visibility alone satisfies the current selection condition.

Impact: Old projects may appear in a dashboard intended for active work.

Required change: Exclude archived records through the same explicit status requirement.

Review question
What should happen when required fields are missing?

The generated function accesses title and status through dictionary indexing without explaining the input contract.

Decide whether malformed eligible records should raise a clear exception or be handled through another documented policy.

The first three findings are supported directly by the snippet and the stated requirements. The missing-field question needs an explicit decision about invalid input.

This separation matters. Review comments become more trustworthy when they distinguish demonstrated mistakes from assumptions that still need confirmation.

Apply a correction that enforces the public-data boundary

We will choose a strict but narrow input policy. Every row must be a dictionary. Only records explicitly marked public and active are eligible. An eligible record must have a non-empty string title.

The function will return a fresh dictionary containing only the two allowed fields. It will not include private notes, owner information, or unrelated data.

The corrected code below implements those decisions. The validation is visible without introducing a new package or changing unrelated parts of the project.

def public_cards(records):
    cards = []

    for position, row in enumerate(records, start=1):
        if not isinstance(row, dict):
            raise TypeError(
                f"Row {position} must be an object"
            )

        if (
            row.get("visibility") != "public"
            or row.get("status") != "active"
        ):
            continue

        title = row.get("title")

        if not isinstance(title, str) or not title.strip():
            raise ValueError(
                f"Row {position} needs a title"
            )

        cards.append({
            "title": title.strip(),
            "status": "active",
        })

    return cards

The eligibility condition now rejects a record whenever either requirement is not satisfied. In other words, only records that are both public and active can reach the output-building step.

The output is also deliberately restrictive. A new field added to the input later will not automatically become part of the public card. This is safer than copying the entire source record and trying to remove sensitive fields one by one.

That approach is often called allowlisting. You specify the fields permitted in an output rather than assuming that all fields are safe unless explicitly forbidden.

The corrected function operates only on an in-memory collection. It does not publish, email, or upload anything. That makes its data-selection responsibility easier to inspect separately from any later sharing operation.

The displayed correction was checked with artificial records in an isolated Python environment. The checks confirmed that a public active record produced the expected card, private and archived records were excluded, empty input returned an empty result, and an eligible record with a blank title raised ValueError.

Those checks support this small example. They do not establish that a real publishing service, API permission model, or external data source is safe. The review should address those components separately if they are part of your application.

3 Confirmed code findings Private-record inclusion, private-field exposure, and archived-record inclusion.
2 Approved output fields Only title and status are included in the public card.
4/4 Isolated behavior checks The corrected standalone function passed four focused checks.
Key Takeaway

Review AI-generated conditions against the exact data-selection rules. A function can run successfully while including forbidden records or fields. Require explicit eligibility and allowlist the information that may leave the component.

Recognize security, data, and asynchronous risks

Some generated-code problems are visible in a single expression. Others appear only when you understand what the function can access or what its caller assumes.

A pre-execution review should therefore include more than logic. You also need to inspect permissions, external effects, error handling, and the timing of operations that complete asynchronously.

Inspect secret handling and external destinations

Code that reads an environment variable is not automatically unsafe. Many applications use environment variables to obtain configuration and credentials.

The important question is what happens to those values afterward. An access token should not be printed to ordinary logs, inserted into a public report, or sent to a destination unrelated to the authorized task.

Look carefully at network requests introduced by generated code. Confirm the destination, the data included in the request, and the reason the connection is needed.

A new telemetry call or analytics helper may appear harmless. If it sends raw records or credentials to an external endpoint, however, it changes the project's data boundaries and deserves explicit review.

Check logging statements for a similar problem. Error messages can accidentally include request bodies, private filenames, account details, or authentication headers. More detailed logging is not always safer when the underlying values are sensitive.

Never approve a new outbound request simply because the code labels it as monitoring, diagnostics, or error reporting. Confirm what information it sends and whether the destination is authorized.

Review file operations and proposed shell commands

AI coding agents sometimes propose shell commands alongside source-code edits. They may install packages, remove generated files, change permissions, or update local configuration to make a workflow run.

Each command deserves attention before execution. A broad deletion command can remove files outside the intended temporary directory. A script that overwrites an output file may destroy an earlier result without asking.

Path handling also matters. If untrusted input is used directly to construct a filename, it may contain directory separators or other unexpected path elements. A code review should confirm that the destination remains within the intended location.

Installing dependencies creates another boundary. Check whether a new package is necessary, where it comes from, and whether the requested operation could be implemented using an existing trusted dependency.

Do not run an unfamiliar command with administrator privileges as a shortcut around a permission error. The permission failure may be protecting a resource the task should not modify.

Destructive action
Unexpected deletion or overwrite

Determine exactly which files or records can be modified and whether preservation of existing data is required.

Dependency change
Package installation without justification

Confirm the package identity, version constraints, source, and role in the implementation.

Permission expansion
More access than the task requires

Review new filesystem, network, database, and service permissions before granting them.

Safer boundary
Separate preparation from execution

Let reviewable functions prepare data or proposed changes before another authorized component performs real actions.

Catch asynchronous success messages that arrive too early

JavaScript introduces another review concern: a function may report success before the operation it initiated has actually finished.

Suppose a settings screen calls an asynchronous storage function. The storage operation returns a Promise that settles when the save completes or fails.

An AI assistant proposes this wrapper:

async function saveSettings(settings, writeSettings) {
  writeSettings(settings);

  return { saved: true };
}

The wrapper calls writeSettings() without awaiting the returned Promise. It then returns a success object.

Under the stated contract, this is a real problem. The caller can receive a fulfilled result before the storage operation has completed. If the write later rejects, that failure is not represented by the wrapper's returned success.

Adding await makes the wrapper wait for the write operation before returning.

async function saveSettings(settings, writeSettings) {
  await writeSettings(settings);

  return { saved: true };
}

With this change, the wrapper resolves successfully only after the awaited operation resolves. A rejection from that operation propagates through the wrapper unless the surrounding code deliberately handles it.

The correction depends on the stated interface: writeSettings() must return a Promise that accurately represents the save operation. If it starts background work and returns before that work completes, adding await alone cannot guarantee durable storage.

This distinction should appear in the review. The goal is not to claim that a keyword solves every asynchronous problem. It is to verify that success is reported at the correct point in the operation's actual contract.

Look for code that reports completion, commits state, or sends confirmation before its required operation has finished. Review the meaning of success, not just whether the function returns a Promise.

Key Takeaway

Review how generated code handles credentials, files, external destinations, permissions, and asynchronous completion. A function may appear successful while performing an unauthorized action or reporting a result too early.

Compare Codex, Claude Code, Copilot, Cursor, Qodo, and CodeRabbit

The six tools discussed here can assist with reviewing code, but they operate in different contexts. A local coding agent can inspect a working directory before you open a pull request. A repository review service may analyze changes after they are submitted for review.

Those workflows should not be confused with a promise that no code will execute. A tool may run analysis commands or use additional services depending on its configuration. If you need a strictly non-executing inspection, verify its permissions and selected review mode.

Use Codex and Claude Code for context-aware review

Codex can review code changes and identify potential bugs, behavioral risks, and important compatibility concerns. Its code review workflow can also use repository-specific guidance to focus on project rules.

OpenAI's documentation describes using AGENTS.md to communicate review expectations that would otherwise remain informal. For example, a repository might require all public exports to exclude internal notes.

That instruction helps a reviewer understand the project's intended data boundary. It does not replace ordinary security controls or testing, and reviewers should still evaluate the actual code.

Claude Code can also inspect changes and support review of a local project. Anthropic separately documents a GitHub pull-request Code Review service for eligible Team and Enterprise organizations.

That service analyzes changes with multiple review agents and reports findings on relevant lines. It does not automatically approve or block the pull request. Claude Code also offers local review workflows distinct from the organization service.

OpenAI Codex
Review changes against repository rules

Useful context: Local changes or pull requests, related source code, and project guidance.

Review focus: Correctness, compatibility, important code risks, and requirements recorded in AGENTS.md.

Decision: Inspect findings and the actual diff before accepting a suggested change.

Anthropic Claude Code
Examine bugs and surrounding code context

Useful context: Code changes, related files, repository instructions, and review-specific guidance.

Review focus: Logic errors, security concerns, broken edge cases, and changed behavior.

Decision: Check the review mode, permissions, availability, and unresolved findings.

Use GitHub Copilot for reviews within the pull request lifecycle

GitHub Copilot code review works within GitHub's pull-request workflow. Depending on the available configuration, reviews can be requested manually or triggered automatically for relevant pull requests.

This makes it useful when you already organize changes through branches and pull requests. The feedback appears alongside the code under review, where you can inspect the finding and its surrounding context.

GitHub also supports repository guidance that can make review comments more relevant to local conventions. The precise options and availability depend on your plan and repository settings.

A Copilot review should be treated like other review feedback. A finding is something to investigate, not an instruction that must be applied without checking it.

Likewise, the absence of a finding does not show that every changed path is correct. Confirm what was reviewed and whether the comments correspond to the latest proposed code.

GitHub Copilot Code Review
Review the proposed change in GitHub

Where it fits: Pull requests in supported repositories.

What to inspect: Review comments, changed files, repository instructions, and the current proposed revision.

Important limit: Automated feedback is not a substitute for understanding the affected system.

Use Cursor Bugbot to inspect proposed pull request changes

Cursor offers Bugbot for AI-assisted review of pull requests. Its documented workflow examines changes and provides findings about potential bugs, security issues, and code quality.

Bugbot can operate through pull-request integrations, with configuration determining when reviews run and which repositories are included.

That is useful when the main review artifact is a pull request, rather than a standalone code snippet in a chat.

A review comment still needs to explain the actual failure condition. Check whether the identified problem follows from the proposed code and the application's contract.

If the finding refers to behavior outside the diff, inspect the related source before deciding that the reported issue is confirmed.

Use Qodo and CodeRabbit for repository-oriented review

Qodo provides context-aware review workflows focused on code changes, requirements, and affected repository behavior. Its documentation describes reviewing pull requests with specialized analysis and reporting findings that can be discussed or addressed.

This is particularly relevant when a proposed change touches a shared interface or differs from an established requirement. The reviewer needs more than a description of the edited lines to assess its broader impact.

CodeRabbit also supports AI-assisted code review through pull-request workflows. Its platform includes review findings, repository guidance, and tools for examining changes and their risks.

Both products can help organize review feedback, but the responsibility to confirm an issue remains with the person or team accepting the proposed change.

Cursor Bugbot
Find issues in pull request changes

Useful when the proposed work is already represented by a pull request connected to a supported Cursor workflow.

Inspect the flagged code and its actual behavior before accepting a fix.

Qodo
Evaluate changes against repository context

Useful for reviewing proposed changes, requirement gaps, and broader effects on a codebase.

Check whether each finding is supported by the relevant source and project rules.

CodeRabbit
Examine pull request findings and risks

Useful for AI-assisted review comments, change analysis, and repository-specific guidance within supported workflows.

Confirm the proposed issue before treating a review comment as a required code change.

None of these tools eliminates the need to understand what the program is allowed to do. A tool that examines a pull request may provide broader repository context than a pasted snippet. A local reviewer may be easier to use before a pull request exists.

Choose the workflow that matches where your code lives, which changes need inspection, and what permissions you are willing to grant. Review tools should support your decision, not replace it.

Key Takeaway

Codex and Claude Code can support context-aware review workflows, while GitHub Copilot, Cursor Bugbot, Qodo, and CodeRabbit provide repository-oriented review capabilities. Select the tool according to the review stage, available context, and permission model.

Use a structured pre-run AI code review checklist

You do not need an elaborate review process for every short function. A consistent sequence of questions can already uncover common mistakes before they reach a real environment.

The aim is to make the decision traceable. You should be able to explain what the code is intended to accomplish, which risks were examined, and why the proposed changes were accepted.

Review the change in a fixed order

Begin with intent, then move to the changed behavior and possible effects. This prevents the review from becoming a collection of superficial formatting comments.

Syntax, naming, and style matter for maintainability, but they should not distract from a condition that exposes private data or a command that could overwrite important files.

1
Confirm the requested behavior
Define the task, expected outputs, and prohibited side effects.
2
Inspect the change surface
Read the affected files and diffs, including newly created content.
3
Trace data selection and output
Check which records enter the function and which fields leave it.
4
Inspect permissions and side effects
Identify file writes, external calls, package installations, and destructive operations.
5
Check compatibility and error behavior
Examine changed return values, public interfaces, defaults, and asynchronous completion.
6
Resolve important findings
Separate confirmed bugs from unresolved assumptions and request narrow corrections.
7
Decide whether controlled testing is appropriate
Approve only the next action that is understood, authorized, and appropriate for the environment.

Give the review assistant a specific reporting format

A broad prompt such as "review my code" may produce a mixture of style advice, speculative concerns, and useful defects. It can be hard to tell which findings genuinely matter.

A more focused request tells the assistant which behavior is required, what it may inspect, and how each finding should be supported.

Ask for findings before general praise or summary. Each confirmed issue should identify the relevant code and explain the condition under which it produces an incorrect or unsafe result.

Copy-Ready Prompt: Review AI-Generated Code Before Execution
Act as a careful code reviewer. This is a review-only task. Do not execute code, install packages, edit files, send network requests, or run shell commands. Original task: [DESCRIBE WHAT THE CODE WAS REQUESTED TO DO] Required behavior: [LIST THE EXPECTED OUTPUTS AND RULES] Prohibited behavior: [LIST DATA EXPOSURE AND SIDE EFFECTS TO AVOID] Existing interfaces that must remain compatible: [DESCRIBE RELEVANT CONTRACTS] AI-generated code or proposed diff: [PASTE SANITIZED CODE OR DIFF] Review the change for: 1. Incorrect conditions or calculations 2. Missing input validation 3. Unexpected output fields or data exposure 4. Destructive file or database operations 5. Unnecessary network calls or dependencies 6. Incompatible return values or API changes 7. Incorrect asynchronous or error handling 8. Unnecessary complexity that increases risk For each finding, report: - Severity - Relevant function or changed lines - Exact failure condition - Expected behavior - Actual behavior implied by the code - Smallest justified correction - Evidence supporting the finding Separate confirmed bugs from possible concerns. Do not invent runtime results or test outcomes. Do not assume a method is safe because it is named safely. If no supported bug is found, state the review limits and identify any important remaining uncertainty.

This prompt can be adapted for Codex, Claude Code, ChatGPT, or another assistant capable of examining supplied source code. In an agentic environment, text instructions should be accompanied by appropriate permission settings.

A request not to execute code is useful, but it is not a substitute for configuring the tool to operate within the intended authority.

Prioritize findings by impact and supporting evidence

A code review becomes difficult to use when twenty minor suggestions obscure one serious data-disclosure bug. Group findings by their effect on the program, not merely by how easy they are to fix.

A finding deserves high priority when the code can perform an unauthorized action, expose sensitive information, corrupt important data, or violate a critical requirement under a supported condition.

A possible performance problem may also matter, but the reviewer should identify the workload or input that would trigger it. Do not present a vague concern as an established failure without relevant evidence.

Block until resolved
Supported consequential defect

Example: a public output includes a private field or a command can overwrite an unintended file.

Investigate before approval
Important unresolved assumption

Example: a storage helper may not return a Promise that reflects the actual write.

Consider improvement
Complexity or maintainability concern

Example: a small data transformation gains unnecessary layers without an explained benefit.

No supported finding
Review completed within scope

State which files and requirements were inspected and which execution risks remain unverified.

Do not count review comments as a quality score. One precise finding that prevents disclosure can be more valuable than many cosmetic observations.

Also avoid accepting every automated suggestion. A reviewer may misunderstand an intentional interface or overlook a constraint outside the visible code. Confirm each proposed correction against the actual requirement.

Key Takeaway

Review code in a consistent order and require concrete evidence for important findings. Focus on behavior, data boundaries, compatibility, and unauthorized effects before considering cosmetic improvements.

Decide whether to accept, revise, or reject a change

The final result of a pre-run review should be a clear decision about the proposed code. It should not end with a vague statement that the implementation "looks good."

A useful decision identifies whether the change satisfies the defined contract, whether consequential risks remain, and what the next authorized action should be.

Accept only changes whose behavior and authority are understood

A change may be ready for controlled testing when the reviewed code matches the intended behavior and no unresolved high-impact finding prevents that step.

Acceptance at this stage does not mean approval for unrestricted execution. A script that handles sensitive records may still require a restricted environment and additional checks before being connected to real data.

For a small local function, the next action may be a controlled execution with fabricated inputs. For a database migration, external integration, or production change, the next step may require a separate review and deployment plan.

The key is to keep authorization proportional to the possible effect of the code.

Accept for controlled verification
No unresolved blocker within the review scope

The intended behavior is clear, the changed code has been inspected, and the next test environment is appropriate.

Revise or reject
Important uncertainty or unsupported change remains

The code may expose data, perform an unauthorized action, alter a critical contract, or depend on an unresolved assumption.

Request narrow corrections instead of a new uncontrolled rewrite

When you identify a defect, describe the smallest change that would address it. If the issue is an incorrect Boolean condition, changing the condition may be sufficient.

If a public output includes private fields, the correction should define and enforce the permitted output schema. There is no need to redesign the entire application unless the surrounding structure also prevents the requirement from being met.

Ask the assistant to explain every additional change it proposes. A correction that introduces new dependencies, changes unrelated behavior, or expands permissions deserves another focused review.

Review the revised diff rather than assuming the assistant only changed the lines it described. A response stating that an issue has been fixed is not evidence that the final code now satisfies the requirement.

Hand off a clear review result before testing or deployment

A useful review handoff contains the intended change, the important findings, what was corrected, and what remains unverified.

Keep the statement factual. If the code was inspected but not executed, say that. If a safe example was run locally, identify the checked behavior without extending the result to unrelated systems.

Do not write "fully verified" when you have only read the diff. Likewise, do not treat a completed automated review as proof that production behavior is correct.

The handoff should tell the next person exactly which questions still need controlled execution or broader system testing.

The requested behavior is documented and matches the reviewed implementation.
Every meaningful changed file has been inspected.
Data selection, output fields, and permission boundaries have been reviewed.
Unexpected commands, dependencies, and side effects have been resolved or explicitly authorized.
Critical findings are corrected or block the next execution step.
The review result distinguishes inspected code from behavior actually executed.
The next verification environment is appropriate for the possible effects of the code.

The most useful outcome of a pre-run review is a justified next action. Sometimes that means proceeding to controlled testing. Sometimes it means requesting a smaller patch or refusing to execute a change that crosses an important boundary.

Key Takeaway

Finish the review with a clear accept, revise, or reject decision. Record what was inspected, which issues remain, and what still needs verification. A review decision is not permission to execute code without appropriate safeguards.

Frequently Asked Questions

Q1. How do I review AI-generated code before running it?
Start with the intended behavior and inspect the generated code or diff without executing it. Check conditions, data selection, output fields, dependencies, file operations, external requests, and changed interfaces. Record concrete findings and resolve important risks before proceeding to controlled testing.
Q2. Can ChatGPT review AI-generated code for bugs?
Yes. ChatGPT can analyze supplied code or a proposed diff and identify possible logic, data-handling, and security concerns. Give it the intended behavior and ask for evidence supporting each finding. Verify its conclusions against the actual code rather than treating every suggestion as correct.
Q3. How does Codex code review work?
Codex can examine code changes and report potential bugs and risks. Its code review workflow can use repository instructions, including applicable AGENTS.md rules, to consider project-specific requirements. Review findings should still be checked by a person, and automated review does not replace controlled verification.
Q4. Can Claude Code review changes without running my application?
Claude Code can support review of code and diffs without requiring the application itself to be run. However, the commands and tools used depend on the selected workflow and permissions. Configure an appropriate review mode and confirm tool access before assuming the session is entirely non-executing.
Q5. What is the difference between GitHub Copilot review and Cursor Bugbot?
Both support AI-assisted review of proposed code changes, including pull-request workflows. GitHub Copilot code review operates through GitHub's supported review features, while Cursor Bugbot provides Cursor's own pull-request review integration. Their setup, permissions, and available review options differ.
Q6. Are Qodo and CodeRabbit useful for AI code review?
Yes. Qodo and CodeRabbit provide automated review capabilities for code changes within supported development workflows. They can help surface findings and organize review feedback. You should still confirm whether each reported issue is supported by the code and your project requirements.
Q7. What security risks should I look for in AI-generated code?
Examine unauthorized data exposure, secrets in logs, unexpected network destinations, destructive file operations, excessive permissions, and unsafe handling of untrusted input. The relevant risks depend on what the code can access and the actions it is allowed to perform.
Q8. Does a clean AI code review mean the code is safe?
No. A clean review means no supported issue was found within the reviewed scope. Automated reviewers can miss defects, misunderstand requirements, or lack important environmental context. Controlled testing, appropriate permissions, and further review may still be necessary before real deployment.

Conclusion: review the change before trusting the code

AI coding tools can produce useful code quickly, but readable source is not automatically correct source. A function may run successfully while selecting forbidden records, changing an established interface, or performing an operation that was never requested.

The public project card example showed how a small Boolean mistake could include private and archived records. Its returned data structure also contained information that should not have been made available to a sharing workflow.

Those problems were visible from the source code and the required behavior. We did not need to run the flawed implementation against real records to recognize them.

The JavaScript example revealed a different kind of risk. A function can report success before an asynchronous operation has finished. Reviewing the Promise contract is necessary to understand whether the result means what the caller expects.

Codex, Claude Code, GitHub Copilot, Cursor Bugbot, Qodo, and CodeRabbit can help with parts of this inspection. Their value comes from the supported findings they surface, not from replacing your understanding of the system.

Before running the next piece of AI-generated code, read the proposed change against its actual requirements. Identify the data it can reach, the operations it can perform, and the contracts it may alter.

If a problem is supported by the code, request a narrow correction and inspect the revised diff. If the important uncertainties are resolved, the code can move to an appropriate controlled verification stage.

Your Next Step: Review One AI-Generated Change Before Running It

Choose a short AI-generated function or an unmerged code change. Write down what it should do and what it must never do. Inspect its conditions, output fields, dependencies, and side effects before allowing execution. Use the review prompt in this guide to request specific findings, then check each finding against the code. Resolve consequential defects and identify any assumptions that still need confirmation. The goal is to understand the change before deciding whether it deserves access to your real environment.

About Sam Na

Sam Na writes RoutineOS guides on AI-powered productivity, practical coding workflows, and reliable digital systems. His articles focus on helping readers make informed decisions about AI-generated work, understand how their tools behave, and use clear requirements to reduce avoidable mistakes.

RoutineOS explores how AI and thoughtfully designed workflows can simplify everyday tasks without making the systems behind them harder to understand.

Sam Na · RoutineOS seungeunisfree@gmail.com
A Quick Note Before Applying This Guide

This article provides general information and educational programming examples. The appropriate code review process depends on your application, data, permissions, development environment, and the consequences of a particular change.

Reviewing source code can reveal important risks, but it cannot guarantee that a program is free from bugs or security problems. Before using unfamiliar code with important files, accounts, or production systems, check current official documentation and consult a qualified developer or security professional when appropriate.

References and Official Documentation
OpenAI Developers — Custom Code Review Rules for Codex

Official guidance explaining how Codex Code Review can use repository instructions in AGENTS.md to identify project-specific risks.

Codex code review guidance
Anthropic — Claude Code Review Documentation

Official documentation covering code review workflows, findings, repository context, and the limitations of automated review.

Claude Code Review documentation
GitHub Docs — GitHub Copilot Code Review

Official instructions for reviewing pull requests with GitHub Copilot and understanding supported review features.

GitHub Copilot code review documentation
Cursor Documentation — Bugbot

Official guidance describing Cursor's pull-request review tool, supported triggers, and configuration.

Cursor Bugbot documentation
Qodo Documentation — Code Review

Official overview of Qodo's code review workflow, repository context, and reported findings.

Qodo Code Review documentation
CodeRabbit — Official Documentation

Official documentation describing pull-request reviews, code analysis, and review configuration within the CodeRabbit platform.

CodeRabbit documentation
Previous Post Next Post