TL;DR: Narrow before reading. Start from the task's own clues (error messages, stack traces, names, URLs) with exact search; use the ownership and build graph to find the right project; give the agent a scoped map of that project, not the whole repository; follow definitions and references with a code index or language server; read slices, not files; and keep findings in notes so they survive context clearing. Isolate broad exploration in subagents that return file and symbol lists. Measure by how many files the agent opened per task and whether it found the right ones.
How to approach it
Put a number on the problem first (two million lines does not fit in anything), then describe a narrowing funnel from clues to project to files to functions, with the tool for each stage, and how you would know it works.
A strong answer
Scale. At roughly 10 to 12 tokens a line, two million lines is over 20 million tokens. Even a generous working budget holds a fraction of a percent. The agent must decide what to read with very little reading.
The funnel.
| Stage | Tool | Output |
|---|---|---|
| Clues from the task | Exact search for error text, identifiers, URLs, config keys | A handful of hits with paths |
| Which project | Code ownership files, build graph, directory metadata | One or two projects or packages |
| Map of that project | Files with main symbols, ranked by relevance | A few hundred tokens of outline |
| Follow the code | Language server or symbol index: definition, references, callers | The functions involved |
| Read | Slices of the relevant functions and their tests | A few hundred lines |
def funnel(total_lines, hits_files, project_files, read_functions,
lines_per_function=40):
read = read_functions * lines_per_function
return {"total": total_lines, "files_considered": project_files,
"files_opened": hits_files, "lines_read": read,
"share_read": f"{100 * read / total_lines:.3f}%"}
run = funnel(2_000_000, hits_files=6, project_files=180, read_functions=9)
print(run["lines_read"], run["share_read"]) # => 360 0.018%
A good run reads a few hundred lines, around two hundredths of a percent of the repository, and still finds the cause, because every step narrowed the search before any reading.
Use the repository's own structure. Ownership files and build targets say which team and package own the failing service; test layouts say where the tests are; the repository's instruction files say how to build only that package.
Protect the context. Search results and file slices are cleared once used; findings go into notes ("parse_date in libs/dates/parse.py is called by invoices/ingest.py:88; the bug is the day-first default"). Broad exploration (which of forty services call this library?) runs in a subagent that returns a list, not forty files.
Measure. On a labelled set of tasks with known fix locations: whether the agent opened the right files, how many files it opened, tokens spent before the first edit, and success. These tell you which stage of the funnel is weak.
What interviewers probe next
"Wouldn't embeddings over the whole repository be simpler?" They help for vague questions, but code questions often contain exact names, and embeddings of millions of chunks return many look-alikes. Use them as one tool after exact and structural search, scoped to the project.
"The language server is slow to start on this repository." Run a shared, pre-built index service the agent queries, rather than starting a language server per session.
"How does the agent know when to stop exploring?" When it can name the files and functions to change and the tests that cover them, written in notes.
What if?
What if · interview follow-ups
Hold your answer as the constraints change
A coding agent must fix a bug in a two-million-line monorepo.
Start here
What if the task gives no names, only 'invoices sometimes show the wrong date'?
Where do clues come from?
Generate clues: search for date parsing in the invoicing package found through ownership, look at recent changes there, run the relevant tests, and use semantic search scoped to that package for the vague description.
Carry it forwardNo names means scoped discovery, not whole-repo reading.
Weak answerEmbedding-searching the entire repository first.
Constraint changes
What if exact search for the function name returns 300 hits?
How do you narrow?
Restrict to the owning project, prefer definitions over uses, and follow references from the definition with the index. Three hundred hits is a signal to scope, not to read.
Carry it forwardToo many hits means narrow the scope.
Weak answerReading the first twenty hits.
Constraint changes
What if context clearing removes the file the agent just analysed?
What should survive?
The finding, not the file: notes record the location and what it does, so the agent can re-read a slice if needed instead of rediscovering it.
Carry it forwardKeep conclusions in notes; let raw reads go.
Weak answerDisabling clearing for code reads.
Now defend it
One-line design?
A funnel from task clues to owning project to scoped map to definitions and references to small slices, with findings in notes, broad exploration in subagents, and measurement of files opened and found.
How it's scored
Weak: Embeds the whole repository and retrieves top-k chunks, or reads files until the context is full.
Hire: Combines exact search, a project-scoped map and a language server, reading slices.
Strong Hire: Quantifies the scale, designs the funnel with a tool per stage including ownership and build metadata, protects context with clearing and notes, isolates broad exploration in subagents, uses a shared index service, and measures file-finding accuracy and tokens before first edit.
Common mistakes
- Whole-repository semantic search as the first step.
- Reading entire files instead of slices.
- Losing findings when context is cleared.
- No measurement of whether the agent found the right files.