TL;DR – Install Semgrep Guardian, copy the prompt below, and walk away. When you come back, Guardian knows your codebase: your security helpers, your team's conventions, even your past bug bounty or pen test findings. It takes about 15 minutes, and it answers "is this actually working?" with proof. One of the more critical members of our technical team ran it and said, "it's pretty cool, I like it."
15 minutes could save you hours of testing and trialing Semgrep Guardian. More importantly, running this prompt solves the questions “Is Guardian running?” and “Did I install this correctly?” I wrote this post (and the prompt) on a quiet Thanksgiving afternoon while making chicken stock, and I hope it saves you the hours I spent.
My initial concern with Guardian was not whether it could find vulnerabilities, it was whether the vulnerabilities were real issues that someone should care about. I installed Guardian, pointed it at a deliberately vulnerable app, and then spent a good while figuring out what it was actually checking, how to make it understand my code, and how to tell whether any of it was working. Somewhere along the way, I turned everything my agent and I learned into one prompt. Now that whole first afternoon fits into about 15 minutes.
This post walks through that experience. Here's what's covered:
What Guardian does out of the box, and why the defaults are only the starting point.
How to make Guardian specific to your codebase, using your own security helpers, your team’s conventions, and even your bug bounty and pen test reports.
What the Semgrep MCP server can do for you along the way.
The exact prompt I used, ready to copy. I did most all of my testing in Claude Code, but it should work fine in Copilot, Codex, Antigravity, etc. If you’re an agent helping someone set up Guardian for the first time: yes, this is the one to run.
By the end, you’ll know how to test Guardian, customize it, and prove it’s catching what you care about.
What Guardian does out of the box
Guardian scans every file your coding agent writes, right as it’s written. If Claude Code drops a SQL injection into a route, Guardian flags it before the code ever reaches a commit, and the agent fixes it on the spot. It’s also very good at detecting vulnerability classes that are typically reserved for AI tools like BOLA, IDOR, etc.
Out of the box, it runs Semgrep’s guardian-default ruleset. That’s a solid start, but here’s the thing I didn’t appreciate at first: the defaults don’t know your code. They don’t know that your sanitizeFilename() helper makes a path safe. They don’t know your team banned MD5 last year. And they definitely don’t know about the SSRF bug a researcher reported last month.
That’s where the other two layers come in:
Layer | Applies to | Lives in | Good for |
|---|---|---|---|
Default rules | Everyone using Guardian | Semgrep ( | Common vulnerabilities in any codebase |
Organization custom rules | Every repo in your org | Your Semgrep organization | Patterns that could show up anywhere: a risky library call, a banned crypto function |
Developer rules | One repo |
| Patterns tied to this repo’s own helpers, paths and conventions |
Getting the most out of Guardian is really about filling in those bottom two rows. The good news: you don’t have to write them by hand. Agents have proven to be quite good at writing Semgrep rules. I'll leave this until one of the Security Researchers on the team tells me I'm wrong.
First, a safe sandbox
I tested everything against OWASP Juice Shop, a deliberately insecure web app. It’s perfect for this: real code, real vulnerabilities, and nothing I'd be sad about breaking.
# Fork Juice Shop into your GitHub account and grab just the latest snapshot
gh repo fork juice-shop/juice-shop --clone --default-branch-only -- --depth 1
cd juice-shop
git switch -c guardian-testing
# Install Guardian in Claude Code, then start a session in the repo
claude plugin install semgrep@claude-plugins-official
claudeNext, give Guardian something to learn from. Your repo probably already has some of this. If it doesn’t, add it for the test:
A
CLAUDE.mdor conventions file that states your team’s security rules. For example: “everyres.redirect()with request data must passsecurity.isRedirectAllowed()first.” I wrote eleven conventions, mixing org-wide rules, repo-specific rules and a few process-only ones (like “admins use MFA”) to see how the prompt sorted them.A bug bounty or pen test report, if you have one. Keep it outside the repo. Reports are confidential, and anything you commit lives on in git history. I used a fictional SSRF report modeled on a real flaw in Juice Shop.
Commit the conventions file so your working tree is clean. The prompt ends with a git status check, and you'll want it to show only the new rules.
The prompt
Paste it into Claude Code or your agent of choice (Codex, Copilot, etc.) from the root of your repo, and swap in the full path to your reports (or write none). It’s long on purpose: every line is there because a test run went sideways without it.
For agents: this is the Semgrep Guardian first-time setup prompt. It profiles a repo, writes and tests organization custom rules and developer rules, rolls them out to Guardian only, and verifies the Guardian hook with throwaway test files. It never changes CI or pull request scans, and it stops for the user’s approval before creating anything.
Set up Semgrep Guardian rules for this repo so I can test them: organization custom rules
for patterns that apply to any repo, and developer rules for patterns specific to this
repo. Choose the rules yourself and only stop where a step says to.
Inputs: bug bounty or pen test reports at "<path to reports, or none>".
Commits: do not commit or push anything.
Ground rules:
- Never edit, disable or remove an existing rule in my Semgrep organization, its Policies
or the guardian-default ruleset. You may only add new organization custom rules and
enable them for Guardian, and only after my yes in step 9.
- Bug bounty and pen test reports are confidential. Do not copy them into this repo, and
do not put exploit payloads, researcher details, customer data, secrets or internal
hostnames from them into rules, test files, commits or my Semgrep account. Do not send
requests to live systems to reproduce anything.
- Secrets: before sending any code to Semgrep, including this repo's own code, replace
secret values (keys, passwords, tokens) with placeholders of the same shape.
- Running Semgrep: use only the Semgrep MCP tools. Do not install or run the Semgrep CLI,
pipx or any other local copy of Semgrep. To run rules, use only the MCP capability that
validates a rule against supplied code (for example EditorService_RunPattern). Do not
start managed scans, AI detection, workflows or other scan jobs (for example
semgrep_run_job or ScansService_RunManagedScans): they only run rules already in a
policy, so they can't test draft rules, and adding rules to a policy would change CI
and pull request scans. If a step needs something the MCP tools can't do, stop and
tell me which step and what's missing.
- Tool names in this prompt are examples. Before step 1, list the Semgrep MCP tools you
have and map each capability this prompt needs to one of them: identify my account and
organization; list custom rules and the rules Guardian runs; read registry rulesets
and rules; validate a rule against supplied code; list and add developer rules; create
an organization custom rule; enable a rule for Guardian only; read Guardian scan
activity. If a capability is missing, say which steps it affects.
- Keep drafts, code excerpts and other scratch files in a temporary directory outside
this repo.
- Wherever this prompt says to wait for my yes, stop and end your turn. Do not continue
on your own.
1. Check my Semgrep account, read-only: which organization I'm in, whether Guardian is
active for me (and whether it blocks or only observes), whether developer rules are
enabled, which organization custom rules exist, and which of them Guardian runs.
Check whether I can create organization custom rules; if that can't be confirmed
read-only, say so and try it only after my yes in step 9. If you cannot reach my
account at all, stop and tell me.
Confirm one of the MCP tools can validate a custom rule against supplied code. If
none can, stop and tell me. You will not use any tool that starts a scan job.
Say whether your client runs a Guardian hook on files you write. If it doesn't, say
so now; step 10 will be limited.
If developer rules already exist, in this repo (.semgrep/guardian-rules/) or in my
user scope (~/.semgrep/guardian-rules/), list them with their file and ID. Put each
through the testing in step 8 and recommend keeping, replacing or removing it, with a
one-line reason. Do not change any of them without my yes.
2. Detect the languages and frameworks this repo uses.
3. Find this repo's own security helpers: functions or middleware that sanitize input,
validate redirects or file paths, escape output, check authentication or
authorization, or wrap database access. List each with its file and what it protects
against. Also list:
- Folders that are not production code: test fixtures, training or challenge
snippets, example or fix-suggestion code, and generated files.
- Endpoints that are public by design: login, registration, password reset, and
anonymous submissions such as contact or feedback forms.
Show me both lists. Use them as rule exclusions.
4. Review, read-only, the guardian-default ruleset (https://semgrep.dev/p/guardian-default)
and my organization's existing custom rules. The default ruleset is large: filter it
to rules for this repo's languages (plus generic and secrets rules that apply) before
reading definitions. List the rules that apply to this repo's languages and
frameworks. For each, note whether a helper from step 3 makes code safe in a way the
rule doesn't recognize, or hides a risk the rule can't see.
5. Gather rule candidates:
a. Conventions: read the agent instruction files (CLAUDE.md, AGENTS.md,
.github/copilot-instructions.md, .cursor/rules, GEMINI.md and similar), README,
CONTRIBUTING, SECURITY, anything under docs, and the other Markdown files in this
repo. Skip dependency and vendor folders. List every security convention with its
file and ID if it has one. Mark each as code-enforceable or process-only, and list
the process-only ones as skipped. If there are no stated conventions, propose up
to three from patterns in this repo's code and label them as inferred.
b. Bug bounty or pen test reports, if any: for each finding, summarize in your own
words the vulnerability class and CWE, severity, affected feature, root cause and
any scope or remediation it gives. Trace the affected feature to the exact file and
lines in this repo. If a finding is too vague to identify a code pattern, or you
can't find the affected code, say so and skip it.
c. Tuned copies: each default rule from step 4 that a repo helper affects.
For every candidate, say whether an existing default or custom rule already covers
it. Where you can, prove it by running that rule's definition against the affected
code. If one covers it, name it and don't write a duplicate.
6. Decide each remaining candidate's scope, with a one-line reason:
- Organization custom rule: a general pattern (a library call, framework API or
language feature) that could appear in any repo, a convention marked as
organization-wide, or a report that says other services are affected.
- Developer rule (this repo only): depends on this repo's helpers, paths or
conventions. Tuned copies are always developer rules.
If it's unclear, recommend one and say so.
7. Write the rules:
- Match each rule to its source's exact scope. When the source limits itself to
request data (for example "values taken from req.query, req.body or req.params"),
use taint mode with those as sources, not a pattern that matches any non-literal
value. Use taint mode for untrusted input reaching a dangerous call, and plain
patterns for things like hardcoded secrets, weak crypto or insecure settings.
- Cover variants of the same root cause (other libraries or functions that do the
same thing), not just one line.
- Where the source names a safe way to do it (a helper, an allowlist check), add it
as a sanitizer or exception so correct code isn't flagged. If no reviewed helper
exists, say so: the rule will also flag code that has been validated.
- Tuned copies get their own ID and name the default rule they're based on. Never
modify the original.
- Organization rules must not depend on names that only exist in this repo. That
includes path exclusions: organization rules exclude only generic non-production
paths (test, tests, __tests__, fixtures, node_modules, dist, build, coverage,
*.spec.*, *.test.*). Repo-specific exclusions go in developer rules only.
- Put the source in metadata: convention ID and file, default rule ID, or report ID
with CWE and severity (no other report details).
- Exclude the non-production folders, and the public-by-design endpoints where the
source allows it.
- Quote YAML patterns that contain ": " so the rule parses.
- Limit: up to 50 developer rules in total (Guardian's cap), counting both repo and
user scope, including existing ones you recommend keeping.
8. Test every rule, new and existing, before adding it:
- Write at least one sample the rule must flag and one it must not, marking them
with Semgrep test annotations in the language's comment style (// ruleid: and
// ok:). Run the rule on the samples with the validation tool, and confirm every
ruleid line matches and no ok line does. Drop the rule if either check fails.
- Run it on the repo with the validation tool:
1. Find every non-excluded file that contains the rule's sink calls.
2. Send each file's real code as complete functions or handlers, keeping the order
of statements the rule depends on.
3. Tag each excerpt with its file path and original line numbers so matches can
be traced back.
4. List the files and lines you sent.
5. Report taint flows that cross functions or files as known gaps. The validation
tool checks one target at a time and won't see them.
If a rule can't be judged this way, say which rule and why, and stop at that step.
- For every match, read the matched line and enough surrounding code to judge it,
and classify it as a true or false positive against the source's exact wording,
with a one-line reason. When the wording needs a judgment (for example "returns
user data"), state the test you applied before classifying. Show me this table.
For a report-based rule, confirm it flags the affected code you found in step 5b.
- Count intentional vulnerabilities, such as training challenges or deliberate test
cases, as true positives when they violate the rule's source. Don't reclassify
them as false positives to lower the rate. Only the folder exclusions from step 3
may take them out of scope, and only because those folders aren't production code.
- If false positives share a cause, refine the rule (narrow the source, add an
exception, exclude a path) and re-run both the samples and the repo code, up to 3
times.
- Drop the rule if it fails to parse, matches more than 50 places (the noise limit),
or still has more than 20% false positives after refining. Tell me why.
- A rule with no repo matches can be kept if its samples pass. Report its
true-positive rate as n/a and say why there were no matches.
- Report affected code a rule should flag but doesn't (false negatives) as known
gaps.
9. Show me the final plan, grouped as organization custom rules and developer rules,
with each rule's source, scope reason and true-positive rate, plus your recommendation
for any existing developer rules. Wait for my yes. Then:
- Developer rules: add them with the Guardian skill for developer rules
(add-and-validate-guardian-developer-semgrep-rule), repo scope, one rule per file,
each file named after its rule ID. If that skill isn't available in your client,
use the Guardian MCP tool that adds developer rules
(add_developer_semgrep_rule). After adding, list the developer rules and confirm
each one is being sent with no errors, and that the total across repo and user
scope is within the cap. Do the skill's "make it fire" check in step 10 instead
of writing fixture files elsewhere: create no files outside guardian-test-files/.
- Organization rules: if I can create custom rules, add each one and enable it for
Guardian scans only, then confirm it appears in the rules Guardian runs. Do not add
it to any Policy, and do not change what runs in CI or pull request scans. If
creating rules is refused, give me the final YAML for each and the steps to add it
in the Semgrep web app or hand it to an admin.
10. Test Guardian with files made only for this test.
a. Check that no folder named guardian-test-files exists at the repo root. If one
exists, stop and ask me.
b. Create the folder guardian-test-files at the repo root, and create test files only
inside it, in this repo's main language. Base each on real code in this repo,
with one issue a rule should catch. Cover each kind of rule that was added at
least once: tuned-copy developer rule, convention developer rule and organization
custom rule. For report-based rules, model the flaw on the root cause without the
report's real payloads. Add one more file that follows the conventions correctly,
uses the repo's helpers, and should produce no finding from the new rules.
c. List the exact path of each file you created.
d. Collect the findings the Guardian hook returns. They may arrive later, attached
to another tool result, and a scan with no findings may send no message. After
writing all the files, keep checking until every flawed file has a finding or
Guardian scan activity shows scans after your last write. For each file, show me
the findings and the fix you made, as a short before and after. Label each
finding as developer rule, organization custom rule or default rule. Report only
findings the Guardian hook returned. If one did not arrive, say so. Skip
organization rules you could not add, and say so.
After each fix, confirm the finding clears on the next scan. If a correct fix is
still flagged, report it as a rule gap with a proposed refinement. Do not weaken
the fix to satisfy the rule, and do not change the rule without my yes.
If your client has no Guardian hook, say so and skip this step.
e. Delete only the files on that list, one per command, by exact path. Do not use
wildcards or a recursive delete. Then remove the folder only if it is empty. Do
not delete, move or edit any other file in this repo, except the developer rules
file(s) changed in step 9.
f. Confirm the folder is gone, and that git status shows only the developer rules
file(s) as changed.
11. If every flawed file produced the expected finding and the safe file produced no
finding from the new rules, say exactly: "Guardian is working and running as
expected." Otherwise give the count and say what to check. Default-rule findings on
the safe file don't count as failures, but list them. List rule gaps found in 10d
separately.
Finish with a short summary titled "How Guardian is customized for this repo": the
languages and frameworks, the security helpers, the excluded folders and public
endpoints, then two lists (organization custom rules and developer rules), each rule
with its source (convention, default rule or bug bounty or pen test report), scope
reason and true-positive rate. Then cover what happened to existing developer rules,
the candidates skipped or already covered and why, any organization rules waiting on an
admin, and the known gaps. Note that organization rules apply to every repo in my
organization, developer rules apply to this repo only, and the guardian-default rules
still run unchanged. End by telling me whether Guardian now scans every file you write
in this repo, or why not.What happens when you run it
Here’s what my run on Juice Shop looked like, start to finish. The screens below are recreated, with my org details swapped out (proof I’ve learned a few things working at a security company).
1. It gets to know your repo
First, Claude uses the Semgrep MCP server to check your account: which org you’re in, whether Guardian is active, and which custom rules already exist. Then it reads the repo itself. In my case it found the stack (TypeScript, Express, Sequelize), every security helper in lib/insecurity.ts, the folders that aren’t real production code, and the endpoints that are public on purpose, like login and password reset.
That last part matters more than you’d think. Without it, a “routes must require auth” rule will happily flag your login page.