A layered security-audit workflow for Claude Code: a deep LLM-driven repository audit, continuous guardrails during daily work, deterministic CLI scanners the LLM can't replace, and per-PR review — with the exact commands and the order to run them in.
Before I trust an AI agent with a codebase, how do I find what it — and everyone else — could break first?
No single tool is enough. Reasoning-based audits catch design and logic flaws that pattern scanners miss; deterministic scanners catch CVEs, leaked secrets across Git history, and misconfigurations an LLM will never enumerate reliably. This guide stacks both:
- Deep audit —
claude-security(official Anthropic plugin) for a thorough, verifier-checked pass over the whole repo. - Continuous guardrails —
security-guidanceand Semgrep Guardian, catching bad patterns as code is written. - Deterministic scanners — Gitleaks, OSV-Scanner, Trivy for secrets, dependencies, and IaC.
- Per-PR review —
/security-reviewand/code-review maxon every branch.
Everything below runs inside Claude Code unless marked as a terminal command. Open the project root first.
Isolation warning. The audit plugins run with the same file and shell permissions as Claude Code, with no separate sandbox. Never point them at an untrusted or suspicious repository without a sandbox/container. This is repeated in context below — it's the one thing not to skip.
- Before you start
- 1. Deep repository audit with claude-security
- 2. Continuous guardrails
- 3. Deterministic scanners
- 4. Every PR and branch
- Recommended sequence
- Recommended stack
- Related
- Further reading
- License
Start from a clean state so the report is tied to a specific revision and fixes are easy to review and roll back:
git status
git add .
git commit -m "checkpoint before security audit"claude-security is the official Anthropic plugin for a deep security audit of a repository. Open the project root in a terminal and start Claude Code:
cd C:\path\to\your\repo
claudeInside Claude Code:
/plugin marketplace add anthropics/claude-plugins-official
/plugin install claude-security@claude-plugins-official
/reload-plugins
/claude-security
Skip the marketplace add line if the official marketplace is already connected.
After /claude-security a menu appears:
- Scan codebase — full code audit.
- Choose Whole repository.
- Set the highest available effort — for a first audit prefer
exhaustive/max. - Let the scanner explore the repository, but don't let it change code automatically.
The plugin analyzes architecture, public entry points, authentication/authorization, injection, SSRF, file operations, data leaks, privilege escalation, and other vulnerability classes. On large projects it prioritizes attacker-reachable code first and usually skips generated/vendor files unless the most exhaustive mode is selected.
Results land in a directory like:
CLAUDE-SECURITY-2026.../
├── report.md
├── findings.jsonl
└── revision...
Each candidate issue is re-checked by independent verifier agents to cut down false positives.
To generate fixes, run the plugin again:
/claude-security
and choose:
Suggest patches
The plugin writes patch files but does not apply, commit, or push them on its own. That's the point — review each patch by hand before applying it.
- No isolation. The plugin works with the same file and shell permissions as Claude Code, without a separate sandbox. Don't run it on a suspicious or untrusted repository without a sandbox/container.
- Plugin/CLI compatibility (
v0.10.0). There are open reports that plugin version0.10.0is incompatible with some recent Claude Code versions: a scan may fail withWorkflow tool not available. If you see exactly that error, the problem is almost certainly CLI/plugin compatibility, not your repository — update Claude Code and reinstall/update the plugin first. - Resource usage — it is heavy. Scanning a single source folder is still a multi-agent run: up to ~14 subagents in parallel, each reading and grepping across the source. Expect 100% CPU and 20+ GB of memory while it runs; both drop the moment the panel finishes. Close other heavy work first, and don't launch it on a memory-constrained machine. The setup commands you'll see early on —
git ls-files,mkdir, andpython … write_scan_meta.py— are the scan sizing itself up (size gauge, report directory, revision stamp), not suspicious activity. - Python dependency (watch out on Windows). The scan's report scripts need Python. A
uv-managed interpreter is not onPATH—where python, thePATH, and the usual install directories will not find it, because uv keeps it outsidePATH; reach it withuv run pythonor locate it withuv python find. If you rely on auto-detection you may install a redundant second Python (e.g. viawinget) — harmless but unnecessary. Make sure a discoverable Python exists, or point the tool at the uv-managed one.
For continuous control rather than one big audit:
/plugin install security-guidance@claude-plugins-official
/reload-plugins
It works continuously:
- warns about insecure patterns during
EditandWrite; - reviews the diff after a task completes;
- can separately check a prospective commit.
So the ideal combination is:
claude-security— deep periodic audit;security-guidance— control during daily development.
For higher recall, enable two parallel LLM reviews.
PowerShell:
$env:SG_DUAL_OR = "on"
claudeBash:
export SG_DUAL_OR=on
claudeThis roughly doubles the cost of the check but can surface more issues. Add project-specific rules in .claude/claude-security-guidance.md.
The best additional automated layer. Install per Semgrep's current instructions:
/plugin marketplace add semgrep/guardian
/plugin install semgrep@semgrep-marketplace
/reload-plugins
Then ask:
Login to Semgrep
Guardian automatically checks files Claude creates through:
- Semgrep Code;
- Semgrep Supply Chain;
- Semgrep Secrets.
It uses deterministic rules and complements Claude's reasoning-based audit well.
Both are also present in the Claude Code ecosystem:
- Aikido — a single platform for SAST, secrets, and IaC;
- Endor Labs — more focused on dependency and software supply-chain risk.
They make sense for teams already using those cloud platforms. For a local or free workflow, Semgrep plus the CLI scanners below is usually simpler.
An LLM audit does not replace tools that exhaustively check the full Git history, lock files, CVE databases, and infrastructure configs. Don't skip these.
Secrets across the whole Git history:
gitleaks git -vChecks not only the current files but patches throughout Git history — an API key removed from the current version can still live in an old commit.
Vulnerable dependencies:
osv-scanner scan -r .Checks dependency manifests and lock files against the OSV database.
One comprehensive local sweep:
trivy fs --scanners vuln,misconfig,secret .Checks:
- dependencies and CVEs;
- secrets;
- Dockerfiles;
- Kubernetes;
- Terraform;
- other IaC/misconfiguration issues.
Claude Code ships this built in:
/security-review
It reviews the diff of the current branch against the default branch in origin — so a Git remote named origin must exist.
Broader than a plain security review:
/code-review max
Beyond security it can also find:
- logic errors;
- broken edge cases;
- concurrency problems;
- incorrect error handling;
- contract incompatibilities;
- potential regressions.
1. Make a clean checkpoint commit
2. gitleaks git -v
3. osv-scanner scan -r .
4. trivy fs --scanners vuln,misconfig,secret .
5. /claude-security → Scan codebase → Whole repository → max/exhaustive
6. Verify every finding directly in the code
7. /claude-security → Suggest patches
8. Apply patches one at a time, together with regression tests
9. /code-review max
10. /security-review
For the strongest result:
claude-security
+ security-guidance
+ Semgrep Guardian
+ Gitleaks
+ OSV-Scanner
+ Trivy
+ ordinary unit/integration security tests
Part of a set of agent guides — pick the layer you need:
- Awesome AGENTS.md — the base, tool-agnostic ruleset every agent imports (one
AGENTS.md). - Awesome Agent Skills — portable
SKILL.mdskills every agent loads: code review, debugging, security and leak audits, code and text cleanup. - Agent MCP Integrations — MCP servers that connect agents to browsers, cloud, databases, infra, and domain APIs.
- Claude Code Token Optimization — the token-efficiency layer (RTK, LSP, Context7,
codebase-memory-mcp, claude-mem, Caveman, Ponytail). - Claude Code Security Audit — this repo: the layered security-audit workflow.
- Claude Code documentation — slash commands, skills, plugins.
- anthropics/claude-plugins-official —
claude-security,security-guidance. - Semgrep — Guardian, Code, Supply Chain, Secrets.
- Gitleaks · OSV-Scanner · Trivy
Released under the MIT license. The tools and plugins referenced here are third-party projects under their own licenses — check each before use.