Lesson 3 of 6
Indexing, planning, editing
6 min read
Your repo has 400 files and the model can only 'see' a few at a time. So how does an agent change the right three lines?
Indexing: reading the whole repo
A model can only hold so much text at once, but your codebase is far bigger than that window. So a coding agent indexes the repo first: it splits your files into chunks and builds a searchable map — often using embeddings, which let it find code by meaning rather than exact words. Ask about 'the login flow' and it can pull the right files even if none of them literally say 'login'.
Indexing turns a repo too big to read into a map the agent can search. It retrieves the few relevant files instead of trying to read everything.
Planning: deciding the change
With the right files in hand, the agent plans. It works out what to change and in what order — which function to touch, which tests to run, whether one edit depends on another. On a bigger task it may write the plan out first, then execute it step by step. A good plan is what keeps a multi-file change coherent instead of a pile of random edits.
Planning is the agent deciding what to change before it changes anything — the difference between a surgical edit and a mess.
Editing: a precise diff, not a rewrite
Finally it edits. Modern agents don't paste a whole new file — they produce a small diff: change these lines, leave the rest. That keeps edits reviewable, avoids clobbering code it wasn't asked to touch, and applies cleanly even as the file changes around it. Read → plan → edit is the inner mechanism behind every step you saw in the loop.
Retrieval isn't perfect. If the index misses a relevant file, the agent plans with a blind spot — which is why a clear prompt naming the right area still helps, even with good indexing.
The three moves
- —Index — chunk the repo and search it by meaning to find the relevant files.
- —Plan — decide what to change, in what order, before touching anything.
- —Edit — apply a small, reviewable diff, not a full-file rewrite.
A repo is far bigger than the model's context window. How does an agent find the right files to change?
Continue in the app
Take the whole How AI Coding Agents Work course — tracked
Get your personalized path, progress and streaks in the app — this lesson and every next one, in order.