How to Grep Like an LLM

marcusmichaels1 pts2 comments

Grep like an LLM · notes to self

Grep like an LLM

11 June 2026

An AI agent can land in a codebase it has never seen and find the right<br>file in seconds. It has no map and no memory of the project. It reads<br>almost nothing.

I asked mine how, and the answer was grep, git, and a method of stopping the moment your question is answered.

grep is a search program that has shipped with every Mac and Linux<br>machine for decades. You give it a word, and it prints every line of<br>every file that contains that word. That is the whole tool. git grep<br>is the same idea built into git, searching only the files your project<br>tracks.

These notes are based on Sundae Service, our codebase of a made-up ice cream van business.

The short version

Search the noun, not the verb. Build a map before you read anything. Find<br>the entry point and read top-down. Read the types before the logic. Trace<br>one field from where it's written to where it's read. When the code won't<br>explain itself, ask the history. Stop when your question is answered.

Each line of that gets its own module later in the series, but the<br>commands are useful from day one, so here they are. Most use git grep,<br>ordinary grep that only searches the files your project tracks, which is<br>exactly what keeps node_modules and build output out of your results.<br>If any look unfamiliar, that's what the modules are for.

You want to know<br>Run

Where does this feature actually live?<br>git grep -ci 'loyalty' (high counts mark the centre of gravity)

Which files mention it at all?<br>git grep -li 'loyalty'

What renders this exact text on screen?<br>git grep -F '99 Flake (+ £0.50)'

Which files are named after it?<br>git ls-files | grep -i menu

Matches for the word, not every substring<br>git grep -w 'van' (stops vanilla matching)

Enough context to skip opening the file<br>git grep -n -C 3 'jingle'

Who sets this value?<br>git grep 'soldOutAt =' (write sites are rare and load-bearing)

What changed in this area?<br>git log --oneline -- services/stock/

When did this string appear, and why?<br>git log -S 'meltAlert' --oneline (then read that commit's PR)

Seven flags do most of the work, and they mean the same thing in grep,<br>git grep, and ripgrep: -i ignore case, -l filenames only, -c<br>count per file, -w whole word, -n line numbers, -F literal string<br>(regex off), -C 3 three lines of context around each match. Two more<br>from git log: --oneline for one commit per line, and -S 'x' for<br>commits that add or remove x.

Learn these once. They'll outlive every editor you ever install.

Each module is sized for a commute, meaning you can read one on the train<br>in the morning and try it at your desk the same day. The full series is<br>below.

grep read files file word line

Related Articles