The loop — plan, prompt, diff, read, verify, commit
By the end of this lesson you will have run one full turn of the loop on the smallest change in the starter, the page heading, ending in a commit whose message says why, and the time that turn took.
Everything else in this course is an application of the six steps below. They are what separates building with an assistant from being driven by one.
plan → prompt → diff → READ → verify → commit small
↑ │
└──────────────────────────────────────────────────┘
Two rules hold the whole thing up:
Never commit code you do not understand. Secrets never enter code.
Everything below is machinery for keeping those two true while still moving fast.
plan — the smallest next thing
You wrote the project plan in unit 1. This one covers the next twenty minutes. "Add a remove button to each watchlist row." One outcome, one place, something you could check by looking.
Vague requests produce sprawling diffs. Sprawling diffs do not get read. Unread diffs are how you end up owning code you cannot change.
prompt — say the constraints, not just the goal
A good prompt carries the goal and the boundaries the assistant cannot infer:
Add a remove button to each row in
Watchlist.tsx. The list isWATCHLISTinsrc/lib/watchlist.ts— do not add a store. The server component stays server-only; if this needs client state, tell me before writing it rather than converting the file.
That last clause is the important one. You have asked it to surface an architectural decision instead of quietly making one. And here the decision is real: a button in a browser cannot edit a file in your repository, so removing a row means keeping the list somewhere else, which is a choice for you to make, not one for the agent to settle quietly. Assistants convert server components to client components all the time to make something work, and that is exactly the change that could drag your API key into the browser.
diff — never let it write straight to the file unseen
Whatever your cockpit, insist on seeing the change as a diff before it lands. In Claude Code's Manual mode or Codex's Read Only that is the approval prompt on every edit; in an editor's agent mode it is the inline review; in chat it is you pasting deliberately.
Once you move to a mode that edits without asking — accept-edits in Claude Code, Default in Codex — the diff you read is git diff before every commit, still a diff, read before it enters history. Claude Code's auto mode, which recent versions start in, applies edits without showing you; switch out of it while you are learning. Speed you cannot inspect is not speed.
READ — the step everyone skips
This is the one that makes you a programmer rather than a requester. Four questions, every diff, in this order:
- Did it change anything I did not ask about? Extra files, a new dependency, a reformatted function, a "while I was here" refactor. Every one of those is scope you did not choose.
- Does it touch data fetching? If yes, the key rule is in play. Where is the fetch happening, server or client? Did a
"use client"appear at the top of a file that reads the environment? - What happens when it fails? Generated code is reliably optimistic. Empty list, network error, a field that is
nullthis morning: pick one and find the line that handles it. Often there is no line. - Can I explain this to someone else? If the answer is no, you have a choice: ask the assistant to explain it, or throw it away. What you may not do is commit it.
A useful habit: ask for the explanation before you accept, not after. "Explain what this code does line by line, and tell me what happens if the API returns an empty array." The answer is often where the bug is.
verify — run it, and run the failure
Load the page. Then break it on purpose: an empty list, a ticker that does not exist, the dev server with the key removed. The happy path proves the code compiles; the failure path proves someone thought about it.
By the end of this unit, verify starts earlier and runs without you: you write what "working" means as a test before the code exists, and the agent runs npm test on every change. The last lesson of the unit sets that up.
commit small — the undo button you get for free
One logical change per commit, with a message saying why rather than what.
git add src/lib/quotes.ts
git commit -m "Check res.ok before parsing, so a 429 shows a message, not blank rows"
Not "update quotes.ts". The diff already says what changed; only you can say why.
This matters more with an assistant than without one. When a change three prompts ago turns out to be wrong, small commits let you take out exactly that one. One giant commit called "add watchlist" means your only undo is deleting a day.
And the second absolute rule lands here: Staging without looking is how keys get committed. Read git status before every git add, and stage only once the list holds just the files you meant to change. The starter's pre-commit hook refuses key-shaped strings, and it is a seatbelt, not a substitute for looking.
What this costs and what it buys
It is slower per change. Genuinely: reading a diff properly takes a few minutes.
It is much faster per project, because the alternative is not "fast", it is "fast until the first thing you cannot explain, then stuck". The loop is what keeps every line in your repository either understood or deliberately borrowed.
Try it now
The prompt
Run one full turn of the loop on the smallest thing you can find in the starter: change the page heading. Overkill on purpose, because you are practising the motion rather than the change. Write the one-line plan first: what the heading should say, and why. Mock mode on, manual mode, and paste, with your heading in place of the brackets:
Plan: the page heading should say what this tool is for. In
src/app/page.tsx, change the h1 text to "[your heading]" and nothing
else, except that if a comment beside it describes the old heading,
update the comment so it is true. The page stays a server component; if this needs client code,
stop and tell me why before writing anything. Show me the diff before
it lands. Then explain what the page would show if the heading were an
empty string. Spend no API calls. Afterwards run npm test and
npm run lint, show me the line of the npm test output that starts with
"Tests", and tell me whether npm run lint printed any error. If it did,
show me the fix before making it, then run npm run lint again.
A good answer is a one-line diff in one file (plus a comment line if one needed correcting), an honest sentence about the empty case — a heading element with nothing in it, which a screen reader still announces — a passing Tests line and a lint run with no errors.
A heading with an apostrophe in it ("Today's movers") is the common way to meet a lint error here: the rule react/no-unescaped-entities refuses a bare ' inside JSX text, and the pre-commit hook would refuse the commit for the same reason. The fix is to write it as ' or as the typographic apostrophe ’. That is verify doing its job on a one-line change.
Check it yourself
- The diff you approved changes one line, in
src/app/page.tsx, apart from a comment it may have corrected. git diff --statagrees: one file, with a line or two inserted and deleted.grep -n "use client" src/app/page.tsxprints nothing.npm run devin mock mode: your heading is at the top of the page. (Read the addressnpm run devprints on itsLocal:line; if port 3000 is busy it uses 3001.)- Time the turn, from the plan to the commit below. That is your baseline cost per turn.
Break it on purpose
Verify means running the failure too. Empty the WATCHLIST array, reload in mock mode, and read what the page says: it names the file to edit instead of drawing a table with nothing under the headings. That is a failure path someone thought about. Put the list back with git restore src/lib/watchlist.ts.
Compare with ours
Our diff
- <h1 className="text-lg font-semibold tracking-tight">Watchlist</h1>
+ <h1 className="text-lg font-semibold tracking-tight">What moved overnight</h1>
The message says why, because the diff already says what. The full state at the end of this unit is on the starter's branch ref/build-your-first-tool/u2.
Checkpoint
git status # only the files you expect, and no .env*
git add -A
git commit -m "Heading says what the page is for"
Then answer this lesson's questions.