The security guidance plugin makes Claude review its own code changes for common vulnerabilities while it works and fix what it finds in the same session. The plugin catches issues such as injection, unsafe deserialization, and unsafe DOM APIs before the code reaches a pull request, reducing how much security review falls to human reviewers downstream. Once installed, the plugin runs automatically. There is nothing to invoke and no separate command to remember. The plugin is the in-session companion to Code Review, which runs on pull requests. This plugin reduces what reaches the PR. Code Review catches what does. For how the plugin layers with on-demand review and CI scanning, see How this fits with other security tools.Documentation Index
Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Claude Code CLI version 2.1.144 or later
- Python 3.8 or later on your
PATH. The plugin triespython3,python, andpy -3in that order
Install the plugin
In a Claude Code session, install from the official Anthropic marketplace:/reload-plugins to load it.
Enable in cloud sessions and shared repositories
User-scoped plugins do not carry into Claude Code on the web, because those sessions run on Anthropic infrastructure rather than your machine. To enable the plugin there, or to turn it on for everyone who clones a repository, declare it in the project’s checked-in settings:.claude/settings.json
enabledPlugins in managed settings.
What the plugin checks
The plugin reviews Claude’s work at three points, each at a different depth:- On each file edit: a fast pattern match for risky calls, with no model call
- At the end of each turn: a background model review of everything that turn changed
- On each commit or push Claude makes: a deeper agentic review that reads surrounding code
On each file edit
When Claude writes to a file, the plugin scans the new content for known risky patterns. This is a pattern match with no model call, so it adds no usage cost. Example pattern categories:- Dynamic code execution:
eval(,new Function,os.system,child_process.exec - Unsafe deserialization:
pickle - DOM injection:
dangerouslySetInnerHTML,.innerHTML =,document.write - Workflow files: edits under
.github/workflows/, which can grant repository-level permissions
security-patterns.yaml file.
At the end of each turn
A turn is one round of Claude responding: you send a message, Claude works and replies, and the turn ends. After each turn, the plugin computes a git diff of everything that changed in the working tree during the turn, including changes from Claude’s edit tools, Bash commands, and subagents, and sends it to a separate Claude review focused on security. The review runs in the background, so Claude’s reply is not delayed. If the review finds issues, Claude is re-prompted with the findings and addresses them as a follow-up. This catches issues a string match cannot, such as:- Authorization bypass
- Insecure direct object references
- Injection
- Server-side request forgery
- Weak cryptography
On each commit or push Claude makes
When Claude runsgit commit or git push through its Bash tool, the plugin runs a deeper agentic review of the change in the background. This review reads surrounding code, including callers, sanitizers, and related files, to decide whether a finding is real before reporting it. The extra context keeps false positives low on patterns that look dangerous in isolation but are safe in your codebase.
This layer fires only on commits and pushes Claude makes through its Bash tool. Commits you run from your own shell, including the ! shell escape inside a session, are not reviewed. Commit and push reviews are capped at 20 per rolling hour.
Review independence and limits
The plugin does not ask the same Claude instance that wrote the code to grade itself. The per-edit check is a deterministic string match with no model involved. The end-of-turn and commit reviews run as a separate Claude call with a fresh context and a security-focused prompt: the reviewer starts from the diff, has no investment in the original approach, and is instructed only to find problems. None of the layers block writes or commits. Findings reach the writing Claude as instructions, Claude addresses them in the conversation, and the review model can miss issues. Treat the plugin as one layer of defense in depth, not a complete security solution. See How this fits with other security tools.Add your own rules
The plugin has two extension points: a Markdown guidance file for the model-backed reviews, and a YAML or JSON patterns file for the per-edit string match. Both are additive. You can add checks but cannot disable built-in ones from these files.Add guidance for the model-backed reviews
Create.claude/claude-security-guidance.md in your project and describe your threat model and review checklist in plain language. The model-backed reviews load it as additional context alongside the built-in vulnerability checklist.
The following example is for a web service with role-gated admin routes and a customer-data logging policy:
.claude/claude-security-guidance.md
Add custom per-edit patterns
Create.claude/security-patterns.yaml to add regex or substring rules to the per-edit pattern check. These run as deterministic string matches alongside the built-in patterns:
.claude/security-patterns.yaml
| Field | Type | Description |
|---|---|---|
rule_name | string | Identifier shown in the warning |
reminder | string | Warning text appended to Claude’s context, capped at 1 KB |
regex | string | Python regex matched against the edited content |
substrings | list | Literal substrings; provide this or regex |
paths | list | Optional glob patterns; the rule applies only to matching files |
exclude_paths | list | Optional glob patterns to skip |
.claude/security-patterns.yml and .claude/security-patterns.json with the same schema. JSON works on any Python install. The YAML forms require PyYAML to be importable, which the plugin does not install for you. The plugin loads up to 50 custom rules and skips regexes that look prone to catastrophic backtracking.
Rule file lookup locations
The plugin looks forclaude-security-guidance.md and security-patterns.yaml in the same locations, independently of how the plugin was enabled:
| Scope | Path | Notes |
|---|---|---|
| User | ~/.claude/claude-security-guidance.md | Applies to every project on your machine |
| Project | .claude/claude-security-guidance.md | Checked in with the repository |
| Project local | .claude/claude-security-guidance.local.md | Gitignored, for personal overrides |
~/.claude/ through device management. The same paths apply to security-patterns.yaml.
Usage cost
The per-edit pattern check makes no model call and adds no cost. The end-of-turn and commit reviews each spend additional model usage that counts toward your usage like any other Claude request. The commit review is agentic and may take several model turns per commit. The increase scales with how often Claude edits files and commits in the session. Both model-backed reviews use Claude Opus 4.7 by default. SetSECURITY_REVIEW_MODEL to choose a different model for the end-of-turn review and SG_AGENTIC_MODEL for the commit review.
The plugin is available on all plans.
Disable or uninstall
To turn off individual layers while keeping the rest, set the matching environment variable:| Variable | Effect |
|---|---|
ENABLE_PATTERN_RULES=0 | Disable the per-edit pattern check |
ENABLE_STOP_REVIEW=0 | Disable the end-of-turn diff review |
ENABLE_COMMIT_REVIEW=0 | Disable the commit and push review |
ENABLE_CODE_SECURITY_REVIEW=0 | Disable all model-backed reviews at once |
SECURITY_GUIDANCE_DISABLE=1 | Disable the plugin entirely without uninstalling |
.claude/settings.json, disabling it from /plugin writes an override to your .claude/settings.local.json rather than editing the checked-in file, so the plugin stays off for you while teammates are unaffected. If it was enabled through managed settings, only an administrator can disable it.
How the plugin integrates with Claude Code
The plugin is built entirely on hooks, the mechanism for running your own code at specific points in Claude’s loop. It registers:| Hook event | Purpose |
|---|---|
SessionStart | Bootstrap the plugin’s Python environment |
UserPromptSubmit | Capture the working-tree baseline that the end-of-turn review diffs against |
PostToolUse on Edit, Write, and NotebookEdit | Per-edit pattern match |
Stop | End-of-turn diff review, run in the background |
PostToolUse on Bash, filtered to git commit and git push | Commit and push review, run in the background |
How this fits with other security tools
The plugin is one layer in a defense-in-depth approach. It catches issues earliest, while code is still in the editor, but it is not a guarantee and does not replace later checks. A typical stack:| Stage | Tool | What it covers |
|---|---|---|
| In session | Security guidance plugin | Common vulnerabilities in code Claude writes, fixed in the same session |
| On demand | /security-review | One-time security pass on the current branch, run when you ask |
| On pull request | Code Review, Team and Enterprise plans | Multi-agent correctness and security review with full codebase context |
| In CI | Your existing static analysis and dependency scanners | Language-specific rules, supply-chain checks, and policy enforcement the plugin does not attempt |
Related resources
To go deeper on the pieces this page touches:- Code Review: set up the PR-time multi-agent review
- Automate workflows with hooks: build your own checks at the same lifecycle points
- Discover and install plugins: browse other official plugins