Coding and Software-Engineering Agents › The repository navigation problem
Language AI HandbookAll chapters Repository tasks usually expose more source than the model should read for one change. Start with a failing test or a symbol name, then use imports, references and call sites to determine which files belong in the working context. The right search scope depends on repository size and the task.
A small change may require reading several files around a much larger repository. Use search output as a starting point for selecting source to read.
Repository navigation uses lexical matches and code relationships such as imports and call sites. Document retrieval also retrieves selectively, though its search units and relevance judgments often differ.
An exact search for an identifier can narrow the files to inspect. Follow references or use a symbol index when several definitions share a name.
The navigation toolbelt
The tools a competent repository agent exposes to itself are, essentially, the tools a careful human engineer uses. You can think of them in increasing order of resolution:
- Grep / regex search (Part I, Ch 3) finds every occurrence of a symbol, string, or pattern across the repository. It is the fastest way to answer "where is this function defined?" or "which files reference this class?" This is usually the first move.
- Glob / directory listing gives the agent the shape of the repository, so it can learn the project layout, find the test directory, and understand which files are even candidates.
- Symbol-aware search (an LSP, tree-sitter, or language-specific index) resolves definitions, references, and types, which plain grep cannot do when a name is overloaded across files.
- Read opens a specific file or line range at full text. This is expensive in context, so you spend it only on candidates you have narrowed down.
- Git history and blame reveals how a piece of code came to be and why, which is frequently the most informative evidence about how to change it.
- The test suite itself is a navigation tool: a failing test names the exact function, the exact scenario, and often the exact expected output, which is a shortcut to the code you need.
Search results usually cost fewer input tokens than complete files. Start with a capped list and refine a broad query before reading files. A cap bounds what the tool returns; it does not make the underlying search free.
The fixture has 12 candidate files and 13 points on the progress axis. At zero, no candidate has been processed. The search-first policy has already paid for three search results. It then opens only the second and third candidates. The exhaustive policy reads a file at each candidate position.
PythonIn [5]Expand
# Deterministic model of context cost. A grep returns ~200 tokens for a
# candidate list; reading a file costs ~4000 tokens. The funnel runs a fixed
# number of cheap searches first, then reads only the narrowed candidates.
n_candidate_files = 12
grep_cost = 200
read_cost = 4000
n_searches = 3
funnel_positions = list(range(n_candidate_files + 1))
shortlist = (2, 3)
blind_cumulative = [p * read_cost for p in funnel_positions]
funnel_cumulative = [
n_searches * grep_cost + read_cost * sum(i <= p for i in shortlist)
for p in funnel_positions
]
print("blind total tokens:", blind_cumulative[-1])
print("funnel total tokens:", funnel_cumulative[-1])
print("savings factor:", round(blind_cumulative[-1] / funnel_cumulative[-1], 1))ConsoleOut [5]Expand
blind total tokens: 48000 funnel total tokens: 8600 savings factor: 5.6
The search-first route costs 8,600 tokens in the calculation, compared with 48,000 for exhaustive reads. This result assumes the searches find the two useful files. A missed file or a broader shortlist changes the comparison.
VisualizationOut [6]Expand

Inspect what the search excluded when a later test shows a missing dependency or caller. Refine the search before reading more source.
A symbol index can help distinguish same-named definitions or references where its language analysis supports them. Text search returns the matching text without deciding what a call resolves to.
A compact outline of the repository. It can list important directories, top-level definitions and links to README and configuration files. A large index needs a selection budget so only relevant entries reach the model.
What the agent needs from the test name
A name like test_parse_iso_date_handles_leap_year suggests where to search and what to examine. Read the assertion to learn the input and the expected result before changing the parser.
A test name can expose a useful search term. test_case_7 gives little direction; a name containing the public API can point to callers and tests.
When no test exists, the engineer (or the agent) must write one first. That is the next section.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!