Skip to content
Latchkey

ripgrep (rg): Fast Recursive Search in CI

ripgrep (rg) recursively searches the current directory for a regex pattern, skipping files listed in .gitignore by default.

rg is the workhorse for "does this string appear anywhere" checks in pipelines. It is fast, but its exit-code behavior surprises people: no match is exit 1, which fails a CI step.

What it does

ripgrep searches the current directory tree for lines matching a regular expression. It honors .gitignore, .ignore, and hidden-file rules by default, which is why it is faster and quieter than grep -r. Output is colorized and grouped by file.

Common usage

Terminal
rg "TODO"                       # search cwd recursively
rg "func main" src/             # restrict to a path
rg -i "error" logs/             # case-insensitive
rg -w "id"                      # whole word only
rg -F "a.b.c"                   # fixed string, no regex

Options

FlagWhat it does
-i / -SCase-insensitive / smart-case (insensitive unless pattern has uppercase)
-wMatch whole words only
-FTreat the pattern as a fixed string, not a regex
-vInvert: show lines that do NOT match
-n / -NShow / hide line numbers
-C <n>Show n lines of context around each match
--hiddenAlso search hidden files and directories
-u / -uu / -uuuReduce filtering (ignore .gitignore, then hidden, then binary)

In CI

rg exits 0 when it finds a match, 1 when it finds none, and 2 on an actual error. To assert a pattern is absent, invert the meaning: ! rg -q "FIXME" fails the step only when FIXME exists. To assert presence, rg -q "VERSION=" succeeds on a hit. Use -q (quiet) so the step gates on exit code without dumping output.

Common errors in CI

"rg: command not found" is the most common failure because ripgrep is not preinstalled on most runners; install it with apt-get install -y ripgrep, brew install ripgrep, or cargo install ripgrep. A step that "fails for no reason" right after an rg call usually hit exit 1 (no match) under set -e; guard it with || true if no-match is acceptable. "regex parse error" means an unescaped metacharacter; add -F for a literal search.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →