home / skills / 0xdarkmatter / claude-mods / file-search

file-search skill

/skills/file-search

This skill speeds up codebase exploration by combining fd, rg, and fzf for fast file search, content search, and interactive selection.

npx playbooks add skill 0xdarkmatter/claude-mods --skill file-search

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
2.3 KB
---
name: file-search
description: "Modern file and content search using fd, ripgrep (rg), and fzf. Triggers on: fd, ripgrep, rg, find files, search code, fzf, fuzzy find, search codebase."
compatibility: "Requires fd, ripgrep (rg), and optionally fzf. Install: brew install fd ripgrep fzf (macOS)."
allowed-tools: "Bash"
---

# File Search

Modern file and content search.

## fd - Find Files

```bash
# Find by name
fd config                    # Files containing "config"
fd -e py                     # Python files

# By type
fd -t f config               # Files only
fd -t d src                  # Directories only

# Exclude
fd -E node_modules           # Exclude directory
fd -E "*.min.js"             # Exclude pattern

# Execute command
fd -e py -x wc -l            # Line count per file
```

## rg - Search Content

```bash
# Simple search
rg "TODO"                    # Find TODO
rg -i "error"                # Case-insensitive

# By file type
rg -t py "import"            # Python files only
rg -t js -t ts "async"       # JS and TS

# Context
rg -C 3 "function"           # 3 lines before/after

# Output modes
rg -l "TODO"                 # File names only
rg -c "TODO"                 # Count per file
```

## fzf - Interactive Selection

```bash
# Find and select
fd | fzf

# With preview
fd | fzf --preview 'bat --color=always {}'

# Multi-select
fd -e ts | fzf -m | xargs code
```

## Combined Patterns

```bash
# Find files, search content
fd -e py -x rg "async def" {}

# Search, select, open
rg -l "pattern" | fzf --preview 'rg -C 3 "pattern" {}' | xargs vim
```

## Quick Reference

| Task | Command |
|------|---------|
| Find TS files | `fd -e ts` |
| Find in src | `fd -e ts src/` |
| Search pattern | `rg "pattern"` |
| Search in type | `rg -t py "import"` |
| Files with match | `rg -l "pattern"` |
| Count matches | `rg -c "pattern"` |
| Interactive | `fd \| fzf` |
| With preview | `fd \| fzf --preview 'bat {}'` |

## Performance Tips

| Tip | Why |
|-----|-----|
| Both respect `.gitignore` | Auto-skip node_modules, dist |
| Use `-t` over `-g` | Type flags are faster |
| Narrow the path | `rg pattern src/` faster |
| Use `-F` for literals | Avoids regex overhead |

## Additional Resources

For detailed patterns, load:
- `./references/advanced-workflows.md` - Git integration, shell functions, power workflows

Overview

This skill provides modern file and content search workflows built on fd, ripgrep (rg), and fzf. It combines fast filename discovery, high-performance text search, and interactive fuzzy selection to locate files, inspect code, and open results quickly. The focus is speed, accuracy, and seamless integration into command-line workflows.

How this skill works

It uses fd to locate files by name, type, and patterns while respecting .gitignore. ripgrep (rg) performs fast content searches with options for context, file-type filtering, and output modes (file list, counts, matches). fzf offers interactive fuzzy selection and previewing, letting you pick results and pipe them into editors or commands.

When to use it

  • Quickly find files by name or extension across a project
  • Search codebase for TODOs, functions, or error messages with context
  • Interactively select and preview search results before opening
  • Combine filename search and content search into automated workflows
  • Count or list files that match a pattern for reporting or cleanup

Best practices

  • Prefer fd -t or rg -t to filter by file type for faster results
  • Narrow search scope (provide a directory) to reduce noise and latency
  • Use rg -F for fixed-string searches when regex is unnecessary
  • Pipe rg -l into fzf for interactive selection and use --preview to show context
  • Exclude common build folders (node_modules, dist) or rely on .gitignore to skip irrelevant files

Example use cases

  • Find all TypeScript files: fd -e ts and open selected with fzf | xargs code
  • Locate every TODO in the repo and count occurrences: rg -c "TODO"
  • Search for a function name with context and open chosen file: rg "functionName" -C 3 | fzf --preview 'rg -n --color=always "functionName" {}'
  • Batch-open matched files: rg -l "pattern" | fzf -m | xargs vim
  • Run a command per file found: fd -e py -x wc -l to get line counts

FAQ

Do these tools respect .gitignore?

Yes. Both fd and rg respect .gitignore by default, which skips node_modules and other ignored paths.

When should I use rg vs fd?

Use fd to find files by name or type. Use rg to search file contents. Combine them when you need to locate files and then search inside them.