Skip to content
SkillModel-led1,674 tokens in use

semgrep-rule-creator

A strict, test-first workflow for writing custom Semgrep rules: read the docs, write tests, dump the AST, build the rule, pass semgrep --test, then optimize.

8,320 stars on the repository CC-BY-SA-4.0trailofbits/skills · plugins/semgrep-rule-creator/skills/semgrep-rule-creator
/plugin marketplace add trailofbits/skills
View source

Install command as written in the repository's README

Skill label

measured from its files

What installing semgrep-rule-creator costs

36tokens idle
1,674tokens in use
5,014tokens, up to

Idle is what sits in context while the skill is installed. In use is its instructions, loaded when it runs. Up to adds the files its instructions link. Counts are approximate, made offline with cl100k_base.

Model dependence Model-led

Script-ledMixedModel-led

Mostly instructions, so how well it works depends on the model that follows them.

This describes the skill's structure, how much of it is scripts. It does not say how well it works.

Touches

shelldeclared and detectednetworkdeclaredwrites filesdeclared

Declared tags come from the skill's frontmatter; detected ones from its scripts, its code blocks and the commands it names in inline code. This is detected, not audited.

How it scores

Quality

How well the skill is written, counted from its own files: its frontmatter, its steps, examples, stated output and constraints, its size and whether every file it ships is one it names.How we score it →
Excellent
  • Frontmatter12/15
  • Structure25/25
  • Examples15/15
  • Output15/15
  • Size10/15
  • Resources10/15

Security

Starts at 100 and loses points for each thing in the skill's files that a reader should look at first.How we score it →
Excellent
  • Runs shell commands−2

    does this on the machine, as the frontmatter declares

    SKILL.md, line 67

Repository health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
Good
  • Development activity100
  • Maintenance52
  • Community64
  • Maturity32
  • Momentum40

semgrep-rule-creator guides an agent through writing a custom Semgrep rule for a security vulnerability, bug pattern or coding standard. It favors taint mode for data flow issues and pattern matching for simple syntax checks, and it will not accept a rule that lacks tests.

The output is a directory named after the rule id with exactly two files: the YAML rule and a test file annotated with ruleid and ok markers. Every test must pass before the rule is simplified.

What You Get

  • A rule-id directory holding one Semgrep YAML rule and one annotated test file
  • Tests that cover vulnerable cases, safe cases, edge cases, sanitized input and nested code
  • A rule that passes semgrep —test with no missed or incorrect lines
  • A final message check that confirms every metavariable in the message interpolates

Common Use Cases

  • Detecting an injection bug with a taint mode rule from a source to a sink
  • Enforcing a coding standard across a codebase with a simple pattern rule
  • Turning a bug found in an audit into a reusable rule with tests

What Makes It Unique

The workflow is strict: tests come first, a hundred percent of them must pass, and generic or multi-rule files are forbidden. It also has the agent dump the AST before writing patterns so they match how Semgrep parses the code, and it puts a re-test step after every simplification. Running existing rulesets is left to the static-analysis skill.

Under The Hood

The skill reads two reference files for the command list and the step-by-step workflow. It tells the agent to fetch seven Semgrep and Trail of Bits documentation pages from raw.githubusercontent.com with the web fetch tool before writing any rule, so it reaches the network. The agent runs the semgrep command line tool in a shell for validation, tests, AST dumps and dataflow traces, and writes the rule and test files to disk in a new rule directory. It uses no bundled scripts.

Join founders building with open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on SubstackJoin 750+ subscribers