Large language models (LLMs) have transformed software development, yet our understanding of how they generate code remains critically underdeveloped. We address this gap by triangulating evidence across three layers. Longitudinally, autonomous agent-attributed code is statistically indistinguishable from human code under a semantic modification definition (HR = 1.019, p = 0.490), yet attracts disproportionately corrective modifications in production (49.1% vs 37.9% human baseline). This finding demands a causal explanation. Empirically, existing benchmarks overestimate LLM capabilities: models that achieve 84 to 89% correctness on synthetic tasks attain only 24 to 35% on real-world class-level code. Behaviourally, detection systems reveal puzzling asymmetries: GPT-3.5 is far more detectable than modern models (AUC-ROC = 0.96, a 27-point gap), even though modern models produce mutually similar code structures; yet no single feature reliably distinguishes AI-generated from human code at the class level, and the leading commercial detector achieves only 15 to 64% recall. Together, these findings raise a question that empirical studies cannot answer: why do LLMs generate code with these properties? This thesis proposes mechanistic interpretability, a causal token-level circuit tracing, as the bridge between empirical observation and principled correction. By identifying the transformer circuits responsible for detectable stylistic signatures, hallucination patterns, and systematic defects, we aim to drive an agentic repair framework that intervenes at the causal source of defects rather than patching surface symptoms.
Table 1. Code stability by collaboration tier. Mod. % = share of units modified at least once during the observation window; Median = median days to first modification; HR = Cox hazard ratio for modification risk relative to the human baseline (HR < 1.0 indicates lower risk). Def 1 = syntactic modification definition; Def 2 = AST-structural modification definition.
Model
ROUGE-L
CB-F3
TSED
Pass
GPT-o4-mini
0.60
0.88
0.82
0.29
Claude-4-Sonnet
0.68
0.90
0.84
0.36
Qwen-3-Coder
0.67
0.90
0.84
0.35
Average
0.65
0.89
0.83
0.33
Table 2. OpenClassGen evaluation: three LLMs on 300 stratified classes. CB-F3 = CodeBERTScore-F3; TSED = tree-edit similarity ( Rahman et al., 2026 ) .
Function-level
Class-level
Model
CB
GPTZero
CB
GPTZero
GPT-3.5
0.96
0.70 (29%)
0.89
0.53 (15%)
GPT-OSS
0.80
0.86 (64%)
0.81
0.83 (51%)
Claude 3 Haiku
0.70
0.71 (35%)
0.83
0.62 (20%)
Claude Haiku 4.5
0.71
0.76 (42%)
0.80
0.66 (21%)
Table 3. Detection AUC-ROC: CatBoost vs. GPTZero. GPTZero recall shown in parentheses; CatBoost recall ranges from 61–87% ( Rahman et al., 2025a ) .
Goal
Question
Metric
Evaluate real-world generation
How does context richness affect contamination-free performance?
Pass@k, functional coverage, edit distance
Assess detection robustness
How does adversarial perturbation affect structural detectors?
F1, AUROC, recall under Conditions A and B
Explain generation mechanisms
Which circuits cause each defect pattern?
Logit attribution, patching causal effect (Cohen’s d )
Validate mechanistic repair
Does circuit-informed intervention reduce defects?