Skip to content
Skillpedia
Security8.0k Β· #12709

semgrep

What it does

This skill runs Semgrep, a code scanning tool, with rule sets chosen for your languages. It is for developers who want a quick, broad security check of their code.

When to use it

  • βœ“When you want a fast security scan of a project in several languages.
  • βœ“When you want to see the exact rules that will run before any scan starts.
  • βœ“When you need a single combined report of findings in a standard format.

Skill link

https://github.com/trailofbits/skills/blob/main/plugins/static-analysis/skills/semgrep/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/trailofbits/skills/blob/main/plugins/static-analysis/skills/semgrep/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œI want to scan my project for security issues with Semgrep, and I want to see the plan before it runs.”

5 new skills a week. 1 minute to read.

How it works

The agent detects the languages in your project, proposes rule sets, and waits for your approval. Then it runs each approved rule set and merges the output into one report. It also says which rule sets did not run.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Semgrep Security Scan

Run a Semgrep scan with automatic language detection, parallel execution, and merged SARIF output.

Essential Principles

  1. Always use --metrics=off β€” Semgrep sends telemetry by default; --config auto also phones home. Every semgrep command must include --metrics=off to prevent data leakage during security audits.
  2. User must approve the scan plan (Step 3 is a hard gate) β€” The original "scan this codebase" request is NOT approval. Present exact rulesets, target, engine, and mode; wait for explicit "yes"/"proceed" before spawning scanners.
  3. Third-party rulesets are required, not optional β€” Trail of Bits, 0xdea, and Decurity rules catch vulnerabilities absent from the official registry. Include them whenever the detected language matches.
  4. scripts/run-scans.sh generates the commands; do not write them yourself β€” it builds every semgrep line from the approved list. That is what makes --metrics=off, the --include scoping rule, and the parallel dispatch properties of the code rather than instructions. Give it the approved rulesets and let it run.
  5. Always check for Semgrep Pro before scanning β€” Pro enables cross-file taint tracking and catches ~250% more true positives. Skipping the check means silently missing critical inter-file vulnerabilities.
  6. Report what did not run β€” scans.json carries failed and skipped alongside scans. A ruleset whose repo would not clone, or whose scan exited non-zero, must appear in the report. A partial scan presented as a complete one is worse than no scan.

When to Use

  • Security audit of a codebase
  • Finding vulnerabilities before code review
  • Scanning for known bug patterns
  • First-pass static analysis

When NOT to Use

  • Binary analysis β†’ Use binary analysis tools
  • Already have Semgrep CI configured β†’ Use existing pipeline
  • Need cross-file analysis but no Pro license β†’ Consider CodeQL as alternative
  • Creating custom Semgrep rules β†’ Use semgrep-rule-creator skill
  • Porting existing rules to other languages β†’ Use semgrep-rule-variant-creator skill

Output Directory

All scan results, SARIF files, and temporary data are stored in a single output directory.

  • If the user specifies an output directory in their prompt, use it as OUTPUT_DIR.
  • If not specified, default to ./static_analysis_semgrep_1. If that already exists, increment to _2, _3, etc.

In both cases, always create the directory with mkdir -p before writing any files.

# Resolve output directory
if [ -n "$USER_SPECIFIED_DIR" ]; then
  OUTPUT_DIR="$USER_SPECIFIED_DIR"
else
  BASE="static_analysis_semgrep"
  N=1
  while [ -e "${BASE}_${N}" ]; do
    N=$((N + 1))
  done
  OUTPUT_DIR="${BASE}_${N}"
fi
mkdir -p "$OUTPUT_DIR/raw" "$OUTPUT_DIR/results"

The output directory is resolved once at the start of Step 1 and used throughout all subsequent steps.

$OUTPUT_DIR/
β”œβ”€β”€ rulesets.json                # The approved plan (Step 3), read by run-scans.sh (Step 4)
β”œβ”€β”€ scans.json                   # What ran, failed, skipped, and covered nothing (Step 4)
β”œβ”€β”€ raw/                         # Per-scan raw output (unfiltered)
β”‚   β”œβ”€β”€ python-python.json        # <language>-<ruleset> for language-scoped rules
β”‚   β”œβ”€β”€ python-python.sarif
β”‚   β”œβ”€β”€ python-django.json
β”‚   β”œβ”€β”€ python-django.sarif
β”‚   β”œβ”€β”€ all-security-audit.json   # all-<ruleset> for cross-language rules, run once
β”‚   β”œβ”€β”€ all-security-audit.sarif
β”‚   └── ...
└── results/                     # Final merged output
    └── results.sarif

Prerequisites

Required: Semgrep CLI (semgrep --version). If not installed, see Semgrep installation docs.

Optional: Semgrep Pro β€” enables cross-file taint tracking, inter-procedural analysis, and additional languages (Apex, C#, Elixir). Check with:

# --metrics=off because Principle 1 has no exceptions, and this is the first semgrep command
# of a run. stderr is kept because "OSS only" has several causes (logged out, no subscription,
# registry blocked) and the run downgrades silently for all of them.
if PRO_ERR=$(semgrep --pro --validate --metrics=off --config p/default 2>&1); then
  echo "Pro available"
else
  echo "OSS only"
  echo "  reason: $(printf '%s' "$PRO_ERR" | tail -n 3)"
fi

Limitations: OSS mode cannot track data flow across files. Pro mode uses -j 1 for cross-file analysis (slower per ruleset, but parallel rulesets compens

FAQ

Will it run without asking me?

No. The skill requires your clear approval of the scan plan before it starts.

Does it need a paid account?

The skill checks whether Semgrep Pro is available, since Pro finds more cross-file issues. It can run without it.

Does Semgrep send data out?

The skill turns off Semgrep's telemetry on every command to avoid sending data.

Details

Original description by the author

Runs a Semgrep security scan over a codebase: detects languages, selects rulesets, presents the plan for explicit approval, then runs every approved ruleset through scripts/run-scans.sh, which batches the semgrep processes and writes scans.json, and merges the output to SARIF. Supports two scan modes, "run all" for full ruleset coverage and "important only" for security findings at medium-to-high confidence and impact. Uses Semgrep Pro for cross-file taint analysis when it is available. Use when asked to scan code for vulnerabilities, run a security audit with Semgrep, find bugs, or perform st

repo: trailofbits/skills

Popularity

GitHub stars
8.0k
Ranking position
#12709
License
CC-BY-SA-4.0
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills