reference Commands

opengrep ci

See also
opengrep scan, --audit-on, --suppress-errors, --subdir, --baseline-commit, --error, OPENGREP_PR_ID, OPENGREP_REPO_NAME
opengrep ci [FLAGS]

Runs the engine of opengrep scan, with defaults suited to continuous integration. The command takes no targets: it scans the current directory, or the directory given by --subdir, and is meant to run at the root of a git repository. When run elsewhere, it logs a warning and continues with the information it can determine.

The rules come from --config or OPENGREP_RULES, as for a scan. Without either, opengrep ci uses --config auto and downloads rules from the registry.

In addition to a scan, opengrep ci provides:

Exit status

StatusMeaning
0The scan completed without blocking findings.
1At least one blocking finding was reported.
otherThe statuses of opengrep scan, with --no-suppress-errors only; otherwise 0.

Flags

FlagSummary
--allow-rule-timeout-controlLet rules set their own time limits, which are otherwise ignored.
--audit-onReport blocking findings but exit with status 0 when the CI event has one of these names.
--baseline-commitReport only the findings that are not present in the given commit.
--configLoad rules from a file, a directory, a URL, a git repository or the registry.
--dataflow-tracesShow the path from source to sink in the findings of taint rules.
--debugLog the messages of --verbose and the diagnostics of the engine.
--developListed in Internal and debugging interfaces.
--disable-intrafileAnalyze every taint rule one function at a time, including rules that set taint_intrafile or taint_interfile.
--dynamic-timeoutScale the time limit of each rule with the size of the file.
--dynamic-timeout-max-multiplierThe largest factor by which --dynamic-timeout multiplies the timeout.
--dynamic-timeout-unit-kbThe file size, in KB, of one step of --dynamic-timeout.
--emacsPrint one line per finding, in the format of Emacs compilation buffers.
--emacs-outputWrite the findings in the Emacs format to a file as well.
--enable-interfileRun cross-file taint analysis for the rules that set the taint_interfile option.
--enable-nosemWhether nosem comments suppress findings; on by default.
--excludeSkip files and directories whose path matches a gitignore-style pattern.
--exclude-ruleSkip the rule with this id.
--files-with-matchesPrint only the paths of the files that have findings.
--force-colorStyle the output even when it does not go to a terminal.
--force-excludeApply --include and --exclude to files named on the command line as well.
--gitlab-sastPrint the findings as a GitLab SAST report.
--gitlab-sast-outputWrite the findings as a GitLab SAST report to a file as well.
--gitlab-secretsPrint the findings as a GitLab secret detection report.
--gitlab-secrets-outputWrite the findings as a GitLab secret detection report to a file as well.
--includeScan only the files whose path matches one of these patterns.
--inline-metavariablesReplace the metavariables in the metadata of a rule with the code they matched.
--interfile-dedup-byWhether a sink reached by several sources across files produces one finding or one per source.
--interfile-depthThe longest call chain the cross-file taint analysis follows.
--interfile-timeoutThe time a rule may spend on the cross-file taint analysis.
--jobsThe number of workers that run rules in parallel.
--jsonPrint the findings as a JSON document.
--json-outputWrite the findings as JSON to a file as well.
--junit-xmlPrint the findings as a JUnit XML report, one failed test per finding.
--junit-xml-outputWrite the findings as a JUnit XML report to a file as well.
--matching-explanationsAdd to the JSON output a record of how each part of a rule matched.
--max-chars-per-lineThe width at which lines of code are wrapped in the text output.
--max-lines-per-findingThe number of lines of code shown for a finding in the text output.
--max-log-list-entriesThe number of items above which a list in the logs is replaced by a note.
--max-match-per-fileThe number of matches in a file, across all rules, above which all its findings are dropped.
--max-memoryThe memory that the analysis of one file may use before it is abandoned.
--max-target-bytesSkip files larger than this size.
--opengrep-ignore-patternAn additional comment prefix that suppresses the findings on a line.
--optimizationsTurn the optimizations of the engine, such as the prefilter, on or off.
--outputWrite the output to a file instead of standard output.
--profileListed in Internal and debugging interfaces.
--quietPrint only the findings, and nothing on standard error.
--rewrite-rule-idsWhether the ids of rules from a subdirectory are prefixed with its path; on by default.
--sarifPrint the findings as a SARIF 2.1.0 document.
--sarif-outputWrite the findings as SARIF to a file as well, including suppressed findings.
--scan-unknown-extensionsScan a file named on the command line even when its extension belongs to no language.
--skinThe layout of the text output.
--subdirScan only this directory, with the CI metadata of the whole repository.
--suppress-errorsMake opengrep ci exit with status 0 on errors; on by default.
--taint-intrafileFollow taint through calls to functions in the same file, for every taint rule.
--textPrint the text output, the default format.
--text-outputWrite the text output to a file as well.
--timeReport the time the scan took, per rule and per file.
--timeoutThe time limit of a rule on a file, in seconds; 0 sets no limit.
--timeout-thresholdThe number of rules that may time out on a file before the file is skipped.
--use-git-ignoreWhether files ignored by git are skipped; on by default.
--verboseLog the progress of the run, at the info level.
--vimPrint one line per finding, in the format of Vim quickfix lists.
--vim-outputWrite the findings in the Vim quickfix format to a file as well.

Examples

A scan of a repository

rule.yaml
rules:  - id: find-eval    pattern: eval(...)    message: found eval    languages: [python]    severity: WARNING
app.py
eval(1)
Command and result
$ git init -q && git add . && git commit -qm init
$ opengrep ci -q --config rule.yaml
blocking · 1 finding

app.py

  warn  find-eval
  found eval

     1: eval(1)

blocking rules fired
  find-eval
$ opengrep ci --config rule.yaml > /dev/null 2>&1; echo "exit status: $?"
exit status: 1

The line naming the provider and the event, the counts and the closing summary go to standard error:

Command and result
$ opengrep ci --config rule.yaml 2>&1 >/dev/null | tail -3
CI scan completed successfully.
  Found 1 finding (1 blocking) from 1 rule.
  Has findings for blocking rules so exiting with code 1