Inspector in gloves and safety glasses checking a metal part for hidden cracks under a black light, with the article title about LLM secure code review without refusals
Cover based on a photo by U.S. Air Force photo by Senior Airman Benjamin Stratton, via Wikimedia Commons, Public domain

LLM secure code review works best as a fast first reader, not a judge: you hand a model a scoped diff of your own code, ask it for structured findings, and then prove or drop every finding with a tool, a test or a human. Done that way, AI code review for vulnerabilities catches real injection, authorization and data-exposure bugs early, at the cost of some noise you already know how to filter. Done loosely, it produces confident reports about bugs that don't exist, or it stops halfway because a safety classifier decided your own code review looked like an attack.

This guide covers both problems. It shows how to set up a secure code review with an LLM that you can trust, what the built-in Claude Code security review does and deliberately skips, why a Claude Code security review refusal can happen on code you own, and how to keep the review running when it does.

Your own code, or code you're authorized to review. Everything here assumes a repository you own or a client engagement that covers source review. Don't paste third-party code, customer data or secrets into a model you aren't cleared to share them with.

Diagram of an LLM secure code review loop: a scoped git diff and threat notes go to the model, the model returns structured JSON findings, each finding is confirmed by Semgrep, CodeQL or a failing test, unconfirmed findings are dropped or sent back, and confirmed ones go to human triage and a fix with a regression test
Diagram of an LLM secure code review loop: a scoped git diff and threat notes go to the model, the model returns structured JSON findings, each finding is confirmed by Semgrep, CodeQL or a failing test, unconfirmed findings are dropped or sent back, and confirmed ones go to human triage and a fix with a regression test Image: RedRouter, Original

What an LLM secure code review is good at

A model reads code the way a reviewer does: it follows data from a request handler into a query, notices that an authorization check is missing on one route out of ten, or sees that a file path comes from user input. Rule-based static analysis (SAST) finds patterns. A model can reason about intent, such as "this endpoint is supposed to be admin-only," which is where many access control bugs live.

That matches where real bugs cluster. Broken access control is first on the OWASP Top 10:2025, and the 2025 CWE Top 25 puts cross-site scripting (CWE-79), SQL injection (CWE-89), CSRF (CWE-352) and missing authorization (CWE-862) in its top four. Those are exactly the categories where reading the surrounding code matters.

What a model is bad at is being right on its own. It can invent a sink that isn't reachable, miss a sanitizer two files away, or rate a harmless pattern as critical. So the workflow below treats every model finding as a hypothesis until something outside the model confirms it.

The built-in option: Claude Code /security-review

Anthropic's claude-code-security-review repository says Claude Code ships a /security-review slash command by default, with the same analysis as its GitHub Action. Run it in a repository and it reviews your pending changes. The repository also publishes the command's prompt as security-review.md, which you can copy into .claude/commands/ and edit.

Read that prompt before you rely on it, because it tells you what the reviewer is told to ignore:

  • It reviews the diff against your base branch and asks for findings "newly added by this PR," not existing issues.
  • It asks for findings only where the model is more than 80% confident of real exploitability.
  • It excludes denial of service, rate limiting and resource exhaustion, and secrets stored on disk.

Those are reasonable defaults for pull request noise, but they are choices. If your threat model cares about resource exhaustion or legacy code, the default command won't cover it, and you should edit your copy.

The GitHub Action version comes with a warning in its own README: it "is not hardened against prompt injection attacks and should only be used to review trusted PRs." Code under review is untrusted input to the model. A comment in a malicious pull request can try to steer the reviewer, so don't run any LLM reviewer with write permissions on code from strangers without a maintainer approving the workflow first.

A secure code review workflow you can trust

1. Scope the input

Review a diff or one component at a time, not a whole monorepo. Include the files the diff touches plus the code they call into: the auth middleware, the query helper, the template filter. Add a few lines of threat notes: who the users are, which routes are public, what data is sensitive. A model that knows "tenants must never see each other's invoices" finds IDOR-style bugs that a model without that sentence misses.

Strip secrets, .env files, session tokens and customer data from the context first. Retention settings on a provider don't erase copies in your local transcripts or CI logs.

2. Ask for structured findings

