The security-guidance plugin: Claude reviews its own code for vulnerabilities
TL;DR
The security-guidance plugin has Claude review its own code for security issues at three points (each edit, end of turn, commit) and fix them in-session. Add your threat model via a guidance file; it reminds rather than blocks, so you still need Code Review and CI.
AI writes code fast, but it can just as quickly write classic security bugs: SQL injection, eval on user data, unsanitised innerHTML. Waiting for PR review to catch them is late and costly. Anthropic's security-guidance plugin has Claude review the code it just wrote within the session and fix it right away, before it reaches a pull request. Install once, it runs automatically, nothing to remember.
Installation
/plugin install security-guidance@claude-plugins-official
// Enable for the whole team: .claude/settings.json
{ "enabledPlugins": { "security-guidance@claude-plugins-official": true } }
It needs Python 3.7+ (the agentic commit review needs 3.10+) and a git repository. On first run, the plugin creates a virtual environment under ~/.claude/security/.
Three layers of checks
| When | How | Catches | Cost |
|---|---|---|---|
| Each file edit | Pattern match, no model call | eval(, os.system, pickle, innerHTML =, edits to GitHub workflow files | Free |
| End of each turn | A separate model reviews the git diff in the background | Authorisation bypass, IDOR, injection, SSRF, weak crypto | One model call per turn that changes files |
| When Claude commits/pushes | Agentic review reading surrounding code | Issues needing broad context, with few false positives | Possibly several model turns per commit |
The end-of-turn review covers up to 30 changed files and fires at most three times in a row; commit reviews are capped at 20 per hour. The reviewer is a separate Claude call with a fresh context, not the model that wrote the code grading itself.
Adding your own rules
.claude/claude-security-guidance.md: describe your threat model in plain language, e.g. "every/adminroute must callrequire_role("admin")before any database read"..claude/security-patterns.yaml(or.json): add regex or substring patterns to the per-edit check, e.g. warn on the API key prefixsk_live_.
Both are additive: these files can't disable built-in checks.
Where it fits
| Stage | Tool |
|---|---|
| In session | security-guidance plugin |
| On demand | /security-review on the current branch |
| Pull request | Code Review (Team/Enterprise plans) |
| CI | Your existing static analysis and dependency scanners |
Risks and caveats
- It reminds, it doesn't block: no layer blocks writes or commits; Claude receives findings as instructions to fix. For hard blocks, use hooks or CI.
- The model can miss things: treat it as one layer of defence, not a guarantee.
- Only Claude's commits are reviewed: commits you run from your shell (including the in-session
!escape) aren't. - Extra usage: reviews run on Opus by default; change with
SECURITY_REVIEW_MODELandSG_AGENTIC_MODEL.
How to apply it
- Dev: Install at user scope so every project has it; check
~/.claude/security/log.txtif reviews don't appear. - Tech Lead: Write
claude-security-guidance.mdfrom real security bugs you've had, and commit it to the repo. - PM/Security: Track findings fixed in-session; those are bugs that never reach a PR.
Sources & references
- Catch security issues as Claude writes code — Claude Code Docs