Searching large repos fast in Claude Code: a Glob/Grep strategy, measured

As file counts grow, search gets slower — with real file counts and timings.

Search cost rises with repo size

In a project with a few hundred files, search speed barely matters. In one with thousands, how you use `Grep`/`Glob` changes the exploration cost a lot.

What Claude Code's Grep tool actually is

Per the official docs (code.claude.com/docs/en/tools-reference, fetched 2026-07-29), `Grep` is built on ripgrep (ripgrep regex syntax, not POSIX), respects `.gitignore`, and can run 5-10x faster with `USE_BUILTIN_RIPGREP=0` pointing at a system-installed ripgrep instead of the bundled one.

Measured: a real folder with 8,000+ files

On a real personal knowledge-base folder (8,149 Markdown files), searching for a keyword:

$ find . -name "*.md" | wc -l
8149
$ time (grep -rl "SEO" . --include="*.md" | wc -l)
216
0.376 total

Narrow with Glob, then Grep

Instead of grepping the whole tree every time, narrow with `Glob` first (e.g. `src/**/*.ts`) so there's simply less for Grep to scan.

Tell CLAUDE.md the directory layout

Stating which directory owns what (frontend, shared components, etc.) in CLAUDE.md cuts down on misdirected exploration.

Combine with --add-dir

When you need to cross multiple directories, adding just the relevant ones via `--add-dir` keeps the search scope tighter than treating the whole repo as one giant working directory.

FAQ

How long does search take on 8,000+ files?
Measured live: 0.376 seconds for a keyword search across 8,149 Markdown files.
What is Claude Code's Grep tool built on?
ripgrep, per the official docs, and it respects .gitignore.
Does using system ripgrep help?
Per official info, USE_BUILTIN_RIPGREP=0 can be 5-10x faster in some environments.
What's the fastest way to narrow a search?
Glob first, then Grep; and describe the directory layout in CLAUDE.md.
Why combine with --add-dir?
It lets you add just the relevant directories instead of treating the whole repo as one search scope.