AI-generated code in pull requests
In most engineering teams the question is no longer whether developers use AI assistants, but how to review what they produce. Generated changes arrive fluent and well documented, which is precisely why they need a different kind of attention: to subtle correctness, to security, and to where the code came from. This guide is for teams setting review practice, disclosure rules and automated checks.
Checks every file against classmates, the web and AI, in 65+ languages.
Why generated changes need attention
Code review evolved around human-written changes. Reviewers learned to read effort into code: a tidy, documented change usually came from someone who had thought carefully. Generated code breaks that heuristic. It is always tidy and documented, regardless of whether anyone has checked that it is right.
Generated changes also tend to be larger. An assistant or agent will happily write four hundred lines where a person would have written eighty, adding helpers, abstractions and handling for cases that do not occur. Large, plausible pull requests are the hardest kind to review well.
None of this argues against AI assistants. It argues for knowing which changes are substantially generated, so the review matches the risk.
The real risks
Plausible errors
Logic that is right for the common case and wrong at the edges, off-by-one boundaries, misread requirements. They pass a quick read because the code looks competent.
Invented interfaces
Calls to functions, options or configuration keys that do not exist in the version you use. Usually caught by tests, but not always by review.
Security patterns that only look right
Input validation that misses a case, outdated cryptography, permissive defaults, secrets handled carelessly in examples that become production code.
Provenance
A generated block that closely reproduces licensed public code, carrying obligations nobody on the team knows about.
Reviewing generated changes
- Ask for smaller pull requests. Generation makes large changes cheap to write and expensive to review. Keep the cost on the author's side.
- Read the tests first. Do they test the requirement, or merely exercise the code that was generated? Generated tests often confirm the implementation's own assumptions.
- Check every external call against the documentation for the version you actually use.
- Question every new dependency. Assistants add packages readily. Each is a maintenance and supply chain decision.
- Look hardest at the boundaries: input handling, authentication, permissions, error paths, concurrency.
- Ask the author to explain the change. An author who directed and verified the generation can; one who accepted it unread cannot, and that is a process problem worth surfacing.
Provenance and licences
Models generate new code almost all of the time, but they can reproduce passages close to code they were trained on, especially for well-known algorithms and popular libraries. If the original carries a licence with attribution or copyleft obligations, merging it can create obligations your project did not intend to take on.
The practical control is a search of public code on the changed files before merge. A match shows the source repository or page, so legal or the owning team can decide: attribute it, replace it, or confirm the licence is compatible. Codequiry searches the web, GitHub and Stack Overflow and links each match to its source; see matching code against GitHub. For a dated, verifiable record of an examination, for example in a due diligence or a dispute, see code examination reports.
A disclosure policy that developers will follow
Disclosure works when it is light and non-punitive. Policies that work in practice share a few features:
- A checkbox or label in the pull request template: "substantially AI-generated". Not a confession, a routing signal for review.
- Clear zones. Components where AI assistance is fine, and any where it is restricted: security-critical code, code under specific licence constraints, regulated components.
- Author accountability. The author owns generated code exactly as they own written code, including its tests and its licence status.
- Automated checks as a backstop, not a policing tool. Their role is to catch what disclosure missed and to route review effort.
Automating the check in CI
A useful pipeline step takes the files a pull request changes, checks them for AI-generated code and for matches against public sources, and posts a summary: which files read as generated, with reasons, and which match public code, with links. It informs the reviewer; it does not decide.
Codequiry offers a REST API with SDKs, documented in the developer API pages, and an MCP server that lets AI assistants call the same checks. AI results come with a likelihood and reasons per file; match results come with the source. The AI code detection API page covers the detection side in more depth.
Check a change set now
Upload the changed files: AI likelihood with reasons, and any public code matches with their sources.
For how detection scores are produced and why they should route review rather than block merges, see how AI detectors work. For the code-level signs reviewers can learn to spot, see how to tell if code is AI generated and detecting agent-built code.
Frequently asked questions
Should teams detect AI-generated code in pull requests?
Detecting it is less important than reviewing it properly. Most teams now allow AI assistants. What matters is knowing which changes were substantially generated, so reviewers read them with the right scrutiny, and checking whether generated code reproduces licensed public code.
Can AI-generated code create licensing problems?
It can. Models occasionally reproduce code close to what they were trained on, which may carry a licence with obligations such as attribution or copyleft. A check that searches public code, including GitHub, and shows any match with its source lets you deal with that before merging.
What is different about reviewing AI-written code?
It looks finished. It is fluent, consistent and documented, which lowers a reviewer's guard, while its typical faults are subtle: plausible but wrong edge cases, invented APIs or options, unnecessary dependencies, security patterns that look right but are not, and code that is correct for a slightly different requirement.
How do I add AI code checks to CI?
Call a detection API from the pipeline on the files a pull request changes, and post the result as a check or comment. Codequiry has a REST API and SDKs, and an MCP server for AI assistants, that return AI likelihoods with reasons and public code matches with sources.
Should a pull request be blocked for being AI-generated?
Usually not. A high AI likelihood is a reason to review more carefully and to confirm licence clearance, not a reason to reject. Blocking should be reserved for policy breaches, such as generated code in a component where AI use is prohibited, or an unresolved licence match.
Know what you are merging
AI detection with reasons and a search of public code, by upload or through the API.
Start a check Pay as you go with credits. Comparing files is free.