Sub topic 5
Triaging the change set before reading any code
This chapter assumes you can use Git branches, commits, and diffs. It also assumes you have started the agent run from a clean baseline on its own branch, as covered in the previous chapter. Triage is the step between "the agent says it is done" and "I start reading hunks." You collect facts about the whole change set first, so that you decide where to spend your reading time.
Why triage comes first
A multi-file change can be 40 files and 1,500 changed lines. If you open the first file alphabetically and start reading, you spend your attention on whatever happens to sort first. You also read without knowing whether the change matches the task.
Triage answers four questions from metadata alone:
- Which files changed, and does that list match the task you scoped?
- How big is each change?
- Which files were added, deleted, renamed, or only had permissions changed?
- Which changes sit in areas that deserve extra suspicion, such as tests, configuration, dependency files, and generated files?
You are looking for mismatches between the scope you set and the footprint the agent left. A mismatch tells you where to look first. It does not tell you the change is wrong.
Step 1: See every file, including untracked ones
The most common triage error is trusting git diff as the full list of changes. By default, git diff compares the working tree to the index. It has two blind spots:
- It does not list untracked files, so new files the agent created are missing.
- It does not show changes you have already staged, and it does not show commits the agent made.
Start with git status, which covers new files, then add the diff views.
git status --short # includes new, untracked files
git diff --stat # size of change per file
git diff --name-status # added, modified, deleted, renamed
git diff --diff-filter=D --name-only # files the agent deletedIn git status --short, ?? marks an untracked file, M a modified one, and D a deleted one. Treat every ?? line as a file you have not yet seen in any diff.
If the agent committed its work, compare against the commit you noted at the start of the run. Replace BASE with that commit hash:
git diff --stat BASE HEAD
git diff --name-status BASE HEADIf the agent staged some changes, git diff HEAD --stat compares the working tree against the last commit and covers both staged and unstaged edits.
Making untracked files appear in the diff
To get new files into git diff output, mark them as intent-to-add. This records the path in the index without staging content, so later diff commands include the file's full contents.
git add -N .
git diff --statCheck git status --short before you run git add -N .. The command adds every untracked path that is not ignored, so you want to know what it will pick up.
Ignored files
.gitignore hides files from git status. An agent can create or modify ignored files such as a local .env, a cache directory, or build output. Normally these do not matter. If the task touched configuration or secrets handling, check them:
git status --short --ignoredStep 2: Compare the footprint to the task
Put the file list next to the task statement you wrote. Suppose the task was "rename the config loader function and update its callers." The expected footprint is the loader module, its callers, and its tests. Now read the actual list:
M src/config/loader.py
M src/app/main.py
M src/billing/invoice.py
M tests/test_loader.py
M requirements.txt
?? src/config/compat.pyThree entries do not follow from the task: src/billing/invoice.py, requirements.txt, and the new src/config/compat.py. You have not read any code, and you already have three questions to answer. These may have good explanations, such as a caller in billing that really needed updating. Each one still needs a reason before you accept it.
The table below lists common footprint signals and what to do about each.
| Signal in the file list | What it may mean | Next step |
|---|---|---|
| File outside the named modules | Scope creep, or a legitimate caller | Read that diff early and decide if it belongs |
| Dependency or lock file changed | New package added, version bump | Ask why; check the package exists and is wanted |
| Test file changed in a non-test task | Tests edited to fit the new code | Go to the test checks in the next section |
| Deleted file | Removed code or tests | Confirm that nothing still references it |
| Very large diff in one file | Reformatting, or a rewrite | Check with `git diff -w` |
| New file with a generic name such as `utils2.py` or `compat.py` | Duplicate helper, or a shim | Compare against existing helpers |
| Config, CI, or build file changed | Behavior change outside the code | Review closely, even if the diff is small |
Step 3: Read the size column
git diff --stat ends each line with a count and a bar of + and - characters. Look at proportions. A rename task should produce many small, similar changes. One file with 400 changed lines in a rename task is an outlier, and you should read it first.
Two edge cases distort the numbers:
- A formatter or line-ending change can inflate a file's diff. Run
git diff -w --statto ignore whitespace-only changes and see whether the size drops. - Code that moved between files appears as deleted lines in one file and added lines in another. Use
--color-movedwhen you read the diff, as in the next step.
git diff --color-moved=zebra # highlight moved code so real edits stand out
git diff -w # ignore whitespace-only changesStep 4: Check status letters and special cases
git diff --name-status gives one letter per file. A is added, M modified, D deleted, and R followed by a similarity score such as R087 is a rename. A rename with a score below 100 means the file was also edited. Read that edit as a modification, not as a pure move.
Two cases the stat output does not make obvious:
- Mode changes. An agent can change a file's executable bit by accident.
git diff --summarylists these asmode change 100644 => 100755. - Binary and generated files.
--statshowsBinfor binary files, with no content to read. Lock files, snapshots, and compiled output can be huge. Decide whether the agent should have touched them at all, and regenerate them with the project's own tool when you can instead of reviewing them by hand.
Deletions deserve their own look. A deleted test file or a deleted function can hide a behavior change, because the diff shows only red lines and no new code to draw attention. After listing deleted files, search for remaining references to them:
git diff --diff-filter=D --name-only
git grep -n "compat_loader" # replace with a deleted name from the listStep 5: Flag test and suppression changes
Before you read any implementation, look at whether tests changed and whether anything now silences a check. This is still triage, because you are only locating suspicious spots. The next chapters cover how to judge them.
git diff -- tests/
git diff -U0 | grep -nE '^\+.*(@pytest\.mark\.(skip|xfail)|# noqa|# type: ignore)'The -U0 option removes context lines, so the search sees only added and removed lines. The pattern matches added lines that skip or expect failure on a test, disable a lint rule, or suppress a type error. Adapt the pattern to your language. For example, use eslint-disable or @ts-ignore in a TypeScript project. A match is not proof of a problem. It is a spot to read closely.
Triage as a decision flow
The diagram shows the order of the checks and where each one sends you.
Writing the reading plan
End triage with a short written plan, even if it is three lines in a scratch file. For the earlier example, it might read:
- Read
src/billing/invoice.pyfirst: out of scope, find out why it changed. - Read
requirements.txtandsrc/config/compat.py: unrequested dependency and new file. - Read
tests/test_loader.pybefore the implementation: check whether a test was altered. - Then read the loader and its callers in the order covered in the next chapter.
The plan stops you from drifting into the most interesting file instead of the riskiest one.
Common triage errors
- Running only
git diffand missing new files. - Forgetting that a staged or committed change does not appear in a plain
git diff. - Reading files in alphabetical order instead of risk order.
- Ignoring deletions because they have no added code to read.
- Accepting a large diff in one file without checking
-wfor whitespace noise. - Skipping lock files and config files because they are tedious to read.
Exercise
You asked an agent to rename a function and update its callers. git diff --stat shows four modified files, and you are ready to start reading. git status --short also shows ?? src/config/compat.py and D tests/test_missing_file.py. Which two facts did the plain diff hide or understate, and what do you do about each before reading any implementation code?
Show answer
The new untracked file compat.py does not appear in git diff, so it needs to be read in full. Use git add -N . and check git diff, or open the file directly, and ask why a compatibility shim was created for a rename. The deleted test file shows that a test was removed. Check git diff --diff-filter=D --name-only, search for the test's subject with git grep, and restore the test if the deletion is not justified by the task. Both go on the early-read list.
Exercise
A change set shows R062 src/old_loader.py src/config/loader.py. How should you read it, and which command helps when the same diff also shows code moved between files?
Show answer
The score 62 means the file was renamed and also substantially edited, so review it as a modification, not as a pure move. Use git diff --color-moved=zebra to highlight moved blocks, and git diff -w to remove whitespace-only noise, so the real edits stand out.