/semgrep:recommend-guardian-policy-rulesfrom Semgrep Guardian
Recommends Semgrep rules to add to an organization's Guardian policy by analyzing existing findings and custom rules, then enables selected rules via the Semgrep MCP.
Ships in Semgrep Guardian. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guardian's policy is the set of Semgrep rules every scan runs. Most
organizations run the guardian-default set and nothing else, so Guardian
misses what their CI scans already know the code gets wrong. This skill closes
that gap for one repository, using rules with a track record in it:
Every call goes through the Semgrep MCP tools Guardian forwards from Semgrep's hosted server, so they act as the user who logged in to Guardian, with that user's permissions.
The policy covers the whole organization. Guardian has no per-repository scoping yet. A rule picked "for" this repo also runs on every write in every other repo in the org. Say that before anything gets written.
You need these hosted tools. MCP tools can be deferred, so search for any that are not in your list before deciding they are missing:
semgrep_accountRuleScopeService_GetResolvedSurfaceRuleIds, RuleScopeService_SetRuleSurfaceScopesIssuesService_ListIssuesRegistry_get_registry_rule, Registry_get_organization_rulesIf none of them exist, call status. The hosted server lists them only for an
org with MCP access, and only once Guardian is logged in. Pass on what status
says, then stop.
Call semgrep_account. Each org's id is its deploymentId, used by every
call below. If it lists more than one org, ask which one.
Call RuleScopeService_GetResolvedSurfaceRuleIds:
path: { deploymentId: "<id>" }
query: { surface: "SCAN_SURFACE_GUARDIAN", ruleProductType: "PRE_SCAN_CONFIG_TYPE_SAST" }
ruleIds holds the rules Guardian runs now: the default set plus this org's changes.defaultRuleIds holds the default set alone. Rules in ruleIds but not here were added by the org.
Rules here but not in ruleIds were turned off.Both lists hold rule hashids (short strings like gxU149), not registry
paths. Keep ruleIds as a set; step 4 drops candidates that are already in it.
Tell the user how many rules Guardian runs, and how many of those the org added
itself.
A permission error here means the user is not an admin of the org. Changing the policy needs the same permission, so stop and say so.
Pick the repository. Default to the one you are working in: take its name from
git remote get-url origin, in owner/repo form. Confirm it with the user if
there is any doubt.
A rule that has already found real problems in this repo is the best candidate
there is. Call IssuesService_ListIssues twice, both with:
path: { deploymentId: "<id>" }
query: { fieldMask: "issues.issue.rulePath,issues.issue.severity,issues.issue.confidence" }
body: {
issueTypes: ["ISSUE_TYPE_SAST"],
limit: 100,
filter: { repositoryNames: ["<owner/repo>"], relativeSince: "RELATIVE_SINCE_ONE_YEAR", ... }
}
aggregateIssueStates: ["AGGREGATE_ISSUE_STATE_OPEN", "AGGREGATE_ISSUE_STATE_FIXING", "AGGREGATE_ISSUE_STATE_FIXED"] to the
filter. Fixed issues count too: the bug was real, and Guardian would have
stopped it before it landed.aggregateIssueStates: ["AGGREGATE_ISSUE_STATE_IGNORED_APP"]
and triageReasons: ["FINDING_TRIAGE_REASON_FALSE_POSITIVE"] to the filter.Follow cursor on each until it runs out or you have seen about 1,000 issues,
which is enough to rank by. Count each rulePath in both.
If the repo has no issues, say so. Then offer to look across the org instead:
drop repositoryNames, or filter by repositoryTags or teamNames.
Custom rules that have fired in the repo are already among the findings above,
with origin custom. To find custom rules that have not fired yet, call
Registry_get_organization_rules with path: { deployment_id: "<id>" } and
query: { fieldMask: "rules.path,rules.rule_type,rules.meta.rule.rule_id" }.
Always pass the mask: a large org has thousands of rules, and the list is
long even without their definitions. If it comes back with more than about 200
rules, do not rank them all. Keep only paths whose names point at the repo's
languages or frameworks, or skip this source and say so. Rank custom rules with
no findings below rules that have found something.
If the user names a ruleset or technology, list its rules with
Registry_list_registry_rules, passing starts_with (for example python.django.)
and deployment_id. Rules with no findings behind them are guesses. Rank them
below the rest, and say why each was picked.
Look up each candidate path with Registry_get_registry_rule:
path: { hashid_or_path: "<rulePath>" }
query: { deployment_id: "<id>",
fieldMask: "path,rule_type,meta.rule.rule_id,meta.rule.origin,definition.rules.severity,definition.rules.languages,definition.rules.mode,definition.rules.options,definition.rules.metadata.confidence,definition.rules.metadata.subcategory" }
meta.rule.rule_id is the hashid that the policy calls take. meta.rule.origin
is community, pro_rules, or custom. Org rules need the deployment_id to
resolve. Look up the top 30 or so by true-positive count, not every path you saw.
Drop a candidate when:
ruleIds. Guardian already runs it.rule_type is not sast. Guardian's code policy takes only code rules.languages appear in the repo. generic and regex count as matching everything.Rank what is left, best first:
metadata.confidence HIGH, then MEDIUM. Rank LOW and audit rules
(subcategory: [audit]) last.CRITICAL/ERROR and HIGH, then WARNING/MEDIUMTwo more things to note against a rule, without dropping it:
options.interfile: true: Guardian scans one written file at a time, so
the rule fires only when source and sink are in the same file.Show the ranked list as a table:
| # | rule path | origin | lang | sev / conf | TP | FP | note |
|---|
Keep the hashid of each row to yourself; the user picks by number or path. Under the table, say again that whatever they pick runs across the whole org.
Ask which to add: "all", a list of numbers, or none. AskUserQuestion takes at
most four options, so use it only when there are four or fewer candidates. For
a longer list, ask in plain text and wait for the reply.
Before writing, repeat the exact rules that will be added and the org they go to, and get a yes. The change shows up in the org's audit log under the user's name.
Call RuleScopeService_SetRuleSurfaceScopes, with at most 100 rules per call:
path: { deploymentId: "<id>" }
body: {
surface: "SCAN_SURFACE_GUARDIAN",
ruleProductType: "PRE_SCAN_CONFIG_TYPE_SAST",
rules: [ { ruleId: "<hashid>", enabled: true }, ... ]
}
Send only the rules being changed. The call touches exactly the rules it is
given, and leaves every other rule in the policy alone. Never send all of
ruleIds back.
The response's ruleIds is the full set Guardian runs afterwards. Check that every hashid you
sent is in it. An error naming a rule (wrong product type, bad hashid) leaves
the whole batch unapplied: drop that rule and send the rest again.
Tell the user:
enabled: false for the same hashids.
For a rule outside the default set, that removes it again; for a default rule, it turns the rule off.Offer to prove one fires. Pick a rule with a true positive in this repo. Tell the user the write is meant to be blocked. Then write a small new file with a real source extension in the working directory that reproduces the pattern. Guardian should block it with the rule's message. Delete the file afterwards.
enabled: false, choosing
candidates from ruleIds. Good reasons to turn one off are rules that mostly
produce false positives here, or rules for languages the org does not use.RuleScopeService_ListRuleSurfaceScopes lists the org's stored changes. They
can differ from what Guardian runs, because default rules and packs are worked out
separately, so treat GetResolvedSurfaceRuleIds as the source of truth.add-and-validate-guardian-developer-semgrep-rule skill.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub semgrep/guardian --plugin semgrep5 skills in this plugin
/add-and-validate-guardian-developer-semgrep-rulewrite a custom semgrep rule with the user, add it to guardian in either user or repo scope, and prove it fires by writing a file that should trip it. use when someone wants guardian to catch something it currently misses, asks to write or add a semgrep rule, or wants a project convention enforced on the code claude writes./install-mfwInstall the mfw (Semgrep Malware Firewall) CLI via the curl|sh installer and walk the user through setup — trust store, PATH shims, shell integration, and the background daemon — asking questions at real decision points. Detects when the user's shell rc files are *managed* (symlinked into nix / home-manager / chezmoi / GNU stow / a dotfiles git repo) and, instead of clobbering them, adds mfw's source line to the right source-of-truth. Use when the user wants to install, set up, or onboard mfw on this machine./reconnectOther plugins' skills for the same job