AI detection in code is a different problem from AI detection in prose, and the tools that work on essays do not transfer cleanly. Code is supposed to be predictable. A function that does the same thing every time is a good function, and a codebase where everyone writes the same way is a healthy codebase.
That is the opposite of what a prose detector rewards. Which is why the honest answer about AI code detection is that nobody has a reliable one, and the controls that do work are not detection at all.
Why prose detectors fail on code
A prose classifier looks for unpredictability, varied sentence length and surprising word choices. Good code has none of those things. It is terse, repetitive by design and full of idiomatic patterns that every competent programmer writes identically.
Imports sit at the top. Error handling looks the same in every file. A loop is a loop. If the code is well formatted, it looks like the output of a linter, which is exactly what it is supposed to look like. Every signal points toward "generated" for a tool trained on prose.
The comments are the exception. Natural-language comments and commit messages are closer to prose, and they are the part a language-based detector might actually score. A generated codebase with generated comments can look generated in the comments while the code itself is unremarkable.
What is actually being measured
Most tools that claim to detect AI code are really measuring one of three things: similarity to existing public code, style consistency with a reference, or language-model probability over tokens.
Similarity is a plagiarism question, not an authorship question. It can tell you that a block matches a public repository, which is useful and checkable. It cannot tell you who wrote it. And since modern tools are trained on public code, some overlap with published solutions is expected. The plagiarism versus AI detection distinction applies here too, just with a different index.
Style consistency is a weaker signal. Variable names, indentation and comment style can be copied, learned or generated. A student whose style suddenly changes may have used a tool, may have found a tutorial, or may have simply matured as a programmer.
Language-model probability is the same problem as prose detection, only harder, because the training data includes almost every good way to write the same function. A high-probability function is a normal function.
The risks that actually matter
For a school or an employer, the useful questions about AI-generated code are not "was it generated". They are:
Is it correct? Generated code has bugs with confidence. It passes the examples in the prompt and fails at the edges.
Is it secure? Generated code often reproduces insecure patterns from its training data. Input validation, authentication and error handling are where the mistakes cluster.
Is it licensed? Code generated from a model trained on open source can reproduce fragments that carry a licence. Copyleft contamination is a real legal question for some projects and a PR problem for others.
Can the author explain it? This is the control that works. Anyone who wrote the code can walk through it, change it and answer questions about why it is shaped the way it is.
None of those risks are addressed by an AI score. A detector tells you nothing about correctness, security or licensing, and those are what cause harm.
If you have to check a student's code
Start with the process, not the output. Ask for the commit history. Ask them to modify the code in front of you: add a feature, change a requirement, fix a seeded bug. Ask them to explain a choice.
A programmer who wrote the code can talk about it. A programmer who pasted it can sometimes talk about it too, which is why the modification test matters. Ask them to change one thing under supervision and watch how they navigate the file.
Compare the submission with their earlier work. A sudden jump in sophistication is a question, not a finding. A student who learned a framework over the summer is allowed to improve.
If the work is generated and prohibited, a process conversation is the evidence. The detector is not. The what detectors get wrong guide covers why the same logic applies to essays, and the is this AI piece separates the questions people usually blur.
A fair test you can run on any code sample
Take twenty lines. Ask the author to explain what each block does, what happens at the edges, and what they would change. Ask one question whose answer is not visible in the code, such as why a particular data structure was chosen.
Then ask for one small modification and time it. Competent authors are fast in their own code. Paste artists are slow, because every edit requires reading a file they have never really seen.
No score is involved in that test, and it produces a much better answer.
The verdict
Code generation is real, common and often fine. Detecting it reliably is not a solved problem, and the tools that claim to solve it are measuring similarity or style rather than authorship.
Use tests, code review and modification conversations. They are slower than a percentage and far more honest. If you want to see what an unreliable detection score looks like next to the evidence, check your text free and read the reasons. The experience is a good reminder of what a number can and cannot tell you about how something was made.