AI agents don't understand your system - they search it.
This gist breaks down the cause-and-effect chain from grep-based code discovery to architecture decisions, showing why:
- naming > abstraction
- locality > layering
- predictability > cleverness
A mental model for building codebases that work with AI, not against it.
AI agents do not understand the whole codebase
β They approximate understanding via search
β Poor structure = noisy search results
β Noisy search = wrong context
β Wrong context = incorrect code
π‘ Therefore: Code structure directly affects correctness, not just speed.
AI agents rely heavily on text-based search (grep / ripgrep)
β Codebases must be search-friendly (grep-friendly)
β Search-friendly code requires:
- explicit naming
- predictable structure
- localized context
β This leads to structuring code into bounded, cohesive modules (feature-oriented / DDD-inspired)
β Within each module, files should follow consistent naming conventions:
*.use-case.ts*.repository.ts*.entity.ts
β As a result, relevant code can be located quickly and deterministically (β‘)
β This reduces:
- search time
- context reconstruction effort
β Which leads to faster task execution by the agent (β‘)
β And fewer tokens required (π):
- less code to read
- less ambiguity
β Which lowers inference cost and improves response quality (π°)
β Resulting in cheaper and more reliable feature implementation
β Ultimately reducing engineering costs for the company (π°) (and potentially improving team efficiency and rewards)
You are no longer designing just for humans - you are designing for search-driven reasoning systems.