Free-form review text is hard to verify. Ask for JSON with one object per finding, including the file, line, CWE, the source-to-sink path and a concrete way to confirm it. This script sends a diff to RedRouter's OpenAI-compatible API with a JSON schema, using glm-5.3-flash-red, which lists JSON output and tool calling in the model catalog:

import json, os, subprocess
from openai import OpenAI

client = OpenAI(base_url="https://redrouter.org/v1",
                api_key=os.environ["REDROUTER_API_KEY"])

diff = subprocess.run(["git", "diff", "origin/main...HEAD"],
                      capture_output=True, text=True, check=True).stdout
threat_notes = open("THREAT_NOTES.md").read()

schema = {
    "type": "object",
    "properties": {
        "findings": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "file": {"type": "string"},
                    "line": {"type": "integer"},
                    "cwe": {"type": "string"},
                    "severity": {"type": "string", "enum": ["high", "medium", "low"]},
                    "source_to_sink": {"type": "string"},
                    "how_to_confirm": {"type": "string"},
                    "suggested_fix": {"type": "string"}
                },
                "required": ["file", "line", "cwe", "severity",
                             "source_to_sink", "how_to_confirm", "suggested_fix"],
                "additionalProperties": False
            }
        }
    },
    "required": ["findings"],
    "additionalProperties": False
}

resp = client.chat.completions.create(
    model="glm-5.3-flash-red",
    max_tokens=4096,
    messages=[
        {"role": "system", "content": (
            "You are reviewing the user's own code for security bugs. "
            "Report only issues you can trace from an input to a sink in the "
            "code shown. For each, say exactly how to confirm it with a test "
            "or a static analysis query. If unsure, leave it out.")},
        {"role": "user", "content": f"Threat notes:\n{threat_notes}\n\nDiff:\n{diff}"},
    ],
    response_format={"type": "json_schema",
                     "json_schema": {"name": "review", "strict": True, "schema": schema}},
)
choice = resp.choices[0]
if choice.finish_reason != "stop":
    raise SystemExit("Review was cut off; split the diff and retry")
findings = json.loads(choice.message.content)["findings"]
print(json.dumps(findings, indent=2))

The JSON comes back as a string in choices[0].message.content, as the structured output docs describe, so parse it and validate it before anything else uses it. RedRouter forwards the schema to the model but, per those docs, doesn't run its own validator over the answer, which is why the script rejects a truncated reply. Every parameter above is on the supported list for Chat Completions; unsupported fields return HTTP 400, per the API compatibility guide. Very large diffs should be split: the model's output cap is 8,192 tokens, even though its context window is much larger.

We haven't benchmarked this prompt against a labeled set of vulnerable code, so treat it as a starting point and tune it on your own history of fixed bugs.

3. Prove each finding outside the model

This is the step that makes LLM secure code review worth doing. For each finding, pick one way to confirm it:

  • A static analysis check. Run Semgrep (semgrep scan --config auto . or the rulesets you already use) or a CodeQL database analysis on the same code, and see whether it flags the same path. Agreement raises confidence. Disagreement is a prompt to read the code yourself.
  • A failing test. Write a unit or integration test that exercises the bug in a local or staging environment you control: the second tenant's request that returns the first tenant's invoice, the path that escapes the upload directory. If you can't write a failing test, you don't have a confirmed bug yet.
  • A human read. For logic and authorization bugs that no tool models well, a reviewer who knows the system decides.

Findings that can't be confirmed get dropped or sent back to the model with the evidence that contradicts them. Confirmed findings get a fix and keep their test as a regression test.

4. Keep humans on the merge button

The model drafts findings, tools and tests confirm them, and a person decides what ships. That division is also how you keep a prompt-injected or simply wrong review from turning into a bad merge.

Why a Claude Code security review refusal happens on your own code

Mainstream assistants run safety classifiers that watch for cyberattack assistance. Security review is close to that line by nature: a good reviewer describes how a bug could be exploited. Sometimes the classifier interrupts work that is plainly defensive.

One public example: in a Claude Code GitHub issue filed July 17, 2026, a developer reported five safeguard interruptions while reviewing their own experimental Go and Rust project, with no deployed service or third-party target. RedRouter's refusal archive entry summarizes it and its limits: the issue lists request references and quotes one safeguard notice, but it doesn't include full transcripts, and RedRouter hasn't reproduced the blocks. It's one report, not a rate. The broader refusal archive collects other source-checked cases.

