Claude Code for Ripgrep — Workflow Guide
The Setup
You are using Ripgrep (rg) as your primary code search tool — a faster alternative to grep that respects .gitignore, searches recursively by default, and supports PCRE2 regex. When Claude Code needs to find patterns across your codebase, Ripgrep provides results significantly faster than grep. Claude Code can use Ripgrep, but it defaults to basic grep syntax and misses Ripgrep’s powerful features.
What Claude Code Gets Wrong By Default
-
Uses
grep -rinstead ofrg. Claude writesgrep -rn "pattern" .which is slower and searches ignored files. Ripgrep is faster, respects.gitignore, and defaults to recursive search. -
Misses Ripgrep’s type filtering. Claude greps through all files then pipes through
grep -l "*.ts". Ripgrep has--type ts(or-t ts) for built-in filetype filtering without extra commands. -
Pipes through
grepfor secondary filtering. Claude chainsrg pattern | grep filter. Ripgrep supports--globfor path filtering and PCRE2 regex for complex patterns — multiple greps are usually unnecessary. -
Does not use
--jsonfor structured output. Claude parses Ripgrep’s text output with awk/sed. Ripgrep has--jsonoutput format for machine-readable results.
The CLAUDE.md Configuration
# Ripgrep Search Workflow
## Search
- Tool: Ripgrep (rg) — fast recursive code search
- Default: recursive, .gitignore-aware, no binary files
- Regex: PCRE2 enabled with -P flag
## Ripgrep Rules
- Basic: rg "pattern" (recursive from current dir)
- Type filter: rg -t ts "pattern" (TypeScript files only)
- Glob filter: rg --glob "*.test.ts" "pattern"
- Case insensitive: rg -i "pattern"
- Fixed string (no regex): rg -F "exact.match()"
- Context: rg -C 3 "pattern" (3 lines before/after)
- Count: rg -c "pattern" (count per file)
- Files only: rg -l "pattern" (list matching files)
- Replace: rg "old" --replace "new" (preview only)
## Conventions
- Use rg for all codebase searches, not grep
- Use -t flag for language filtering
- Use -F for literal string search (avoids regex escaping)
- Use --glob to include/exclude paths
- Use -l for file listing (pipe to other commands)
- Use rg -c for codebase-wide usage counts
- Use --json for machine-parseable output
Workflow Example
You want to find all usage of a deprecated API across the codebase. Prompt Claude Code:
“Find all files that use the deprecated fetchUser function, excluding test files and node_modules. Show the filename and line number for each occurrence, with 2 lines of context.”
Claude Code should run rg "fetchUser" -t ts -t tsx --glob "!*test*" -C 2 -n which searches TypeScript files, excludes test files, shows 2 lines of context, and includes line numbers — all in a single command.
Common Pitfalls
-
Regex metacharacters not escaped. Claude searches for
User.findOne({id})without escaping dots and braces. Use-Ffor literal strings:rg -F "User.findOne({id})"avoids regex interpretation entirely. -
Searching in wrong directory scope. Claude runs
rgfrom the home directory, searching everything. Alwayscdto the project root or specify the path:rg "pattern" ./srcto limit scope. -
Missing
--hiddenfor dotfiles. Claude searches for config patterns but misses.env,.eslintrc, etc. Ripgrep skips hidden files by default. Add--hiddento include dotfiles, or--no-ignoreto also search gitignored files.