Reading a diff — the skill everything else rests on
By the end of this lesson you will have one change your agent made to fetch.js, read twice — as the agent proposed it and in git diff — with the four questions answered in writing before you accepted it.
A diff is what changed. Reading one is the single most valuable habit in this entire track, and it takes twenty minutes to learn.
What you are looking at
const rows = await res.json();
- const sorted = rows.sort((a, b) => a.close - b.close);
+ const sorted = [...rows].sort((a, b) => a.close - b.close);
return sorted;
Lines with - were removed, + added, and unmarked lines are context so you can see where you are. git diff shows it; every assistant shows something similar before it changes a file.
That particular change is real and matters: sort reorders the original array in place, so the version without the copy silently rearranges data other code was still using. Build Your First Tool finds it in generated code.
Four questions, every time
From Build Your First Tool, and worth starting now:
- Did it change anything I did not ask for? Generated diffs wander — a rename here, a reformatted block there. Each one is something you now own.
- Does it touch how data is fetched or stored? Those are the lines that can leak a key or cost you a hundred requests.
- What happens when it fails? Empty list, bad response, no network.
- Can I explain it? In one sentence. If not, do not accept it yet.
Small diffs are readable; large ones are not
A twelve-line diff gets read. A four-hundred-line diff gets skimmed and accepted, and skimming is the same as not reviewing.
So ask for one thing at a time. This is the actual reason behind "commit small" from lesson 4 — not tidiness, but that it keeps each change small enough to genuinely read.
Accepting is a decision
The moment you accept a change it is yours. Not the assistant's: nobody else will be answering for it, debugging it at 7am, or explaining it to whoever reads the repository next.
That framing is the difference between using an assistant well and being used by one.
Try it now
Ask your agent to change something in your fetch script (the prompt below asks it to parse the body only when the request succeeded) and before accepting, answer all four questions in writing. Then run git diff and read the same change in git's own format. Two views of one change, and you now read both.
The prompt
Start your agent in your course folder — claude or codex — press Shift+Tab until plan mode shows under the prompt, and paste:
Read fetch.js. Change nothing yet. It currently prints the address,
the status and the raw body. In three lines, tell me what you would
change so that a refused request still prints its status and the start
of its body, and a successful one parses the body as JSON and prints how
many bars came back and the date of the first, without crashing on
either. Keep the existing
labelled prints. Tell me how many requests to eodhd.com one
run of the script will make.
Approve the plan only if it names fetch.js alone and one request per run. The request uses the demo token, so it spends nothing from any account; on your own key from Build Your First Tool, it would be one call. Then answer the four questions before you approve the edit, and ask the agent to run node fetch.js once and show you the output.
A good answer changes a handful of lines around the parse and nothing else: no renamed variables, no reformatting, no new file. Wrapping the parse in an if or try moves the lines inside it one step to the right, and git diff shows moved lines as removed and added again: that is indentation, not a change you did not ask for. Your agent's version may be shaped differently from ours (a try, a check that the answer is a list) and still be right: the checks below are what count, not a match with our lines.
Check it yourself
- Before you approved anything,
git statusshowed no change: the first answer was a plan. git diff --statlistsfetch.jsand nothing else.- You can explain every line marked
+or-in a sentence, and none of them is a change you did not ask for. - Your four answers were written down before you said yes.
- Run normally,
node fetch.jsprints the number of bars and the date of the first. With a misspelled ticker it prints the status andForbiddenand does not crash with a SyntaxError.
Break it on purpose
Before you accept, tell the agent: also tidy the file up while you are at it. Watch whether the proposed diff grows — renamed variables, reordered lines, different quotes, and sometimes a print you asked it to keep quietly deleted or an extra process.exit(1) — and count the lines you did not ask for. A deletion of something you wanted is the most dangerous kind of extra. Refuse it, and ask again for the change alone. That growth is the first of the four questions, happening in front of you. Agents differ here: if yours keeps the diff small and tells you what it chose to leave alone, that is the answer you want, and the exercise is done once you have checked that its diff really is unchanged.
Compare with ours
Our diff, and our four answers
const body = await res.text();
-console.log("body:", body.slice(0, 120));
+if (!res.ok) {
+ console.log("request failed:", res.status, body.slice(0, 120));
+} else {
+ const bars = JSON.parse(body);
+ console.log(bars.length, "bars, the first on", bars[0].date);
+}
Nothing unrequested. It changes how the body is read, but sends no new request. A refusal now prints instead of throwing — and an empty list would make bars[0].date throw, which we wrote down to fix. In one sentence: it parses only a body the server called ok.
Checkpoint
git status # only the files you expect, and no .env*
git add -A
git commit -m "Parse only a body the server called ok; a refusal prints instead of throwing"
Then answer this lesson's questions.