agent-search
Choose and run the right search tool: rg vs grep vs ast-grep vs fd vs fzf. Bounded repo navigation with ripgrep, fd, tree, bat, and structural search. Use when finding symbols, files, syntax patterns,
SKILL.md.claude/skills/agent-search/SKILL.md
GitHubAgent search
Text and structural search with low memory and bounded output.
Purpose
Locate files and code quickly using the right CLI tool for the job — before opening large files or running embedding indexes.
Tool selection (read first)
Full matrix: references/tool-selection.md
- Default order:
fd(filename) →rg(content) →ast-grep(syntax) →bat/sed(read slice). - Prefer
rgovergrep— gitignore-aware, faster; usegreponly ifrgis missing or piping one stream. fdwhen hunting files by name/path/extension — not file contents.ast-grepwhen the query is syntax shape (exports, JSX patterns, call shapes) — not plain strings.fzfis optional for humans — agents narrow with path prefix +rg --max-countinstead.tree/ezafor directory layout only — not content search.- Cursor IDE: Grep tool ≈
rg; SemanticSearch for meaning; Glob ≈fd. - fff MCP: When project
fff-galleryis connected, prefergrep/find_files/multi_grepfor repeated repo search; one-off probes may still userg/fd— see tool-selection.md and AGENTS.md § fff.
When to use (scenario → tool)
| Scenario | Tool |
|---|---|
| Find files by name or extension | fd |
| Find literal text or regex in code | rg |
rg unavailable |
grep (fallback, avoid -r on repo root) |
| Match function/class/JSX structure | ast-grep |
| Security or rule-pack scan | semgrep --dryrun |
| Orient in unfamiliar directory | tree -L 2 |
| Read lines after locating file | bat --line-range or sed -n |
| Too many hits | Narrow path, --max-count, or -g glob |
Required tools
- Text:
rg,fd,tree(oreza), optionalfzf,bat,zoxide,delta - Structural:
ast-grep(sg), optionalsemgrep,tree-sitter,universal-ctags
Install: agent-cli-hub/references/install-blocks.md
Common commands
Text search (gallery globs)
rg "ipcMain.handle" electron/ -n --glob '!node_modules'
rg "useGalleryStore" src/ -n --max-count 30
fd "\.tsx$" src/components
tree -L 2 src/
Interactive pick (optional, human only)
rg --files | fzf
fd . -t f | fzf
Bounded file read
bat --line-range 1:80 electron/main.ts
sed -n '40,100p' src/App.tsx
Structural (ast-grep)
ast-grep --pattern 'export function $NAME($$$)' --lang ts src/
semgrep --config auto --dryrun src/
Tags (optional)
ctags -R src electron
PowerShell:
rg "ipcMain" electron/ -n
fd "\.tsx$" src
Get-Content .\electron\main.ts -TotalCount 80
Agent-safe patterns
- Always pass
--glob '!node_modules','!dist','!mcp-server/dist'on broad searches. - Cap matches:
--max-count,-m, or narrow path prefix (src/,electron/). - Run
rgbeforecat; usebat --line-rangeorsed -nfor slices. - Prefer
ast-grep --dry-run/semgrep --dryrunbefore rewrite modes.
Commands requiring confirmation
ast-grep -U(rewrite),semgrep --autofix— see commands-requiring-confirmation.md.
Troubleshooting
- No matches: Try case-insensitive
rg -i; check wrong folder or generateddist/. - Wrong tool: See tool-selection.md — filename vs content vs syntax.
- ast-grep missing:
npm i -g @ast-grep/clior see install blocks. - WSL fd: Use
fdfindor symlink tofd.
Verification checklist
rg --version && fd --version
rg "export" src/ -n --max-count 3