chapter three

3 Workflow: Build your own codebase knowledge builder

 

This chapter covers

  • Build a workflow that turns any repo into a readable tutorial
  • Prune a huge repo to fit the LLM's context window
  • Force structured YAML output from an LLM
  • Decompose a task with the overview-then-zoom-in pattern
  • Encode domain knowledge in a swappable instructions file

Chatting with an LLM works for a 19-file codebase like nanoGPT because you already know what to ask. Your questions about vocab_size = 50304 and gradient accumulation were driven by your own expertise. That approach breaks down on a 500-file codebase you've never seen before. You don't know which questions to ask, and you can't paste the entire project into the context window.

What you need is a systematic approach: a tool that reads the whole codebase, identifies the core concepts, and explains them in a logical order, mapping out their dependencies. This is a pipeline that asks the right questions for you, not a conversation where you hope to stumble on them yourself. That's what you will build in this chapter: a Codebase Knowledge Builder. The full code is available at github.com/zachary62/Crack-Any-Codebase-with-AI/tree/main/ch03-workflow. By the end, you'll have learned three techniques that are reused throughout this book: forcing structured output from LLMs, decomposing a problem with an overview-then-zoom-in strategy, and encoding domain knowledge in instruction files.

3.1 Turn any codebase into a tutorial for $2

3.2 What the LLM sees determines everything

3.2.1 Most repos fit. The interesting question is what to do when they don't.

3.2.2 Prune the obvious, then let the LLM pick the rest

3.2.3 The LLM needs guidance to pick well

3.3 Analyze: The overview-then-zoom-in pattern

3.3.1 Step 1: Get the overview (1 LLM call)

3.3.2 Step 2: Map relationships (1 LLM call)

3.3.3 The pattern that scales

3.4 Write chapters that read as one tutorial, not ten

3.4.1 Sequential context: Each chapter knows what came before

3.4.2 The instructions file: Where the real engineering lives

3.4.3 Putting it all together

3.5 Swap the instructions, change the output

3.5.1 Same codebase, different lenses

3.5.2 Different questions for different layers

3.6 Summary