in this blog
A pull request diff can pass every linter and unit test while still hiding a subtle logic flaw. Static pattern matchers look for known syntax signatures, so they routinely miss context-dependent bugs like a local server exposed to DNS rebinding or an internal proxy open to SSRF. We automated the first pass of pull request security review with Claude to catch those semantic flaws before merge. That setup only holds up in practice when two boundaries are enforced alongside it: aggressive false-positive filtering to keep inline comments worth reading, and a human approval gate on untrusted pull requests so adversarial diffs never reach the model.
What runs where
Security review with Claude splits into two stages that share the same underlying analysis. Before code leaves a developer's machine, running /security-review in Claude Code scans all pending local changes. The developer sees explanations of potential vulnerabilities in the terminal and can ask Claude Code to implement fixes directly in the inner loop. Once a branch becomes a pull request, the Claude Code Security Reviewer GitHub Action takes over in CI. It triggers automatically on new pull requests, runs a diff-aware scan on changed files, and posts inline review comments with severity ratings and remediation guidance.

Both stages support repository-specific customization, so your local checks and CI checks enforce the same rules. To customize the local command, copy security-review.md into your project's .claude/commands/ directory and edit its instructions.
| Stage | Trigger | Scope | Output and remediation |
|---|---|---|---|
Local (/security-review) | Manual command in Claude Code before commit | All pending local changes in the working tree | Terminal explanations; developer can ask Claude Code to apply fixes immediately |
| CI (GitHub Action) | Automatic on pull_request events (gated for external forks) | Changed files in the pull request diff | Inline PR comments with severity ratings and fix recommendations |
What the scanner checks
The scanner runs language-agnostic semantic analysis on the diff, so it works across any stack in the repository. Its default audit prompt targets high-impact vulnerability classes: injection attacks (SQL, command, LDAP, XPath, NoSQL, and XXE), authentication and authorization flaws, business logic bugs such as race conditions and TOCTOU issues, remote code execution via deserialization or eval, reflected, stored, and DOM-based XSS, insecure data handling, and dependency vulnerabilities.
Semantic analysis earns its keep on flaws that require reading how components interact across a diff. In Anthropic's write-up of the tool, they reported two catches from their own internal pull requests. In one PR, an engineer added a feature to an internal tool that started a local HTTP server intended only for local connections; the GitHub Action flagged a remote code execution vulnerability exploitable through DNS rebinding before the code merged. In a second internal PR for a proxy system managing internal credentials, the action caught an SSRF vulnerability in the diff.
Neither bug looks like a classic syntax error. Catching them requires understanding the trust boundary implied by the code, which is where a semantic first pass complements traditional static analysis.
Keeping false positives down
An automated reviewer that cries wolf on every pull request gets ignored within a week. Keeping inline comments actionable requires filtering out low-impact findings by default and avoiding redundant scans across noisy commit histories. We rely on three controls to keep the signal high:
- Built-in exclusions for low-impact classes. The action automatically filters out Denial of Service vulnerabilities, rate limiting concerns, memory or CPU exhaustion issues, generic input validation without proven impact, and open redirects.
- Cache-checked runs. The
run-every-commitinput defaults tofalse, so the action uses its cache across commits. Enabling it on multi-commit pull requests can increase false positives. - Repository-specific instruction files. You can tune the scanner to your team's security policies by passing custom text files to
false-positive-filtering-instructionsandcustom-security-scan-instructionsin the workflow, or by editing.claude/commands/security-review.mdfor local runs.
Treat the custom instruction files like any other review rubric: when a finding does not apply to your threat model, document the exclusion once so the scanner stops flagging it on future diffs.
Workflow setup
The GitHub Action runs from a standard workflow file in .github/workflows/security.yml. It triggers on pull_request events and needs two permissions: pull-requests: write to post inline review comments, and contents: read to inspect repository files. The checkout step uses actions/checkout@v4 with fetch-depth: 2 so the diff-aware scanner has the parent commit context it needs.
The example below shows a minimal .github/workflows/security.yml file configured to post inline comments using a repository secret:
name: Security review
on:
pull_request:
permissions:
pull-requests: write
contents: read
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: anthropics/claude-code-security-review@main
with:
comment-pr: true
claude-api-key: ${{ secrets.CLAUDE_API_KEY }}
The CLAUDE_API_KEY secret must be enabled for both the Claude API and Claude Code usage. If you leave the optional inputs unset, the action uses claude-opus-4-1-20250805 as its default claude-model, enforces a claudecode-timeout of 20 minutes, and keeps run-every-commit set to false. Override those inputs only when your repository's size, latency budget, or model policy requires it.
Where a person still decides
The most important operational boundary is trust. The GitHub Action is not hardened against prompt injection attacks, so running it automatically on untrusted pull requests exposes the workflow to adversarial instructions hidden inside a diff or commit message. Public repositories and any repo accepting external contributions should never let fork pull requests trigger the scan automatically.
Enable GitHub's "Require approval for all external contributors" setting in your repository's Actions configuration. With that gate active, workflows on external pull requests wait until a maintainer reviews the diff and approves the run. Only trusted pull requests execute the action without manual intervention.
Even on trusted branches, the scanner is a first pass, not an automated gatekeeper. Both inline PR comments and local /security-review output require human triage to confirm exploitability, weigh the finding against your production environment, and decide what must be fixed before merge.