You can't fully prevent this from the client side, but you can make it less likely and less costly:

  • Say plainly in the prompt that this is your code and the goal is to find and fix bugs.
  • Ask for the source-to-sink path and a confirming test, not a working exploit against a live system.
  • Keep reviews small, so an interruption costs one step instead of a whole session.

Keep the review running when a step is blocked

If interruptions keep breaking your workflow, you have two practical options.

Hand only the blocked step to another model. Keep your main assistant for everything else and route the review step that was refused to a reduced-refusal model. The broker pattern post shows how to set that up from Claude Code.

Run the whole review through RedRouter. Claude Code can point at RedRouter's Anthropic Messages-compatible endpoint with ANTHROPIC_BASE_URL=https://redrouter.org and an explicit catalog model; the Claude Code setup docs give the full variable list and describe it as a configuration recipe, not a live-tested compatibility result. OpenCode and Cline setups are in Claude Code, OpenCode and Cline on RedRouter. Because /security-review is a prompt, your edited copy in .claude/commands/ should travel with the project; test it on a known-vulnerable branch before you trust it on a new model.

A reduced-refusal model changes how often a review step is declined, not how often a finding is right. The verification step above applies to every model, including this one.

Choosing a model and what it costs

Code review sends a lot of input (the diff, the surrounding files, the threat notes) and gets back comparatively little output, so input price matters most.

  • GLM 5.3 Flash Red (glm-5.3-flash-red): $0.25 per 1M input tokens, $0.10 per 1M cached input tokens and $1.00 per 1M output tokens, with a 1,048,576-token context window, tool calling and JSON output. Its catalog entry describes it as GLM 5.3 Flash modified to reduce refusals. It's a good fit for running the structured review on every pull request.
  • red-cyber-1 (Beta): $0.28 input, $0.10 cached input and $1.10 output per 1M tokens, also with a 1M context window, tool calling and JSON output. The models docs describe it as RedRouter's featured model for authorized penetration testing and red-team work, and it's the model the Claude Code setup docs use.

Current GLM 5.3 Flash Red rates are on the pricing page, and red-cyber-1 rates are on its model page. Prices can change, so check those pages before budgeting.

Keeping your code private

Source code is often the most sensitive thing a company has. On RedRouter, each API key has a store_content setting, and new keys start with prompt and completion storage off. Account-wide zero data retention is a separate opt-in switch in Settings that is off by default; eligibility and pricing are in the data handling docs. What RedRouter keeps explains the difference, and the security page covers how RedRouter approaches authorized security work. Whatever provider you use, check your own CI logs and local transcripts too.

Further reading

The OWASP Code Review Guide is a free reference for what a manual secure code review should cover, and OWASP ASVS 5.0.0 gives a checklist of requirements you can turn into threat notes for the model.

FAQ

What is LLM secure code review?

It's using a large language model to read your own code or diffs and report likely security bugs, such as injection, missing authorization or path traversal. The model drafts findings; static analysis, tests and human reviewers confirm them before anything changes.

Can AI code review find vulnerabilities reliably?

It finds real bugs, especially logic and authorization issues that pattern-based tools miss, but it also reports false positives and misses things. Treat each finding as a hypothesis and confirm it with Semgrep, CodeQL, a failing test or a human read.

Why does Claude Code refuse a security review of my own code?

Its safety classifiers watch for cyberattack assistance, and security review language can look similar. Public reports, such as one archived in RedRouter's refusal archive, describe interruptions during defensive review of code the reporter owned. Clear context and small, fix-focused requests help; routing blocked steps to a reduced-refusal model is the fallback.

Does an LLM replace SAST tools?

No. Use both. SAST is repeatable and cheap to run on every commit; a model adds reasoning about intent and context. Agreement between them is a strong signal, and disagreement tells you where to look.

Is it safe to send proprietary code to an LLM API?

Only if your agreements allow it and the provider's data handling fits your policy. Remove secrets first, check the provider's retention settings, and remember that local logs and transcripts keep their own copies.

Sources

All read on November 11, 2026 (PT).