semgrep-rule-creator — Claude Code skill: write static analysis rules
A skill that walks you through creating custom Semgrep rules to detect security vulnerabilities and code patterns in your projects. Use it when you need static analysis tailored to your codebase.
npx skills add trailofbits/skills --skill semgrep-rule-creator -a claude-codeWhat semgrep-rule-creator does
semgrep-rule-creator guides the full Semgrep rule-writing workflow: analyze the problem, write tests first, study the AST structure, create the rule, and iterate until all tests pass using semgrep --test. It requires Semgrep to be installed on your system.
Two core approaches: taint mode for tracking how untrusted input flows to dangerous sinks (more accurate, fewer false positives for injection bugs), and pattern matching for syntactic rules. The skill prioritizes taint mode but lets you switch strategies if one isn't working. Output structure is strict: one folder per rule, containing a YAML file with the rule and a test file annotated with # ruleid: and # ok: markers.
The skill blocks common mistakes: overly broad patterns that match everything, rules without tests on safe cases, skipping AST analysis, optimizing before the rule works. Before writing any rule, it requires fetching Semgrep documentation—seven links covering syntax, testing, and taint analysis.
What it helps with
- Detect injection vulnerabilities specific to your tech stack
- Automate checks for internal coding standards and conventions
- Track dangerous data flows from untrusted sources to unsafe sinks
- Validate rules on test cases without false positives
- Extend built-in Semgrep rulesets with domain-specific logic
Example prompts for the agent
- Write a Semgrep rule to find `eval()` calls with user input
- Create a taint mode rule that catches SQL injection in Django
- Write a rule to detect use of weak encryption algorithms
How to install semgrep-rule-creator
1Skills CLI (Vercel)
npx skills add trailofbits/skills --skill semgrep-rule-creator -a claude-code2Manually: put the files in place
~/.claude/skills/semgrep-rule-creator/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/semgrep-rule-creator/
1Skills CLI (Vercel)
npx skills add trailofbits/skills --skill semgrep-rule-creator -a codex2Manually: put the files in place
.agents/skills/semgrep-rule-creator/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add trailofbits/skills --skill semgrep-rule-creator -a cursor2Manually: put the files in place
.cursor/skills/semgrep-rule-creator/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install trailofbits/skills semgrep-rule-creator2Manually: put the files in place
.github/skills/semgrep-rule-creator/SKILL.md1Skills CLI (Vercel)
npx skills add trailofbits/skills --skill semgrep-rule-creator -a gemini-cli2Platform CLI
gemini skills install https://github.com/trailofbits/skills --path plugins/semgrep-rule-creator/skills/semgrep-rule-creatorManually: put the files in place
.devin/skills/semgrep-rule-creator/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add trailofbits/skills --skill semgrep-rule-creator -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set35
The whole set →Similar
Questions about semgrep-rule-creator
How do I install semgrep-rule-creator in Claude Code?
Run npx skills add trailofbits/skills --skill semgrep-rule-creator -a claude-code in your terminal, then open ~/.claude/skills/semgrep-rule-creator/SKILL.md.
What does semgrep-rule-creator do?
It guides you through the entire Semgrep rule creation process: analyzing the problem, writing tests first, validating with semgrep --test, and ensuring your rule is specific and free of false positives. The skill enforces a strict workflow to keep rules focused and well-tested.
When should I use taint mode versus pattern matching?
Use taint mode for injection vulnerabilities—it tracks data flow from source to sink and catches only real issues. Use pattern matching for simple syntactic patterns. Taint mode typically has fewer false positives but requires understanding how data propagates in your code. The skill starts with taint mode but lets you switch if needed.