name: rg description: "⚡ IMPORTANT: Auto-trigger for text search. Use when: search for text, find files containing, locate TODOs, security scan secrets, trace class usage, grep pattern matching. Returns only matching lines. 30-98% token savings. 3-4x faster than grep/Select-String."
Text search with ripgrep (rg)
Core rule
When you need to search for text content inside files, use rg on the command line instead of Select-String (PowerShell), grep -r (Bash), or reading entire files.
rg (ripgrep) is a fast regex-aware search tool that respects .gitignore, outputs relative paths, and produces compact results. For an AI agent, this matters because:
- Extracts only matching lines: Instead of loading a 2.6 MB JSON file (
692k tokens) and searching in-context,6k tokens) — a 98% reduction.rgreturns just the 415 matching lines ( - Relative paths reduce overhead: Same benefit as
fd— shorter paths = fewer tokens per match. - .gitignore awareness: Automatically skips build artifacts, dependencies, and generated code that would add noise and consume tokens without providing value.
- Speed at scale: 3-4x faster than
Select-Stringon 10k+ files means results arrive sooner, and the model can act on them faster.
Prerequisites: check/install ripgrep
IMPORTANT: Check availability first:
rg --version
If rg is not installed:
| OS | Installation command |
|---|---|
| Windows (winget) | winget install BurntSushi.ripgrep.MSVC |
| Windows (manual) | Download from https://github.com/BurntSushi/ripgrep/releases, extract rg.exe to a PATH directory |
| Linux (apt) | sudo apt-get install -y ripgrep |
| Linux (yum) | sudo yum install -y ripgrep |
| macOS | brew install ripgrep |
Shell compatibility
rg works natively in both Bash and PowerShell — no wrapping needed:
rg "groot/sa-id" catalog/systems
rg "groot/sa-id" catalog\systems
Usage patterns
Search for a string
rg "agreement_id" event.json
rg "spec.system" catalog/components
rg "agreement_id" event.json
rg "spec.system" catalog\components
List files containing a pattern (no content)
rg -l "type: repository" catalog/components
# → Just the file paths, one per line
rg -l "groot-sa-majeur" catalog/systems | wc -l
# → 749
(rg -l "groot-sa-majeur" catalog\systems).Count
Count matches per file
rg -c "agreement_id" event.json
# → event.json:415
Search with regex
rg "sa-\d{4}-" catalog/systems --no-filename -o | sort -u
rg "owner: .*team" catalog/components -l
Extract specific lines (like grep -o)
rg "name: (.*)" catalog/systems --no-filename -o
# Extracts just the matching lines, no file paths
rg "name: (.*)" catalog\systems --no-filename -o
Search with context lines
rg "spec.system" catalog/components/af-ose -A 2 -B 2
# Shows 2 lines before and after each match
Restrict to specific file types
rg "TODO" -t yaml catalog
rg "agreement_id" -t json .project
Include gitignored files
rg "pattern" --no-ignore # Skip .gitignore rules
rg "pattern" -uuu # Unrestricted (all files)
Replace text (preview)
rg "old-system" catalog/components -r "new-system"
# Shows what replacements would look like (does NOT modify files)
Combine results with other commands
# Count components per project directory
rg -l "type: repository" catalog/components | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn
# PowerShell equivalent
rg -l "type: repository" catalog\components | Group-Object { Split-Path (Split-Path $_) -Leaf } | Sort-Object Count -Descending