Why We Flatten the Repo: Feeding the Beast
Every developer knows the pain of context. Your repo is a sprawling city: source files tucked into alleys, configs hidden in basements, and scripts scattered like flyers on a busy street. For humans, this is manageable - we navigate folders, open tabs, and piece together the story. For large language models, though, this chaos is kryptonite.
That’s why we flatten. We take the entire repo, compress its sprawl into one linear document, and feed it to the LLM. It’s not just a hack; it’s a survival strategy.
The Context Problem
LLMs thrive on continuity. They don’t “browse” your repo like an IDE; they consume text streams. If you drip‑feed them file by file, they forget what came before or hallucinate connections that don’t exist. By dumping everything into one file, you give the model a single, coherent context window - a panoramic view of the codebase instead of a slideshow of fragments.
The Benefits of One Big File
-
Cross‑File Reasoning
Functions inutils.pysuddenly make sense when seen alongside the classes inmain.py. The LLM can trace dependencies across files without losing its place. -
Token Stability
Instead of re‑parsing the repo every turn, the model works from a stable snapshot. This reduces redundancy and keeps costs predictable. -
Auditability
A single Markdown file is human‑readable. Auditors, contributors, or future you can scroll through the repo like a book, with headers and syntax highlighting guiding the way. -
Snapshot Integrity
Flattening creates a point‑in‑time capture. You know exactly what the LLM saw, and you can reproduce its reasoning later.
The Trade‑Offs
Of course, flattening isn’t perfect. A 100,000‑line Markdown file is unwieldy for humans, and LLMs still face token limits. That’s why smart tools prune irrelevant directories (node_modules, .git) and timestamp outputs to prevent self‑eating loops. Flattening is less about elegance and more about feeding the beast efficiently.
The Philosophy
Dumping all code into one file is a statement: we value clarity over hierarchy. It’s about giving intelligence - human or machine - the maximum chance to see the whole picture. In a world where context is currency, flattening is the richest coin you can mint.
Summing up
We don’t flatten repos because it looks pretty. We do it because it works. For LLMs, one file means one context, one story, one chance to reason across the entire codebase. It’s the difference between asking an AI to solve a puzzle with missing pieces and handing it the full box.
Flattening is not just a technical trick; it’s the philosophy of total context. And when you’re feeding the beast, total context is everything.