rg-code-search

v2026.09.24

ripgrep (rg) fast code search: smart defaults, regex, file filtering. Use when searching for text patterns, code snippets, or doing multi-file analysis.

GitHub
Install command
npx skhub add laurigates/rg-code-search
Markdown
SKILL.md

rg Code Search

Expert knowledge for using rg (ripgrep) as a blazingly fast code search tool with powerful filtering and pattern matching.

When to Use This Skill

Use this skill when...Use fd-file-finding instead when...
Searching file contents for text or regex patternsSearching for files by name, extension, or path
Filtering matches by file type (-t py, -t js)Filtering files by mtime, size, or -type
Multi-line pattern matching across source filesLocating files to feed into another tool
Use this skill when...Use binary-analysis instead when...
Searching source code or text-encoded filesExtracting strings from compiled binaries or firmware
Auditing repos for hardcoded patterns in tracked filesHunting for credentials inside ELF, Mach-O, or .bin blobs

Core Expertise

ripgrep Advantages

  • Extremely fast (written in Rust)
  • Respects .gitignore automatically
  • Smart case-insensitive search
  • Recursive by default
  • Colorized output
  • Multi-line search support
  • Replace functionality

Basic Usage

Simple Search

# Basic search
rg pattern                  # Search in current directory
rg "import numpy"           # Search for exact phrase
rg function_name            # Search for function name

# Case-sensitive search
rg -s Pattern               # Force case-sensitive
rg -i PATTERN               # Force case-insensitive

File Type Filtering

# Search specific file types
rg pattern -t py            # Python files only
rg pattern -t rs            # Rust files only
rg pattern -t js            # JavaScript files
rg pattern -t md            # Markdown files

# Multiple types
rg pattern -t py -t rs      # Python and Rust

# List available types
rg --type-list              # Show all known types

Extension Filtering

# Filter by extension
rg pattern -g '*.rs'        # Rust files
rg pattern -g '*.{js,ts}'   # JavaScript and TypeScript
rg pattern -g '!*.min.js'   # Exclude minified files

Advanced Filtering

Path Filtering

# Search in specific directories
rg pattern src/             # Only src/ directory
rg pattern src/ tests/      # Multiple directories

# Exclude paths
rg pattern -g '!target/'    # Exclude target/
rg pattern -g '!{dist,build,node_modules}/'  # Exclude multiple

# Full path matching
rg pattern -g '**/test/**'  # Only test directories

A glob with no / matches the basename only. So -g '*name*' can never match a directory called name — it tests SKILL.md, not skills/name/SKILL.md. Add a / and the glob anchors to the full path from the search root instead, where * does not cross /; only ** spans depth.

rg --files -g '*sentry-triage*'      # nothing — basename is SKILL.md
rg --files -g '*sentry-triage*/**'   # nothing — now anchored at the root
rg --files -g '**/sentry-triage/**'  # skills/sentry-triage/SKILL.md ← the only form that works

It fails quietly: -g '*name*' still matches sibling files like name-notes.md, so a partial hit reads as a working search. When hunting a name rather than content, prefer rg -l <pattern> or find -type d -name <name>.

Content Filtering

# Search only in files containing pattern
rg --files-with-matches "import.*React" | xargs rg "useState"

# Exclude files by content
rg pattern --type-not markdown

# Search only uncommitted files
rg pattern $(git diff --name-only)

Size and Hidden Files

# Include hidden files
rg pattern -u               # Include hidden
rg pattern -uu              # Include hidden + .gitignore'd
rg pattern -uuu             # Unrestricted: everything

# Exclude by size
rg pattern --max-filesize 1M  # Skip files over 1MB

Quick Reference

Essential Options

OptionPurposeExample
-t TYPEFile type filterrg -t py pattern
-g GLOBGlob patternrg -g '*.rs' pattern
-iCase-insensitiverg -i pattern
-sCase-sensitiverg -s Pattern
-wMatch whole wordsrg -w word
-lFiles with matchesrg -l pattern
-cCount per filerg -c pattern
-A NLines afterrg -A 5 pattern
-B NLines beforerg -B 3 pattern
-C NContext linesrg -C 2 pattern
-UMulti-linerg -U 'pattern.*'
-uInclude hiddenrg -u pattern
--replaceReplace textrg pattern --replace new

This makes rg the preferred tool for fast, powerful code search in development workflows.

For the full regex and multi-line recipes, output formatting, language-specific search patterns, tool integrations, performance tuning, and the complete file-type table, see REFERENCE.md.

Discovery
Tags

No tags published for this skill.

Version
Latest version metadata

Version

v2026.09.24

Published

Sep 24, 2026

Category

Uncategorized

License

MIT

Source path

tools-plugin/skills/rg-code-search

Default branch

main

Latest commit

1668324

Tree SHA

b2d4cc3