AI Security Scanning Is 86% Wrong — So We Generate the Scanner From the Spec
Semgrep's study: Claude Code's security review produced 86% false positives, and identical runs returned 3, 6, then 11 findings. The fix isn't a better model — it's deterministic rules compiled from your specs.
Two numbers tell you everything about where AI security scanning actually is. The first: 14% true positives. The second: 3, then 6, then 11.
The study
Semgrep’s team ran Claude Code (v1.0.32, Sonnet 4) and OpenAI Codex as security reviewers across 11 open-source Python web apps — roughly 7,000 files, 800K+ lines of code. They collected 445 findings and manually triaged them, with dynamic validation for the trickiest classes (IDOR, auth bypass). The results:
- Claude Code: 46 vulnerabilities, 14% true positive rate — 86% of findings were false positives.
- Codex: 21 vulnerabilities, 18% true positive rate.
- The same prompt against the same codebase returned 3, 6, and then 11 findings across three runs — non-determinism the study attributes to context rot.
(The “1 XSS across all tested apps” figure you may have seen came from
Anthropic’s separate /security-review command, not the main experiment.
Credit where each number lives.)
The villain isn’t accuracy. It’s variance.
An 86% false-positive rate is bad, but a human reviewer can live with noisy — triage exists. What a pipeline cannot live with is the variance: run the same review twice, get a different report. Your CI gate means something different on Tuesday than it did on Monday, and nothing tells you.
Deterministic rules don’t have this property. The same rule against the same code returns the same finding, every run, which is why mutation-scored test suites and CI gates work at all.
The reframe: don’t replace the scanner. Generate it from the spec.
Here’s the part most teams haven’t tried: your specs already know what “secure” means for your system. Every requirement that says inputs must be sanitized or this endpoint requires auth or this data must be encrypted is a scanner rule waiting to be compiled:
REQUIREMENT PAY-001 "Process card payments" ASPECT security(level: "critical", sanitize_inputs: true, encryption_at_rest: true)compiles to Semgrep YAML rules — sql-injection from sanitize_inputs,
auth-bypass from auth: "none", secret-leak from encryption params —
and every rule carries its requirement ID in the metadata, so a finding
arrives with its why attached:
- id: cbrl-PAY-001-Payment-sql-injection metadata: cbrl_requirement: PAY-001 acceptance_criteria: "Card data is never logged or concatenated into queries"This is the hybrid, honestly stated: Semgrep (or your scanner of choice) stays the engine — its 2026 benchmark work is explicitly a hybrid AI-plus- rules story, and SonarSource’s rebuttal of the study makes the same point from the SaaS side. The missing half nobody shipped is the spec-derived half: SonarQube ships 7,000+ rules (their product page’s count) and none of them are yours. Rules compiled from your requirements are the only scanner config that can’t drift from what your system actually must do.
The confession beat
We found this the embarrassing way. Our own sample spec — the travel-
booking demo we ship — carried @security(pci_dss: true) and
@security(role: "admin") and @security(level: "standard"). None of
those parameters exist in our aspect registry. The generator silently
skipped them and emitted nothing.
The platform whose entire thesis is “specs must fail loudly” had a spec failing quietly. That’s why the validator gate now exists: unknown parameters and invalid values are hard errors naming the requirement, the parameter, and the fix — before generation, not after an audit. The fixed sample ships in the repo, and the regression test treats those three parameters as the permanent canary.
Run it
$ ctxbrew coverage-behavior --ctrf report.ctrf.json \ --requirements src/*.requirementsor generate the Semgrep config for a spec and diff it against whatever rules your pipeline inherited from 2019. Deterministic findings with requirement IDs attached — the same answer every run.
Sources
- https://semgrep.dev/blog/2025/finding-vulnerabilities-in-modern-web-apps-using-claude-code-and-openai-codex — Semgrep study (Sept 2, 2025): Claude Code 14% TPR / 86% FPR, Codex 18%, 11 OSS Python apps, ~800K LOC, 445 manually triaged findings
- https://www.sonarsource.com/blog/thoughts-on-claude-code-security/ — SonarSource's rebuttal (~3% FP claim for SaaS tools) — the hybrid context
- https://semgrep.dev/blog/2026/3-5x-more-true-positives-how-we-benchmark-ai-powered-detection — Semgrep's 2026 benchmark pivot: hybrid AI + rules