Skip to content

Instantly share code, notes, and snippets.

@everget
Last active March 22, 2026 05:24
Show Gist options
  • Select an option

  • Save everget/b79cc4d115489d0c15791046042b4e64 to your computer and use it in GitHub Desktop.

Select an option

Save everget/b79cc4d115489d0c15791046042b4e64 to your computer and use it in GitHub Desktop.
Designing Grep-Friendly Codebases for AI Agents

πŸ” Your codebase is a Search API for AI agents

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.


⚠️ Core Limitation

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.


πŸ”— Causal Chain: From Search to Cost

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)

πŸ’‘ Key Insight

You are no longer designing just for humans - you are designing for search-driven reasoning systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment