Grep like an LLM · part 2 of 6
Make a map, don't read
On this page
You have a ticket about loyalty stamps and a codebase you don't know. The slow move is opening files until something looks relevant. The fast move costs one command.
The heat map
$ git grep -ci 'loyalty' repositories/LoyaltyRepository.ts:11 services/loyalty/LoyaltyService.ts:23 apps/sundae.shop/app/account/page.tsx:4
-c counts the matches in each file instead of printing them. -i
ignores case, so Loyalty and loyalty both land. Read the counts like
a map. The service is the centre of gravity. The page is a consumer. You
know the shape of the feature and you haven't opened anything yet.
Don't pipe it through sort. At a dozen lines your eyes are faster than
a pipeline.
The file list
Sometimes you don't need counts, just the territory:
$ git grep -li 'loyalty' repositories/LoyaltyRepository.ts services/loyalty/LoyaltyService.ts apps/sundae.shop/app/account/page.tsx
-l prints filenames only. Same map, less ink. Reach for it when you
already plan to open files and want the shortlist.
Search the noun
Features live under their nouns. Try loyalty, stamp, refund. Verbs
like update and handle match half the codebase. If a search floods,
the fix is usually swapping a verb for the domain word.
At your desk
On the next ticket you pick up, run the heat map before you open a single file. Name the two files with the highest counts. That's the whole exercise. If the map surprised you, it earned its keep.