notes to self

Grep like an LLM · part 3 of 6

Find the door

On this page

Most tasks arrive describing something you can see: a label, a button, a page. The code behind it has an entry point somewhere, and finding that door is faster than wandering the building.

Start from what you can see

A bug report usually quotes the page, and the exact text is the fastest way in:

$ git grep -F '99 Flake (+ £0.50)'
apps/sundae.shop/components/flavour-card.tsx:    <small>99 Flake (+ £0.50)</small>

-F searches for the literal string with regex switched off, meaning the brackets, plus sign and currency symbol are just characters. Copy the text from the screen, paste it inside quotes, and you're looking at the component that renders it.

A label that finds nothing is also an answer: the copy probably lives in a CMS or a translation file rather than in code, and you've learned that for the cost of one search.

Files are named after their jobs

When you know roughly what something is called, search the filenames before the file contents:

$ git ls-files | grep -i menu
apps/sundae.shop/app/menu/page.tsx
services/menu/MenuService.ts

git ls-files prints every tracked filename, and piping it through grep -i filters them, ignoring case. Codebases tend to name files after their jobs, so the door is usually labelled.

Read around the match, not the file

Once a search hits, you rarely need the whole file to understand the match:

$ git grep -n -C 3 'jingle'
services/jingle/JingleService.ts:8-export class JingleService {
services/jingle/JingleService.ts:9-  /* Plays the chime when the van
services/jingle/JingleService.ts:10-     arrives at a pitch. */
services/jingle/JingleService.ts:11:  playJingle(pitch: Pitch) {
services/jingle/JingleService.ts:12-    if (pitch.quietZone) return;

-n adds line numbers and -C 3 brings three lines of context either side of each match. That's often enough to answer the question on its own, and when it isn't, you arrive in the file already knowing the line.

At your desk

The next time a bug report quotes the page, paste the quoted text into git grep -F before you do anything else. One command takes you from the words on screen to the component that renders them.