AI code detectors: can you tell if code was written by AI?
Wendy Zhang · · 9 min read
A pull request lands that looks a little too tidy, or a take-home assignment reads like it came out of a chat window. An AI code detector promises to settle it with a percentage. The research on those detectors is more sobering, and for most engineering teams the authorship question turns out to matter less than a different one: is the code right?
An AI code detector estimates whether source code was written by a large language model, using token-probability statistics, a classifier trained on labeled samples, or a watermark left by the generating model. Peer-reviewed studies from 2024 and 2025 found that existing detectors perform poorly on code and generalize badly to new languages and models, and that simple edits such as renaming variables defeat many of them. A detector score is a weak signal, not proof of authorship.
How AI code detectors work
Every AI code detector, whether a free web form or a research prototype, rests on one of a few ideas. The oldest borrows from AI text detection. A language model assigns a probability to each next token, and text it generated tends to sit in the regions it finds most likely. Measure how “surprised” a reference model is by a piece of code (perplexity) and how much that surprise varies from line to line (often called burstiness), and you get a score. DetectGPT-style methods refine this by perturbing the sample and checking whether the original scores as a local peak of likelihood, which machine output tends to be.
Code makes this harder than prose. A 2023 paper by Yang and colleagues found that existing text detectors performed poorly on code and adapted the approach to code’s statistics. Shi and colleagues (ICSE 2025) studied lexical diversity, conciseness and naturalness, found that how code is segmented by whitespace and newlines was a key distinguishing factor, and built a detector that perturbs code by inserting spaces and line breaks rather than asking another model to rewrite it.
The second family is trained classifiers: collect human-written and model-written samples, extract features (tokens, AST shapes, static metrics such as cyclomatic complexity) and train a model to tell them apart. The third asks a model to rewrite the code and compares the result with the original; Ye and colleagues (AAAI 2025) observed that model-written code changes less under rewriting than human code does. The last is watermarking, where the generating model deliberately biases its token choices so a detector holding the key can recognize the pattern later.
| Method | What it measures | Where it breaks |
|---|---|---|
| Statistical (zero-shot) scoring | How predictable each token is to a language model; machine text tends to sit in high-probability regions | Code is low-entropy by nature, so human code often looks “predictable” too; small edits shift the score |
| Trained classifiers | Patterns learned from labeled human and AI samples: style, structure, AST features | Generalize poorly to new languages, domains and models outside the training data |
| Rewrite comparison | Ask a model to rewrite the code; AI-written code changes less than human code when rewritten | Needs a model call for every check, and results so far come mostly from benchmark datasets |
| Watermarking | A hidden statistical pattern the generating model inserts on purpose | Works only if the vendor watermarks; renaming variables or inserting dead code erases much of it |
Whatever the method, a detector’s percentage describes how closely the sample resembles its training data or its reference model’s expectations. It is not a measured probability that a person did or didn’t write the code.
How accurate AI code detectors are
The most direct evidence comes from software-engineering research that put detectors in front of code they hadn’t been tuned on. Pan and colleagues (ICSE-SEET 2024) built a dataset of 5,069 Python problems with human-written solutions, had ChatGPT generate code under 13 prompt variants, and ran five AI-content detectors over it. Their conclusion was blunt: the detectors performed poorly at distinguishing human-written from AI-generated code. The study was framed around programming education, where the stakes of a false accusation are high.
Suh and colleagues (ICSE 2025) reached the same verdict on existing tools, which they found “all perform poorly and lack sufficient generalizability” for practical use. Their own best model, a fine-tuned approach using static code metrics and AST-based embeddings, reached an F1 score of 82.55 on their benchmark and outperformed GPTSniffer, the previous state of the art. That is a research result under controlled conditions, with a meaningful share of errors even there.
Generalization is the recurring problem. The Droid study (2025), which assembled over a million samples across seven languages and 43 coding models, found that existing detectors did not generalize well beyond the narrow domains and languages they were trained on. A detector tuned on competitive-programming Python says little about a TypeScript service written with a model released last month.
Simple edits defeat most detectors
Real code rarely ships exactly as a model produced it. Someone renames a variable, inlines a helper, reformats a block. That is enough to move most scores. Consider a function in the clean, commented style models tend to produce, and the same logic after a quick hand edit:
def average_order_value(orders):
"""Return the mean order total, or 0.0 for no orders."""
if not orders:
return 0.0
total = sum(order["total"] for order in orders)
return total / len(orders)def avg_order(os):
if len(os) == 0: return 0.0
t = 0
for o in os: t += o["total"]
return t / len(os)The behavior is identical; the surface statistics are not. Suresh and colleagues (2024) showed this systematically for watermarks: random, semantics-preserving transformations such as variable renaming and dead-code insertion pushed true-positive rates below 50% in many cases, leading them to call code watermarking “significantly more fragile” than text watermarking. The Droid authors found that most detectors were easily defeated by model output prompted to look human-written, though training on a small amount of such adversarial data helped.
Watermarking also depends on the vendor. SWEET (ACL 2024) showed a watermark designed for code’s low entropy can work in research settings, but a detector can only find a watermark that the generating model actually applied, and code from tools without one carries nothing to find.
Published evaluations from 2024 and 2025 found that existing AI code detectors perform poorly on code, generalize badly across languages and models, and lose much of their signal when code is lightly edited. Research detectors do better on their own benchmarks, but no study supports treating a detector score as proof of authorship.
The human signals, and why they are weak
Without a tool, reviewers fall back on tells: comments that narrate every line, uniformly descriptive names, docstrings on trivial helpers, defensive checks for cases that can’t happen, an unfamiliar library pulled in for one call, or a style that doesn’t match the rest of the author’s work. In an interview setting, the strongest signal is conversational: the author can’t explain why the code is shaped the way it is.
Each of these has an innocent explanation. Linters and formatters flatten style. Experienced engineers write thorough docstrings. Students copy patterns from tutorials and textbooks. A style change might mean a new editor setup. Stylistic tells also vanish the moment the author asks the model to match the codebase, which is exactly what tools that read a repository’s conventions do.
The more reliable evidence sits outside the code: commit history that shows work developing over time, editor or proctoring logs where a course or interview uses them, and a walkthrough where the author explains decisions and modifies the code live.
When AI code detection actually matters
There are settings where the authorship question is the real question.
- Classrooms and assessments. When the point of an assignment is to show a student can write the code, authorship is the thing being graded. Given the accuracy evidence, a detector score works best as a reason to talk to the student, and assessment design (oral walkthroughs, in-class work, incremental submissions) carries more weight than any scan.
- Hiring. Take-home exercises face the same problem. Some teams either allow AI tools and assess how a candidate uses them, or move the signal into a live session where the candidate extends their own code.
- Licensing and provenance policies. Some open-source projects restrict AI-generated contributions over copyright and licensing uncertainty. The Gentoo Council voted in April 2024 to forbid contributions created with the assistance of natural-language AI tools. NetBSD’s commit guidelines presume LLM-generated code is tainted and require prior written approval from core. QEMU declines contributions believed to include or derive from AI-generated content, pointing to the Developer’s Certificate of Origin and the unsettled copyright status of model output.
- Disclosure policies. Other projects accept AI help and ask for transparency instead. The Linux kernel’s guidelines ask contributors to describe tool use in cover letters and changelogs, and its AI coding assistant rules reserve the Signed-off-by tag for humans, since only a person can certify the DCO. curl accepts AI-assisted pull requests that meet its usual standards and requires disclosure when AI was used to find reported problems.
Notice how these policies are enforced. None of them relies on a detector. They rest on the contributor’s certification and on maintainers’ judgment, because a policy that hangs on a tool with a high error rate would punish honest contributors and miss careful ones. A company with a provenance requirement gets further with the same approach: a clear policy, a disclosure field in the pull request template, and tooling logs from the approved assistants.
If you use a detector anyway
Where a detector is part of a process, a few habits keep it from doing harm. Calibrate it first on samples from your own setting: a handful of solutions you know were written by people and a handful you generated yourself, in the language and problem style you actually assess. If it can’t separate those cleanly, its scores on unknown work mean little. Treat a high score as a prompt for a conversation, never as the finding itself, and record what the follow-up showed. And keep in mind which way the errors cut: the people most exposed to a false positive are those who write clean, conventional code, while anyone determined to hide AI use can rename a few variables.
The more useful question: is the code correct and safe?
Inside an engineering team, “was this written by AI?” is usually standing in for a worry: that nobody really understands the change, that it hides a security hole, or that it quietly breaks something. A detector answers none of those. A careful review answers all of them, and it works the same way whether the author was a senior engineer, a junior one or a coding agent.
AI-generated code does have characteristic failure modes worth checking for deliberately. The vibe coding security guide collects the research on how often generated code is insecure; the short version for a reviewer is:
- Does it do what the task asked? Models solve the problem as they understood it. Read the change against the issue, not against the model’s own summary of it.
- Boundaries and failure paths. Empty inputs, nulls, time zones, retries, partial failures and concurrency are where plausible-looking code goes wrong.
- Trust boundaries. Input validation, authorization checks on every route, injection-safe queries and no secrets in code or logs.
- Callers and contracts. A changed signature or return shape can break code the diff never shows.
- Dependencies. Confirm that a newly added package exists, is the one intended and is maintained.
- Tests that test something. Generated tests can assert whatever the implementation already does. Check that they would fail if the code were wrong.
Volume is the practical problem. Coding agents can open more pull requests than a team can read closely, which is why many teams add an automated reviewer to the loop. The guide to how AI code review works covers what it catches and misses, and why false positives cost more when an agent will dutifully “fix” every comment it receives.
Reviewing AI-generated code with HeyDeer
HeyDeer is an AI code review agent that reviews the change itself, whoever wrote it. On GitHub it reviews pull requests from people and from coding agents such as Claude Code, Codex and Cursor, reviewing each push separately from the agent that wrote it and checking every finding against the code before posting it as an inline review comment. The AI-generated code review setup lets an agent read the review, fix the findings and push again, with the HeyDeer Review check gating the merge.
The same review runs locally before a pull request exists. The HeyDeer CLI reviews the branch’s commits plus uncommitted changes to tracked files against the default branch:
# install once (macOS and Linux), then sign in
curl -fsSL https://heydeer.ai/install.sh | sh
heydeer login
# review the branch and uncommitted changes against the default branch
heydeer review "Add retry with backoff to the payment webhook handler"Because HeyDeer checks each finding against the code, a review takes minutes, so it fits the moment a branch is ready to push, or the end of a coding agent’s task, rather than every commit. Later reviews of the same branch cover what changed since the last one and recheck open findings. The CLI docs list the options, including --json for agents that read the result.
Sources
- Suh et al., An Empirical Study on Automatically Detecting AI-Generated Source Code: How Far Are We? (ICSE 2025)
- Pan et al., Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education (ICSE-SEET 2024)
- Yang et al., Zero-Shot Detection of Machine-Generated Codes (2023)
- Shi et al., Between Lines of Code: Unraveling the Distinct Patterns of Machine and Human Programmers (ICSE 2025)
- Ye et al., Uncovering LLM-Generated Code: A Zero-Shot Synthetic Code Detector via Code Rewriting (AAAI 2025)
- Lee et al., Who Wrote this Code? Watermarking for Code Generation (ACL 2024)
- Suresh et al., Is The Watermarking Of LLM-Generated Code Robust? (2024)
- Orel et al., Droid: A Resource Suite for AI-Generated Code Detection (2025)
- Gentoo Council: AI policy
- NetBSD Commit Guidelines
- QEMU: Code provenance
- Linux kernel: Guidelines for tool-generated content
- Linux kernel: AI coding assistants
- curl: Contributing
Frequently asked questions
Can you tell if code was written by AI?
Whether code was written by AI can sometimes be guessed, but not reliably proven from the code alone. Detectors and human reviewers look for statistical predictability and stylistic habits, and research shows existing detectors perform poorly on code and break when the code is lightly edited. Provenance evidence such as commit history, editor logs or a conversation with the author is far stronger.
How accurate are AI code detectors?
AI code detectors are not accurate enough to act on alone. An ICSE 2025 study concluded that existing detection tools all perform poorly and lack generalizability, and an ICSE-SEET 2024 study of five detectors on 5,069 Python samples reached the same conclusion. Research detectors score better on their own benchmarks, but drop on new languages, new models and edited code.
How do AI code checkers work?
AI code checkers that look for AI authorship work in one of three ways: they measure how predictable each token is to a language model, they run a classifier trained on labeled human and AI code, or they look for a watermark the generating model inserted. Some newer research methods ask a model to rewrite the code and measure how much it changes.
Can AI-generated code be made undetectable?
AI-generated code can often be made hard to detect with small, meaning-preserving edits. A 2024 study found that renaming variables and inserting dead code pushed watermark detection rates below 50% in many cases, and a 2025 study found most detectors were easily defeated by output prompted to look human-written.
Is it bad to use AI-generated code?
Using AI-generated code is a normal part of software work in many teams, and the risk lies in merging it unreviewed. Generated code can contain security flaws, wrong assumptions and broken callers, so it needs the same review, tests and ownership as any other change. Some open-source projects restrict or require disclosure of AI contributions for licensing reasons.
Which open-source projects ban AI-generated code?
Several open-source projects restrict AI-generated code. Gentoo forbids contributions created with the assistance of natural-language AI tools (April 2024), NetBSD presumes LLM-generated code is tainted and requires core approval, and QEMU declines contributions believed to include AI-generated content. Others, such as the Linux kernel and curl, accept AI-assisted work with transparency and full human responsibility.
What should you check in AI-generated code?
AI-generated code deserves the checks any risky change gets: whether it does what the task asked, how it handles errors and empty or boundary inputs, whether it validates untrusted input and enforces authorization, whether it leaks secrets, which callers it breaks, and whether its dependencies exist and are maintained. Tests and an independent review catch most of these.



