Sub topic 4
Keep changes small enough to review
This chapter assumes you can read a Git diff, run git from the command line, and write or run unit tests in at least one language. You should also have used an AI coding assistant on a real task. Earlier chapters covered why AI code needs review and how it typically fails. This chapter covers how to shape the work so that review is possible at all.
Why size decides review quality
Review is a human activity with a limited budget of attention. A reviewer who sees 30 changed lines can hold the whole change in mind. A reviewer who sees 1,500 changed lines across 40 files skims, trusts the parts that look tidy, and misses the line that matters.
AI assistants make this problem worse. They produce code quickly, so the size of a change is limited by the prompt and not by the effort of typing. A single request such as "add user accounts" can return a new model, routes, a migration, a helper module, and edits to existing files in one pass. The code is often well formatted and consistently named. That polish makes a large diff feel safer than it is.
Treat diff size as a property you control before the AI starts, not something you discover afterward.
What "small enough" means
There is no universal line count. Use these working limits as a starting point and adjust them to your codebase and your own reading speed.
| Measure | Comfortable | Needs splitting |
|---|---|---|
| Changed lines (added plus removed) | Under about 200 | Over about 400 |
| Files touched | 1 to 4 | More than about 8 |
| Distinct purposes | One | Two or more |
| Time to explain the change aloud | Under a minute | You need a whiteboard |
The last two rows matter more than the first two. A 150-line change that mixes a bug fix, a rename, and a new feature is harder to review than a 300-line change that does one thing, because you must keep several intentions in mind and check each line against the right one.
A useful test is the one-sentence rule. If you cannot describe the change in one sentence without the word "and", it is probably more than one change.
Shape the task before you prompt
The cheapest place to control size is the request. Compare two prompts.
- Too broad: "Add password reset to the app."
- Scoped: "Add a function
create_reset_token(user_id)inauth/tokens.pythat returns a signed token valid for 30 minutes. Do not change any other file."
The second prompt names the file, the function, the behavior, and the boundary. The result is easy to check against the requirement, which is the step covered in the previous chapter.
Practical ways to keep a request small:
- Split features into layers and request one layer at a time, such as data model, then logic, then the web endpoint.
- Name the files the assistant may touch, and say that all others are off limits.
- Ask for the smallest change that satisfies the requirement, and state what to leave alone, such as formatting, imports, and unrelated functions.
- Separate mechanical work from behavior changes. Do renames, formatting, and file moves in their own change, with no logic edits.
- Ask for a plan first. Read the plan, cut it down, then ask for implementation of only the first step.
Work on a branch and checkpoint often
Small changes need somewhere to live. Create a branch for the task and commit after each reviewed step. Each commit then becomes a unit you can inspect, test, and revert on its own.
git switch -c feature/reset-token
# ask the assistant for one small step, then review it
git diff --stat
git diff
git add -p
git commit -m "Add create_reset_token with 30 minute expiry"git diff --stat gives the size first, before you read anything. If the summary shows more files or lines than you expected, stop and ask why before reading the details. git add -p then lets you stage hunk by hunk, so you accept only the pieces you have reviewed. The hunks you skip stay in your working tree, where you can discard or rework them.
Detect scope creep
Scope creep is any change that the requirement did not ask for. AI assistants add it routinely. Typical examples:
- Reformatting or reordering code in files that had no functional change.
- "Improving" nearby functions, renaming variables, or adding type annotations everywhere.
- Adding new dependencies, configuration, or helper layers for a simple task.
- Deleting code or tests that looked unused or inconvenient.
- Changing default values, timeouts, or error messages.
Each of these may be harmless, but each one is a separate claim that needs its own review. Deleted tests deserve the most suspicion, because a test that fails after an AI edit is evidence, and removing it hides that evidence.
A quick scope check uses the diff statistics:
git diff --stat
git diff --name-status
git diff --diff-filter=D --name-onlyThe second command marks each file as added (A), modified (M), deleted (D), or renamed (R). The third lists only deleted files. Compare the output against the list of files you expected to change. Any difference is a question to resolve before you continue.
You can also ignore whitespace-only noise to see the real change:
git diff -w --statIf the plain stat shows 600 lines and the -w stat shows 40, the assistant reformatted code. Ask for those edits to be reverted, so the history shows only the real change.
A review flow built around size
The diagram shows a loop in which size is checked before detail. Reading starts only after the change passes the size and scope gates.
Note the last step. Small commits do not remove the need to look at the combined result. Before you merge, read git diff main...HEAD once to confirm that the pieces fit together and that nothing was introduced between commits that contradicts an earlier one.
When the change is already too big
Sometimes the assistant has already produced a large change, or you let a long session run. You have three options.
- Discard and re-ask in pieces. This is often the fastest option. The code cost almost nothing to generate, so throwing it away loses little. Keep the prompt that worked as a guide for the smaller requests.
- Split by hunk. Use
git add -pto stage one logical piece, commit it, and repeat. Usegit stash push -pto set aside the parts that belong to later commits. - Review by layers. If you must read it as a whole, read in a fixed order: tests first (they state the intended behavior), then public interfaces, then the internals. Do not read files in alphabetical order, because that hides the structure.
Avoid a fourth option, which is accepting the change because it passes tests. Tests only cover what they were written to cover, and a large change usually contains behavior that no test touches.
Common mistakes
- Letting one long session accumulate edits. Context drifts over a long conversation, and the assistant starts changing things you never mentioned. Start a fresh session for each small task and commit between them.
- Reviewing only the files you expected. Unexpected files are where scope creep appears. Always check the full list from
git diff --name-status. - Trusting a summary. The assistant's own description of its change may omit edits. The diff is the only reliable record.
- Bundling cleanup with features. A reviewer cannot tell which line changes behavior. Keep cleanup separate.
- Skipping the review because the change "only touches tests". AI-edited tests can be weakened to pass, for example by loosening an assertion. Test changes need the same scrutiny as production code.
Summary of the habit
Decide the size before you prompt. Check the size before you read. Reject or split what exceeds your limit. Commit what you have reviewed, and only what you have reviewed. These steps cost little and make every later review step, from edge cases to security, achievable.
Exercise
An assistant returns a change that adds a new endpoint, renames three helper functions, reformats two unrelated files, and removes a test that "was redundant". git diff --stat shows 14 files and 620 lines. Which steps do you take, in order, before reading any code in detail?
Show answer
First compare the file list from git diff --name-status with the files you expected, and list deleted files with git diff --diff-filter=D --name-only. Run git diff -w --stat to see how much is whitespace-only reformatting. Then split the work: discard or revert the reformatting and unrelated files, put the renames in a separate commit with no logic changes, and treat the removed test as a flagged item that must be justified or restored. Only then review the endpoint itself as a small, single-purpose change, ideally by re-asking for it with a scoped prompt.
Exercise
Why is a 150-line change that fixes a bug, renames a class, and adds a feature harder to review than a 300-line change that only adds one feature?
Show answer
The mixed change has three intentions, so each line must be checked against the correct one, and a behavior change can hide inside a rename or a fix. The 300-line change has a single purpose, so every line is judged against the same requirement. Reviewability depends on the number of distinct purposes more than on line count.
Exercise
You staged a diff with git add -p, but some hunks were unrelated to the task. What happens to the hunks you declined, and what should you do with them?
Show answer
They stay in your working tree, unstaged and uncommitted. Inspect them and either discard them (for example with git restore -p) if they are scope creep, or keep them for a later, separate commit if they belong to a different task.