Long-Context LLM Code Review in Practice: Whole-Repository Context Without RAG
This article explains how million-token context windows make whole-repository code review practical without retrieval pipelines. It walks through a four-module architecture, noise filtering in the repository reader, structured context assembly, review-specific prompt design, and orchestration with streaming output, token budgets, and failure fallback, then covers the limits of full injection and where layered retrieval still wins.
1. Why Whole-Repository Context Is Now Feasible
For a long time, code comprehension tools relied on retrieval augmentation: split files, vectorize them, recall the top-K chunks, and stitch them into a prompt. The problem with this pipeline was never whether it worked, but its engineering complexity and its ceiling on quality. Splitting strategies break cross-file semantics, and once the recall step misses a critical dependency, the model’s conclusions become distorted.
Once a single request’s context window reached the million-token range, and call costs dropped by an order of magnitude compared with the previous generation of models, the balance shifted. For small and mid-sized repositories under roughly a hundred thousand lines, full injection is no longer a luxury; it is an everyday engineering practice. The model can see complete call chains, interface definitions, and dependency relationships, so review feedback moves from “about a fragment” to “about the system.”
To be clear, this does not mean retrieval augmentation is obsolete. Very large repositories, multi-repository coordination, and historical commit tracing still call for a layered strategy. This article is about the shortest path that long context unlocks: no index, no vector store, just sending code to the model in a structured form.
2. Overall Architecture: Four Modules with Clear Responsibilities
The tool is split into four layers, with the core logic kept to roughly one or two hundred lines of code so it stays readable and easy to modify:
- Repository reader: recursively walks the directory tree and filters out build artifacts, dependency directories, binaries, and generated files.
- Context assembler: organizes file contents into structured text carrying path and language markers.
- Prompt builder: generates different instructions per review type (security, performance, readability, concurrency correctness).
- Orchestration and output layer: calls the LLM through chained orchestration in an agent framework and streams results back.
The outer interface layer only accepts the repository path and review type parameters, decoupling the long-running task from the request lifecycle.
3. Step 1: The Reader Solves Noise Filtering
What really determines quality is often not the model but the content fed into it. The reader has to handle three kinds of problems:
type RepoReader struct {Root stringSkipDirs map[string]struct{} // dependency dirs, build artifacts, VCS metadataSkipExt map[string]struct{} // binaries, images, lock filesMaxSize int64 // per-file size cap so one large file cannot eat the budget}func (r *RepoReader) Walk() ([]FileChunk, error) {// filepath.WalkDir recurses; return filepath.SkipDir on a skip-rule hit// truncate oversized files and log a warning to keep the overall budget under control}
Three additional practices are recommended. First, output the list of skipped files so a human can confirm no critical module was missed. Second, compute an estimated total token count and compare it against the model’s context limit. Third, degrade oversized files by keeping exported signatures and truncating function bodies rather than simply dropping them.
4. Step 2: Structured Assembly Matters More Than Concatenation
Raw concatenation makes it hard for the model to tell where one file ends. The recommended format uses explicit delimiter markers so every file carries three pieces of information: path, language, and content. The path itself is the strongest semantic clue:
<file path="internal/service/order.go" lang="go">...source code...</file>
Two kinds of low-cost, high-value information can be added during assembly: the module name and dependency list extracted from build configuration files, and a directory tree skeleton. The former helps the model judge dependency version risk; the latter lets it see whether layering conventions have been violated.
5. Step 3: The Prompt Determines How Professional the Review Is
A vague “please review this code” yields almost nothing usable. The effective approach makes review dimensions explicit and requires findings to be locatable and actionable:
You are a senior backend reviewer. Produce review findings based on the full repository context below.Requirements:1. For each issue, give the file path plus a line number or function name;2. Label the severity (blocking / suggestion / optional);3. Explain the trigger condition and potential impact, then the direction of the fix;4. Do not restate code, and do not output summaries unrelated to the issues.Review focus: concurrency safety, completeness of error handling, resource release, boundary conditions.
For multiple review types, the orchestration layer can run several calls serially or in parallel by type, then merge and deduplicate the results. Compared with one very long prompt, per-dimension calls produce more focused findings and are easier for automated pipelines to consume.
6. Step 4: Orchestration, Streaming, and Cost Control
In the Go ecosystem, available agent orchestration frameworks typically provide chained calls, component abstractions, and streaming callbacks, while the model side is plugged in through an adapter layer that conforms to a common interface, so switching providers requires almost no change to business code. Three implementation points matter:
First, streaming output. A review usually takes tens of seconds, so pushing tokens as they are generated noticeably improves the experience and makes it possible to spot anomalies early and abort.
Second, budget control. Bigger context is not always better. Set a token threshold and a file priority order: inject core business code first, and put test data and sample files last.
Third, failure fallback. When the estimate exceeds the limit or a call fails, degrade to “review directory by directory in batches, then aggregate,” so the tool stays usable.
7. Limitations and Where This Goes Next
The boundary of full injection is clear: repository size, context limit, and per-call cost jointly constrain feasibility. Once a repository reaches the million-line scale, a combination of layered retrieval and incremental review is still required, for example injecting only changed files and their direct dependencies. Model output is also advisory: conclusions involving security and compliance must be verified by a human.
Evolving this skeleton further could mean plugging it into CI for incremental review, storing structured findings in a database to build a trend dashboard, or combining it with logging and monitoring/alerting capabilities to observe call quality and spend. The core idea stays the same: use engineering means to keep the context clean and well structured first, then let long context do what it is actually good at.
