Sub topic 1
How an agent changes many files at once
Prerequisites
This chapter assumes you know basic Git (branches, commits, diffs, staging) and can read code in at least one language. You should be able to run a project's tests, linter, and build from the command line. You should also have used a coding agent or AI assistant to edit code at least once.
The agent works in a loop
A coding agent does not produce one patch. It works in a loop of small steps:
- It reads a few files or searches the codebase.
- It decides on an edit and writes it directly to files in your working tree.
- It may run a command, such as the tests or a type checker.
- It reads the output and chooses the next step.
The loop repeats until the agent decides the task is done. Then it writes a summary.
Why one request touches many files
Most real changes are connected. If you ask for one change, the agent follows its consequences through the code.
Suppose you ask it to rename load_config to read_settings. A careful agent will usually touch several kinds of files:
| File kind | Why it changes |
|---|---|
| Definition | The function itself is renamed. |
| Callers | Every call site must use the new name. |
| Tests | Tests import and call the function. |
| Docs and examples | Text and snippets mention the old name. |
| Configuration | Entry points or scripts may reference it. |
The agent finds these places with searches and by reading imports. It can only edit what it has found.
What this means for you
The way the agent works has four consequences for review.
- Edits are incremental. The agent edits file by file. Early edits are not re-checked against later ones unless the agent chooses to look again. Two files can disagree about a function signature.
- The agent's view is partial. It sees the files it opened or searched for. A caller in a file that no search matched may be missed. Dynamic references, such as a name built from a string, are easy to miss.
- It can change more than you asked. While fixing a failing test, an agent may edit a nearby file, delete a check, or reformat code. Each step may look reasonable to the agent, but together they can leave the intended task.
- The summary is not the record. The summary is the agent's own description of what it did. It can leave out edits, or it can claim that tests passed when it never ran them. The record of what actually changed is the diff in your repository.
Edits land in your working tree
Because the agent writes straight to your files, its changes mix with anything you had already changed. If you had uncommitted work, you can no longer tell your edits from the agent's. New files the agent creates are also untracked, so a plain git diff will not show them. Later chapters cover how to prepare for this with a clean branch and how to list every touched file. For now, keep one rule in mind: before a run, know exactly what state your code is in, so that anything that changes afterwards is the agent's work.
Key ideas to carry forward
- A multi-file change is the result of many small edit and check steps, not one atomic patch.
- Related files change together because changes have consequences: callers, tests, docs, and configuration.
- The agent sees only part of the codebase, so it can miss places or touch places it should not.
- You are responsible for the final result, so the review has to rest on the diff and on your own checks.
Exercise
You ask an agent to change a function signature. Its summary says "Updated the function and all callers; tests pass." Name two reasons you should not accept this statement without checking, and name where the real record of its work is.
Show answer
First, the agent only edits files it found, so it may have missed callers, such as dynamic references or files no search matched. Second, the summary is the agent's own description, so it may be incomplete or wrong, for example claiming tests passed when it never ran them or ran only some of them. The real record is the diff in your repository, including untracked new files shown by git status, plus your own test run.