Skip to the lesson
CivOps AI Academy · F12Directing an AI Agent: Briefs, Checks First, and Reading the Change
0%

Chapter 1 · Session 3

Briefs, and the rules Claude Code works by

From now on Claude Code writes the code. Your job is to say what to build, decide before it starts how you will know it is right, and read what comes back. This chapter sets up what makes that job routine: a brief template, standing rules for how Claude Code proves its work and when it must stop, and the right answers to its permission questions.

30 min2 stepsOne pull request

By the end of this chapter you can

  • Name the five parts of a brief and say why the acceptance checks are written first.
  • Add the brief template and the working rules (proof, stopping, never weakening a check) in one pull request.
  • Answer permission prompts safely: which commands may be allowed for good, and which never.

A new job

Claude Code can write in an hour what took a week, and it will happily write the wrong thing in an hour too. It does not know your plant, it remembers nothing from last week unless it is written in the repository, and it will say it is done when it believes it is done. None of that is a reason not to use it. It is a reason to direct it well: a clear brief, checks written first, proof instead of summaries, and a person reading every change before it merges.

The directing loopYou write a brief and checks, the agent works on a branch, opens a pull request where the checks run, you read the change, then merge or rewrite the brief. Directing an agent is a loop; the brief improves each time roundYou writebrief + checksAgent workson its own branchPull requestchecks runYou readthe diff, in orderMergea person approvesnot right: rewrite the brief, say why, run againKeep every version of the brief with the pull request: it is the record of what you asked for.
The directing loop. Every change goes round it once. When the result is wrong, the fix is usually a better brief, not a longer conversation.

What a brief says

Anthropic's guidance for Claude Code puts it plainly: the more specific the instructions, the better the first attempt and the fewer corrections later [1]. Specific does not mean long. It means Claude Code can answer, from the brief alone: what outcome do you want, where are the edges, how will we both know it is done, and what proof should I bring back.

Anatomy of a briefA brief card with five parts from top to bottom: goal, context, acceptance checks written first, out of scope, and how to show it works. docs/briefs/01-status-page.mdGoalthe outcome, tied to the intentContextfiles to read, rules that standAcceptance checksgiven, when, then: fail firstOut of scopewhat must not be touchedHow to show itthe proof you want backWhat and whyProof, written firstWhere the edges areProof you want backShort: one pullrequest of workChecks you write first;the agent may not edit
Anatomy of a brief. Five parts, usually under thirty lines. The acceptance checks are yours, written before any code, and Claude Code may not change them.
PartSaysExample: brief 01, the status page
GoalThe outcome in plant words, and why it matters to the intentA /status page showing which version is live and when it was built, so anyone can tell after a deploy whether a change is live
ContextWhat to read first; rules that standdocs/INTENT.md, CLAUDE.md, the template, the home page (which already shows a build time)
Acceptance checks (written first)Numbered given, when, then lines. Each becomes a test that fails before the work and passes after itGiven the app is built, when I open /status, then I see the version from package.json
Out of scopeWhat must not be touched or addedNo sign-in, no database, no new packages, no change to existing tests or checks
How to show it worksThe proof you want back: commands, exit codes, check results, an address to opennpm test with its exit code; CI green on the latest commit; the preview address of /status
Vague and actionable briefsLeft: a vague request for a status page with no goal, limits or finish line. Right: the same request with a goal, checks written first, what is out of scope, and the proof wanted back. Vague"Add some kind of status pageso we can see what is goingon with the app. Make itnice."No goal you can testNo limits: may touch anythingNo way to know it is doneActionableGoal: /status shows the liveversion and when it was built.Checks first: version, commit,fixed build time, no secrets.Out of scope: sign-in, database,new packages, existing tests.Show: exit codes, CI green,the preview address.
Vague and actionable. The same request, written two ways. Only one can be checked.

Standing rules go in CLAUDE.md

Rules that apply to every brief go in CLAUDE.md once, not in every prompt [2]. The ones this session adds come straight from what went wrong while we built our own platform: an agent reporting "all tests pass" when they had not run, an agent retrying the same refused step for a day, and an agent going around a check it had been refused. Each rule below exists because of one of those.

Step 1

One prompt: the brief template and the working rules

15 minutes

Why

A template means every brief has the same five parts, so nothing important is left for Claude Code to guess. The working rules in CLAUDE.md then apply to every task without you repeating them: how to prove something works, when to stop, and that checks are never weakened. An allow list for read-only commands removes most of the permission questions, while Session 1's deny list still refuses the dangerous ones. One pull request does all three.

Do this

Terminal or PowerShell
cd ~/code/acme-platform && git switch main && git pull && claude
Paste into Claude Code
On a new branch setup/briefs, do three things and nothing else.

1. Create docs/briefs/TEMPLATE.md, a brief template with these headings and one line under each saying what goes there:
   - Goal: the outcome in plant words, and why it matters to the decision in docs/INTENT.md.
   - Context: the files to read first, and any rule that stands.
   - Acceptance checks (written first): numbered lines "Given ..., when ..., then ...". Each becomes a test that must fail before the work and pass after it.
   - Out of scope: what must not be touched or added.
   - How to show it works: the proof I want back (commands, exit codes, check results, an address to open).
   End it with: "One brief, one pull request. If the checks do not fit on one screen, split the brief."

2. Add a section "Working rules" to CLAUDE.md, keeping everything already there:
   - Before you say something works, show the exact command, its exit code and the last 20 lines of its output. Never pipe a test command into another command when reporting its result. If something could not run, say "could not run", not "passed".
   - A change is done when the checks on its pull request are green on its latest commit. Wait for them with gh pr checks --watch before reporting.
   - After two identical failures, stop. Tell me what failed (quote the error), what you tried, whether the cause is in our code or outside it, and what you need from me.
   - Never edit, skip, loosen or delete a test, a check, a limit or a CI step to make something pass, and never use a different command to do something you were refused. If you think a check is wrong, stop and explain; I decide.
   - Every new test must be shown failing before the change that makes it pass.
   - If anything you told me earlier turns out to be wrong, say so first.
   - To show what a branch changed, compare with git diff origin/main...HEAD (three dots).

3. In .claude/settings.json, keep every deny rule exactly as it is and add an allow list for these read-only and checking commands only: npm test, npm run lint, npm run typecheck, npm run build, npx tsc --noEmit, git status, git diff, git log, gh pr view, gh pr checks, gh pr diff.

Commit, push, open a pull request titled "Brief template and working rules", and show me the link.

You will see recreated screen

claude — acme-platform
☒ Create docs/briefs/TEMPLATE.md
☒ Add Working rules to CLAUDE.md
☒ Add allow list to .claude/settings.json
☐ Commit, push and open the pull request
⏺ Write(CLAUDE.md)
 - Before any task, read docs/INTENT.md. Every change must serve the decision written there.
+
+## Working rules
+- Before you say something works, show the exact command, its exit code and the last 20 lines…
+- After two identical failures, stop. Tell me what failed (quote the error), what you tried…
+- Never edit, skip, loosen or delete a test, a check, a limit or a CI step to make something pass…
1
⏺ Write(.claude/settings.json)
+ "allow": [
+ "Bash(npm test:*)", "Bash(npm run lint:*)", "Bash(npm run typecheck:*)", "Bash(npm run build:*)",
+ "Bash(npx tsc --noEmit:*)", "Bash(git status:*)", "Bash(git diff:*)", "Bash(git log:*)",
+ "Bash(gh pr view:*)", "Bash(gh pr checks:*)", "Bash(gh pr diff:*)"
+ ],
  "deny": [
  "Read(./.env)", "Read(./.env.*)", …
2
⏺ Bash(gh pr create --title "Brief template and working rules" …)
⎿ https://github.com/acme-ops/acme-platform/pull/6
⏺ Pull request #6 adds the brief template, a Working rules section in CLAUDE.md, and an allow list of read-only commands. The deny rules are unchanged (no lines removed). To check: open Files changed and look for red lines in .claude/settings.json; there should be none.3
Claude Code writes three files and opens the pull request. The deny list is untouched; only an allow list is added.
  1. Added below the Session 2 line, which stays.
  2. Only additions. Every deny line keeps a space in the margin: unchanged.
  3. It tells you how to check its claim. From now on, every report should.

Check it worked

Pull request #6 (your number may differ) changes three files: docs/briefs/TEMPLATE.md (new), CLAUDE.md and .claude/settings.json. In Files changed, settings.json has no red (removed) lines. Owner two approves and you merge.

Fastest path

After the merge, paste The pull request is merged. Switch to main and pull. Claude Code reads CLAUDE.md again at the start of every session, so the working rules apply from your next prompt in a new session.

If it goes wrong

The settings.json change removes or rewrites a deny rule

Say: Restore every deny rule exactly as it is on main. Only add the allow list. The deny rules are your guard rails from Session 1; adding an allow list never needs them changed.

CLAUDE.md is rewritten from the top, or grows long

Say: Keep everything that was in CLAUDE.md and only add the Working rules section. Keep it to rules; where a fact lives in a file, point to the file. We found six of ten areas listed in our own CLAUDE.md naming nothing that existed, because copied facts had drifted.

The allow list includes git push, rm, supabase or vercel

Say: Remove everything from the allow list except the commands I listed. Those commands change things; you want to be asked.

Permission prompts: what to answer

Claude Code asks before it runs a command that is not on the allow list, and before it edits files, unless you tell it otherwise [3]. It offers three answers. The deny list from Session 1 refuses the dangerous commands whatever you answer, but it cannot list everything, so the answer you choose still matters.

AnswerChoose it forExamples
1. YesAnything you are not sure of, and the first time you see a commandA command you do not recognise; an install
2. Yes, and don't ask againCommands that only read or check, or that only change your branch, which a pull request will show younpm test, npm run lint, npx tsc --noEmit, gh pr checks, gh pr create, git add, git commit
3. No, and tell Claude what to do differentlyAnything that deletes, rewrites history, touches main, the live database or keys, or installs something you did not ask forrm -rf, git reset --hard, git push --force, supabase db push or reset, vercel --prod, reading .env, npm install of an unknown package
Step 2

See your permission rules, and answer prompts the safe way

5 minutes

Why

Answering every prompt by hand is slow, and the temptation is to allow everything, which is unsafe. The safe middle is the allow list from Step 1, plus a few "don't ask again" answers for commands that cannot do harm, with the deny list refusing the rest. Seeing your rules once, and answering one real prompt, sets the habit.

Do this

Start a new session so it reads the merged rules, then type the command below. It lists the Allow and Deny rules; check the deny rules from Session 1 are all there, then press Esc.

Terminal or PowerShell
git switch main && git pull && claude
Type into Claude Code
/permissions

Then give it a harmless task that needs a command not yet on the allow list:

Paste into Claude Code
List the open pull requests in this repository with gh pr list, and tell me in one line each what they change.

You will see recreated screen

claude — acme-platform
> /permissions
Permissions · Allow · Ask · Deny
Allow: Bash(npm test:*) · Bash(npm run lint:*) · Bash(npx tsc --noEmit:*) · Bash(gh pr checks:*) · …1
Deny: Read(./.env) · Read(./.env.*) · Bash(git push origin main:*) · Bash(git push --force:*) · Bash(npx supabase db push:*) · Bash(npx vercel --prod:*) · …2
> List the open pull requests in this repository with gh pr list…
Bash command: gh pr list Do you want to proceed?
❯ 1. Yes
  2. Yes, and don't ask again for gh pr list commands in this project
  3. No, and tell Claude what to do differently (esc)
3
⏺ Bash(gh pr list)
⎿ no open pull requests in acme-ops/acme-platform
Your rules, then a real permission question. Listing pull requests changes nothing, so option 2 is safe.
  1. Commands it may run without asking: the list from Step 1.
  2. Commands it may never run, whatever you answer. All of Session 1's rules should be here.
  3. Option 2 here: it only reads. Answer 3 for anything that deletes, pushes to main, or touches the database or keys.

Check it worked

/permissions shows your allow list and every deny rule from Session 1, and you answered the gh pr list prompt with option 2.

Fastest path

Shift+Tab switches Claude Code to accepting file edits without asking. That is reasonable on a branch, because every edit reaches main only through a pull request you read; commands still ask. Press Shift+Tab again to switch back.

If it goes wrong

You chose "don't ask again" for something you should not have

Type /permissions, find the rule under Allow, and remove it. "Don't ask again" answers are saved for this project on your computer only, so nobody else is affected.

Claude Code asks to run something that would delete files, reset git or touch the live database

Choose 3 and say: Do not run that. Tell me what you are trying to achieve and the safest way to do it. If it was supabase db push or vercel --prod, the deny list should have refused it: check /permissions.

Claude Code is refused a command and tries another way to do the same thing

We hit this: an agent refused permission to open pull requests opened one through a different command. Choose 3 and say: You were refused that. Stop and ask me; never use a different command to do something you were refused. The working rule from Step 1 says the same.

Knowledge check

Which part of a brief is written before any code, and must fail first?

Knowledge check

Claude Code asks permission to run a command. Which is safe to answer "Yes, and don't ask again"?

References

  1. Anthropic: Claude Code best practices. https://www.anthropic.com/engineering/claude-code-best-practices
  2. Claude Code docs: Memory and CLAUDE.md. https://code.claude.com/docs/en/memory
  3. Claude Code docs: Settings and permission rules. https://code.claude.com/docs/en/settings

Chapter 2 · Session 3

Checks first: tests and CI on every pull request

A check that fails before a change and passes after it is the only proof that the change did what you asked. This chapter gives the platform a test runner and a GitHub check that runs lint, the type check and the tests on every pull request, proves the check can fail, and teaches you to read a change before you approve it.

30 min2 stepsOne pull request

By the end of this chapter you can

  • Add Vitest, npm test and .github/workflows/ci.yml in one pull request, and see the check go red, then green.
  • Ask for proof (commands, exit codes, check results), never a summary.
  • Read a change: Claude Code explains it against fixed questions; you confirm in the Files changed tab.

Why checks first

If a test is written after the code, it tends to describe what the code does rather than what you needed. Written first, it is your definition of done, fixed before anyone is tempted to bend it. This is test-driven development: write a failing test, make it pass, then tidy up [1]. With an agent it matters even more, because Claude Code can run the test, read the failure and try again many times on its own [2].

Checks firstThree steps in a loop: red, a check that fails; green, the agent makes it pass; tidy, clean up while it stays green. 1 Redyou write the check; it fails2 Greenthe agent makes it pass3 Tidyclean up; still greennext checkA check that fails before the change and passes after it proves the change did the job
Checks first. The check fails before the change (red) and passes after it (green). If it passes before the change, it proves nothing.

Three checks on every change

CheckWhat it catchesTool
LintCode patterns known to cause bugs, and code that is never usedESLint (npm run lint)
Type checkA value used as the wrong kind (a number where text was expected), a missing field, a misspelt nameTypeScript (npm run typecheck, which runs tsc --noEmit)
TestsThe behaviour you asked for: what a person sees, what is storedVitest (npm test) [3]

All three run on GitHub, on every pull request, where nobody can skip them [4]. The type check runs on its own as well as in the build because we learnt the hard way: our platform's live build was set to ignore type errors while CI checked them, twenty-one errors piled up, and CI failed on every push for weeks until everyone ignored the emails. Until Session 10 makes the check required, GitHub will still let a red pull request merge: owner two's rule is simple, never approve red.

Step 3

One prompt: a test runner, npm test, and the CI check

15 minutes

Why

Tests only protect you if they run on every change, on GitHub. Adding the runner and the check now, while the app is one page, takes minutes; adding them after there are twenty screens takes days. The prompt also makes Claude Code prove the check can fail, because a check that can never go red protects nothing, and we had checks like that.

Do this

Paste into Claude Code
Read node_modules/next/dist/docs/ first, in particular the guide on testing with Vitest: this version of Next.js differs from older guides.

On a new branch setup/tests-and-ci:

1. Set up Vitest as that guide describes, with an npm script "test" that runs every test once and exits (not watch mode). Add a first test, tests/home.test.tsx, that renders the home page and checks it shows "Acme Bottling platform".
2. Make sure package.json has a "lint" script (ESLint) and a "typecheck" script (tsc --noEmit), and that both pass. Fix any errors without using any, @ts-ignore, @ts-nocheck or eslint-disable; if you think one is needed, stop and ask me.
3. Add .github/workflows/ci.yml, named CI, with one job called checks that runs on every pull request and every push to main, on ubuntu-latest with Node 22: npm ci, then npm run lint, npm run typecheck and npm test as three separate steps, so a failure names which one.
4. Prove the check can fail. Push the branch and open a pull request titled "Tests and CI". Then push one commit that changes the test to expect "THIS SHOULD FAIL", wait with gh pr checks --watch, and show me it is red. Then revert that commit, push, wait, and show me it is green.

Report: the links to the red run and the green run, and the exact command, exit code and last 20 lines of npm test on your machine.

You will see recreated screen

claude — acme-platform
⏺ Read(node_modules/next/dist/docs/01-app/02-guides/testing/vitest.md)
⎿ Read 112 lines
1
⏺ Bash(npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths)
⎿ added 61 packages
⏺ Write(.github/workflows/ci.yml)
+name: CI
+on: { pull_request: {}, push: { branches: [main] } }
+jobs:
+ checks:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v5
+ - uses: actions/setup-node@v5
+ with: { node-version: 22, cache: npm }
+ - run: npm ci
+ - run: npm run lint
+ - run: npm run typecheck
+ - run: npm test
2
⏺ Bash(gh pr checks --watch)
⎿ CI / checks fail 38s (step: npm test)
3
⏺ Bash(git revert --no-edit HEAD && git push)
⎿ [setup/tests-and-ci 4c1d2e9] Revert "Prove CI fails"
⏺ Bash(gh pr checks --watch)
⎿ CI / checks pass 41s
⏺ Pull request #7. Red run (the deliberate failure): https://github.com/acme-ops/acme-platform/actions/runs/… Green run (after the revert): https://github.com/acme-ops/acme-platform/actions/runs/… npm test: exit code 0. Last lines: Test Files 1 passed (1) · Tests 1 passed (1).4
Claude Code reads the guide for this version of Next.js first, then shows the check failing on purpose before it passes.
  1. It read the docs shipped with your version of Next.js before writing any setup.
  2. Three separate steps, so a red check names lint, typecheck or tests.
  3. Red on purpose: proof the check runs your tests and can fail.
  4. Proof, not a summary: two run links and an exit code you can check.

Check it worked

Pull request Tests and CI shows a green CI check on its latest commit, and its Checks tab history has one red run before it. Claude Code's report has the exit code of npm test (0) and its last lines.

Fastest path

Asking for the red run in the same prompt saves a round trip later: you never have to wonder whether the check really runs your tests.

If it goes wrong

Claude Code says all tests pass, but the check on GitHub is red

Trust GitHub. Say: The CI check is red. Run gh pr checks, read the failed step's log, fix the cause, and wait for green before you report. Show me the exit code, not a summary. We recorded a run that printed npm: not found and, minutes later, a report of 1,326 tests passing.

The output looked green, but the exit code was not 0

A command piped into another (npm test | tail) reports whether the second command worked, not the tests. Our main branch went red this way. Say: Run npm test without piping it, and tell me its own exit code.

Typecheck fails on files you did not touch

Fix them now, in this pull request. Say: Fix every type error without any, ts-ignore or ts-nocheck. If one needs a decision, list it and stop. Never set the build to ignore type errors: that is how our CI stayed red for weeks.

The test still passed when it expected "THIS SHOULD FAIL"

The test is not testing the page: it may only check that a word appears in a file, or not be run at all. Say: The test passed when it should have failed. Find out why, fix it, and show me it red, then green. Our own guard tests once checked that a word was present, not that anything worked.

npm ci fails in CI with a lock file error

package-lock.json was not committed, or is out of date. Say: Run npm install, commit package-lock.json, push, and wait for the check.

Reading a change

Green means the checks passed. It does not mean the change is what you asked for, or only what you asked for. You do not need to read code line by line: read in a fixed order, riskiest first, and let Claude Code explain each file against fixed questions, then confirm its answers in GitHub's Files changed tab [5]. Google's published guidance for its own reviewers says the same: first whether the change does what was needed, then the details [6].

Reading order for a changeSix stacked bars, narrowing: the summary against the brief, the list of files changed, tests and checks, workflow, configuration and packages, migrations and access rules, then the code. Read a change in this order: the riskiest parts first, the code last1The summaryagainst your brief: did it do what you asked?2Files changedonly files the brief allows; three-dot diff3Tests and checksnothing removed, skipped or loosened4Workflow, config, packagesCI steps, settings, new dependencies5Migrations and accessfrom Session 5: RLS, rules, routes6The code itselfnow, knowing what it should do
Reading order. The parts that can do the most damage come first; the code itself comes last, when you know what it should do. Migrations and access rules join the list from Session 5.
  1. The summary against the brief. Did it do what you asked, all of it and nothing else? Anything it says it could not do is the most important line.
  2. The list of files changed. Every file should be one the brief allows. Compare only what the branch changed since it left main (three dots), or you will see everything main gained too.
  3. Tests and checks. Anything removed, skipped or loosened is the first thing to stop on.
  4. Workflow, settings and packages. CI steps, .claude/settings.json and new dependencies change only if the brief said so.
  5. The code, explained by Claude Code, and then the preview: the change, running, on your phone.
Red flags in a diffFive changed lines with a flag each: a test skipped, a CI step that can never fail, a route opened outside the matrix, an unknown dependency, an error swallowed silently. Five lines worth stopping fortests/status.test.tsx- it("shows the version", ...) + it.skip("shows the version", ...)a test was skipped.github/workflows/ci.yml+ run: npm test || truea step that can never failproxy.ts+ if (path.startsWith('/api/holds')) return next()a route opened outside the matrixpackage.json+ "left-pad-plus": "^0.0.3"an unknown new dependencyapp/api/holds/route.ts+ } catch { }an error swallowed silently
Red flags. Each of these has passed a green pipeline somewhere. Each is a reason to stop and ask.
Step 4

Read the change before you approve it

10 minutes

Why

This is the routine every later pull request goes through, done once on a change that is easy to understand. Claude Code answers fixed questions with the file and line for each; you check its answers against GitHub's own list of files. Two views that agree are worth more than one, and owner two reviews the same way before approving.

Do this

Paste into Claude Code
Explain pull request "Tests and CI" to me file by file, in plain English. Compare only what this branch changed since it left main (git diff origin/main...HEAD, three dots). Then answer each question Yes or No, with the file and line that shows it:

1. Is every changed file one I asked for? List any that are not.
2. Does ci.yml run lint, typecheck and tests as separate steps, on every pull request?
3. Does anything make a failing step pass anyway (|| true, continue-on-error, a skipped test, a test that only checks a word is in a file)?
4. Which new packages were added, who publishes each, and are they only used for testing?
5. Was any deny rule in .claude/settings.json changed?
6. Is anything you told me earlier in this session wrong? Say so first.

Do not change anything.
Open

https://github.com/acme-ops/acme-platform/pulls

Open the pull request, then Files changed. Check the file list matches answer 1, and open ci.yml to see the three steps.

You will see recreated screen

claude — acme-platform
⏺ Nothing I told you earlier was wrong. 1 Yes. Six files: package.json, package-lock.json, vitest.config.mts, tests/home.test.tsx, .github/workflows/ci.yml, tsconfig.json (adds the test types). 2 Yes. ci.yml lines 12–14: three separate steps; on: pull_request (line 2). 3 No. No || true, no continue-on-error, no skipped tests. The home test renders the page. 4 vitest, @vitejs/plugin-react, jsdom, @testing-library/react and /dom, vite-tsconfig-paths: all in devDependencies, used only by tests. 5 No. .claude/settings.json is not in this pull request.1
Six answers, each with the file that shows it.
  1. Question 3 is the one that matters most: a check that cannot fail is worse than none, because it looks like protection.

You will see recreated screen

github.com/acme-ops/acme-platform/pull/7/files
ConversationCommitsChecksFiles changed
1
FileChange
.github/workflows/ci.yml+18
package.json+9 −1
package-lock.json+1,214 −2
tests/home.test.tsx+11
tsconfig.json+1 −1
vitest.config.mts+10
The same pull request on GitHub. The file list is GitHub's, not Claude Code's: they must agree.
  1. Six files, as Claude Code said. package-lock.json is long because it records every installed package exactly: read package.json instead.
  2. Green on the latest commit. Check the time: it should be after the revert.

Check it worked

Question 3 and question 5 are No, and the Files changed list matches answer 1. Owner two reads the same and approves; you merge.

If it goes wrong

The pull request seems to change hundreds of files you never asked about

You are probably comparing with today's main using two dots, which shows everything main gained too. Use the Files changed tab, or say: Show me only what this branch changed, with git diff origin/main...HEAD (three dots).

Question 3 finds || true, continue-on-error or a skipped test

Stop. Say: Remove it. A check that cannot fail protects nothing. If a step fails, fix the cause or tell me why.

A red check seems to have nothing to do with the change

It may have run on an old commit. Say: Which commit did this check run on, and is it behind main? If so, merge origin/main into the branch (no rebase, no force push), push, and wait for the new run. We had agents chase old red checks for hours.

Claude Code calls a warning a false positive and offers to silence it

Say: Check that warning on its own and show me the evidence. On our platform, a whole group of security warnings dismissed as false positives hid routes that returned customer staff details to anyone.

Knowledge check

A new test passes before any change has been made. What does that tell you?

Knowledge check

Claude Code reports "all tests pass". What do you ask for?

References

  1. Martin Fowler: Test Driven Development. https://martinfowler.com/bliki/TestDrivenDevelopment.html
  2. Anthropic: Claude Code best practices. https://www.anthropic.com/engineering/claude-code-best-practices
  3. Next.js Docs: Setting up Vitest with Next.js. https://nextjs.org/docs/app/guides/testing/vitest
  4. GitHub Docs: Workflow syntax for GitHub Actions. https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions
  5. GitHub Docs: Reviewing proposed changes in a pull request. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request
  6. Google Engineering Practices: How to do a code review. https://google.github.io/eng-practices/review/reviewer/

Chapter 3 · Session 3

One brief, end to end: the status page

Now the whole routine on a small, real change: a /status page that shows which version is live and when it was built. You commit the brief, Claude Code writes the tests and shows them failing, then builds until they pass and brings proof, and you read the change and open it on your phone before it merges.

40 min4 stepsEnds with a gate

By the end of this chapter you can

  • Commit a brief before any code, using the template.
  • Have the acceptance checks written as tests and shown failing, then passing, without the tests changing.
  • Stop an agent going in circles, refuse a weakened check, and read the change and the preview before merging.

Why a status page? After every deploy, someone will ask whether their change is live. A page that shows the version, the commit and the build time answers in five seconds. From Session 11, when deploys and rollbacks become routine, it is the first page you open. And it is small enough that every part of the routine is easy to see.

Step 5

Write brief 01 and commit it before any code

10 minutes

Why

The brief is your definition of done, written before anyone is tempted to bend it. Committing it first means the pull request will show the brief, then the failing tests, then the code, in that order, so anyone reading it later can see what was asked and whether it was delivered. The brief is written for you here; read each part, and change anything that is not right for your plant.

Do this

Paste into Claude Code
On a new branch brief/01-status-page, create docs/briefs/01-status-page.md with exactly the text below, commit it, and stop. Do not write any code or tests yet.

# Brief 01: status page

## Goal
A page at /status that shows which version of the platform is live and when it was built, so that after any deploy anyone at Acme Bottling can tell in five seconds whether a change is live.

## Context
Read docs/INTENT.md, CLAUDE.md, docs/briefs/TEMPLATE.md and the home page (app/page.tsx), which already shows a build time.

## Acceptance checks (written first)
1. Given the app is built, when I open /status, then I see the version number from package.json.
2. Given the app was built on Vercel, when I open /status, then I see the first 7 characters of the commit it was built from; built anywhere else, it says "local".
3. Given the app was built at a certain time, when I open /status twice a minute apart, then both show the same build time, in UTC, as YYYY-MM-DD HH:MM UTC.
4. Given a secret environment variable is set, when I open /status, then its value appears nowhere on the page.

## Out of scope
No sign-in, no database, no new packages, no change to the home page or to any existing test or check.

## How to show it works
- Each acceptance check is a test in tests/status.test.tsx, shown failing before the page exists.
- npm test: the exact command, its exit code and the last 20 lines.
- The CI check green on the pull request's latest commit.
- The Vercel preview address of /status.

You will see recreated screen

claude — acme-platform
⏺ Bash(git switch -c brief/01-status-page)
⎿ Switched to a new branch 'brief/01-status-page'
⏺ Write(docs/briefs/01-status-page.md)
+# Brief 01: status page
+## Goal
+A page at /status that shows which version of the platform is live and when it was built…
+## Acceptance checks (written first)
+1. Given the app is built, when I open /status, then I see the version number from package.json.
1
⏺ Bash(git add docs/briefs/01-status-page.md && git commit -m "Brief 01: status page")
⎿ 1 file changed, 27 insertions(+)
⏺ Committed the brief on brief/01-status-page. No code or tests yet, as asked.2
One file, one commit, and it stops: exactly what was asked.
  1. Your text, saved as it is. If Claude Code "improves" it, ask it to save exactly what you gave.
  2. It stops. The next step is the tests, not the page.

Check it worked

The branch has one commit with one file, docs/briefs/01-status-page.md, and Claude Code says it wrote no code or tests.

Fastest path

For your own briefs later, write a paragraph in plain words and ask: Fill docs/briefs/TEMPLATE.md from this as docs/briefs/NN-name.md and show me; do not write code. Then rewrite the acceptance checks in your own words: they are the part that must be yours.

If it goes wrong

Claude Code starts writing the page as well

Say: Stop. Undo everything except the brief. Tests come next, then code. On a branch nothing is lost.

You are not sure an acceptance check can be tested

Ask: For each acceptance check in brief 01, tell me how a test would prove it, and whether any check cannot be tested as written. Do not write the tests yet. Rewrite any check it says cannot be tested.

Step 6

Checks first: the tests, shown failing

10 minutes

Why

Tests shown failing before the page exists prove two things: the tests really run, and they really look for the page. Only then does "passing" later mean something. One of our own checks reported "present" for every page for weeks, real or not, because nobody had ever seen it say "absent". A test that has never failed has never been tested.

Do this

Paste into Claude Code
Read docs/briefs/01-status-page.md. Write its four acceptance checks as tests in tests/status.test.tsx, one test per check, each named after its check. Test what a person would see on the page, not whether a word appears in a source file. For check 4, set a made-up variable such as SUPABASE_SERVICE_ROLE_KEY=made-up-value-must-not-show inside the test, and check the page does not contain it. Do not create the page or change anything else.

Run npm test and show me the exact command, its exit code and the last 20 lines. All four new tests must fail because /status does not exist yet, and the home page test must still pass. Then commit the tests, push the branch, open a draft pull request titled "Brief 01: status page", wait for the CI check (it should be red), and show me the link.

You will see recreated screen

claude — acme-platform
⏺ Bash(npm test)
⎿ FAIL tests/status.test.tsx > 1. shows the version number from package.json Error: Failed to resolve import "@/app/status/page" Test Files 1 failed | 1 passed (2) Tests 4 failed | 1 passed (5)
1
⏺ Command: npm test. Exit code 1. All four status tests fail because app/status/page.tsx does not exist. The home page test passes.2
⏺ Bash(gh pr create --draft --title "Brief 01: status page" …)
⎿ https://github.com/acme-ops/acme-platform/pull/8
⏺ Bash(gh pr checks --watch)
⎿ CI / checks fail 36s (step: npm test)
3
Four red tests, failing for the right reason, and a red check on GitHub. That is success at this step.
  1. The reason is the missing page, nothing else. A typo or a missing package would be the wrong red.
  2. Exit code 1: failure, stated plainly, with the command.
  3. Red on GitHub too, at the tests step, not lint or typecheck.

Check it worked

The draft pull request is red, the failing step is npm test, and Claude Code showed exit code 1 with four failing tests named after your four checks.

If it goes wrong

A new test passes before the page exists

It is not testing the page. Say: Test N passes without the page. Rewrite it so it can only pass when /status shows what the brief asks, and show me it failing.

The tests fail for the wrong reason (a typo, a missing package, a configuration error)

A test must fail because the feature is missing, nothing else. Say: Show me the first error of each failing test. Fix any failure that is not caused by the missing page, then show me again.

Claude Code says the page cannot be tested because it is an async Server Component

Next.js's own Vitest guide says Vitest does not yet support async Server Components. Say: Keep the page a synchronous component that reads a small build-information module, and test the page through it. Do not change the brief's checks.

Claude Code asks you for a real key to test check 4

Never give one. Say: Use a made-up value inside the test. No real key is ever needed in a test.

Step 7

Let Claude Code build it, and ask for proof

10 minutes

Why

Now Claude Code has a target it can check itself against, as many times as it needs, without you. The prompt forbids touching the tests, tells it to read this version's Next.js docs before writing a page, and asks for proof against the brief's "How to show it works". When it reports, you have evidence, not a claim.

Do this

Paste into Claude Code
Now make the tests in tests/status.test.tsx pass by building the /status page as brief 01 describes. Do not change any test, check or CI step; if you think a test is wrong, stop and tell me why.

Before you write the page, read node_modules/next/dist/docs/ on how this version of Next.js renders pages at build time and reads environment variables, so the build time is fixed when the app is built, not when the page is opened.

Then run npm run lint, npm run typecheck and npm test, and show me each command's exit code. Mark the pull request ready for review, wait for the CI check with gh pr checks --watch, and give me the Vercel preview address of /status. Report against each line of "How to show it works" in the brief.

You will see recreated screen

claude — acme-platform
⏺ Read(node_modules/next/dist/docs/01-app/02-guides/environment-variables.md)
⎿ Read 260 lines
1
⏺ Read(node_modules/next/dist/docs/01-app/01-getting-started/08-caching.md)
⎿ Read 310 lines
⏺ Write(app/status/page.tsx)
+// Rendered once, when the app is built: the time shown is the build time.
+export default function StatusPage() {
+ const info = buildInfo();
+ return (<dl><dt>Version</dt><dd>{info.version}</dd> …
⏺ Bash(npm test)
⎿ Test Files 2 passed (2) Tests 5 passed (5) exit code 0
2
⏺ Bash(gh pr checks --watch)
⎿ CI / checks pass 44s Vercel – Preview pass
⏺ How to show it works: 1. Tests: four in tests/status.test.tsx, red in commit 3e5a1f0, green now; the file is unchanged since 3e5a1f0. 2. npm test: exit code 0, 5 of 5 passed (lint 0, typecheck 0). 3. CI: green on the latest commit, 9f8e7d6. 4. Preview: https://acme-platform-git-brief-01-status-page-acme-ops.vercel.app/status3
Built against the tests, then proof for each line of the brief.
  1. Reads the docs for your version before writing the page.
  2. An exit code with the result, for every command.
  3. Proof line by line against the brief, including that the tests did not change.

Check it worked

CI is green on the latest commit, Claude Code gave an exit code for each command, and it says the test file is unchanged since the red commit (Step 8 checks that for yourself).

Fastest path

For anything bigger than this, start in plan mode (Shift+Tab until it says plan mode): Claude Code reads and writes a plan, then waits for your yes. Two minutes reading a plan catches a misunderstanding before it is two hundred lines of code.

If it goes wrong

The same error, the same "let me try again", three times or more

Press Esc to interrupt, then paste: Stop. Do not try again yet. Tell me what exactly failed (quote the error), what you have already tried, whether the cause is in our code or outside it (a service, a permission, another change), and what you need from me. Repeating a step and not knowing when to stop are the commonest agent failures; our own agents once spent a day rebuilding the same refused commit.

CI is green, but the change includes the test file

Stop. Say: You changed tests/status.test.tsx. Restore it exactly as it was in the red commit and make the page pass the original tests. If you believe a test is wrong, explain why and wait. Changing the check to reach green is how an agent "finishes" work it has not done.

Claude Code says it is done, with no exit codes or check result

Say: Show me the exact commands, their exit codes and the last 20 lines, and the result of gh pr checks on the latest commit. If something could not run, say could not run.

The build time changes every time you reload the preview

The page is being drawn on every visit, so it shows the time of the visit. Check 3 should have caught this, so the test is too weak. Say: Check 3 passed, but the preview shows a new time on every reload. Make the test catch this, show it failing, then fix the page.

You will see recreated screen

claude — acme-platform
⏺ Bash(npm run build)
⎿ Error occurred prerendering page "/status"
⏺ Let me try a different approach…
⏺ Bash(npm run build)
⎿ Error occurred prerendering page "/status"
1
(you press Esc)
> Stop. Do not try again yet. Tell me what exactly failed (quote the error), what you have already tried, whether the cause is in our code or outside it, and what you need from me.
⏺ The build refuses because the page reads the current time while it is meant to be rendered once. I tried two ways of reading the time; both run per request. The cause is in our code. I need nothing from you: the docs say to compute the time when the app is built and pass it in. Shall I do that?2
Stopping a circle. Interrupt with Esc, then ask for a diagnosis instead of another attempt.
  1. The second identical failure: the working rule says stop here. If it does not, you stop it.
  2. A diagnosis, not another attempt. Now you can decide.
Step 8

Read the change, try it on your phone, merge

10 minutes

Why

Green means the tests passed; it does not mean the tests are the ones you approved, or that the page works where people will use it. Checking the test file is byte for byte the one that was red, and opening the preview on a phone, take five minutes and close the two ways a green change can still be wrong.

Do this

Paste into Claude Code
Review pull request "Brief 01: status page" for me. Compare only what this branch changed since it left main (git diff origin/main...HEAD). Answer Yes or No, with the file and line:

1. Does each acceptance check in the brief have a test, and does each test check what a person sees on the page?
2. Is tests/status.test.tsx exactly the same now as in the commit where the tests were red? Show me git diff between that commit and HEAD for that file.
3. Is every changed file covered by the brief? List any that are not.
4. Is anything outside the brief's scope added: sign-in, a database, new packages, changes to the home page or to CI?
5. Could the page ever show the value of a secret, and which test proves it cannot?

Do not change anything.
Open

https://github.com/acme-ops/acme-platform/pulls

Open the pull request. In Files changed, check the list matches answer 3. Then open the Vercel bot's preview link on your phone and add /status to the address.

Reload the preview after a minute: the build time must not change. The commit shown must match the latest commit on the pull request. Then owner two approves, you merge, and when Vercel has deployed main, open the live page:

Open

https://acme-platform.vercel.app/status

Your live status page. The commit should match the merge commit on main.

You will see recreated screen

https://acme-platform-git-brief-01-status-page-acme-ops.vercel.app/status
Acme Bottling platform — status
Version0.1.01
Commit9f8e7d62
Built2026-10-14 10:27 UTC3
The preview on a phone. Reload it: the build time stays the same.
  1. From package.json.
  2. The first 7 characters of the commit this preview was built from: compare with the pull request.
  3. The build time in UTC. If it changes on reload, the page is not doing what check 3 asks.

You will see recreated screen

github.com/acme-ops/acme-platform/pull/8
Brief 01: status page #8
ConversationCommitsChecksFiles changed
1
CommitMessageCI
a41b7c2Brief 01: status page–
3e5a1f0Acceptance tests for brief 01 (failing)✗
9f8e7d6Status page: version, commit, build time✓
vercel botPreview: Ready · Visit Preview
Merge pull request
The pull request, ready to merge: the brief, the red tests and the page are three commits, in that order.
  1. The record of the routine: brief, then red, then green. Anyone can read what was asked and see it delivered.
  2. Owner two approved after reading the same answers and the preview.

Check it worked

https://acme-platform.vercel.app/status shows the version, the commit of the merge on main, and a build time that does not change when you reload.

If it goes wrong

Answer 2 shows the test file changed after it was red

Do not merge. Go back to Step 7's second fix: restore the test, then make the page pass it. If the test really was wrong because the brief was wrong, change the brief first, in its own commit, so the record shows why.

The live page still shows the old commit after the merge

Vercel may still be building, or a newer merge replaced the deploy (it shows Canceled, which is not a failure). Wait for Ready at https://vercel.com/acme-ops/acme-platform, then reload. Comparing the commit on /status with main is exactly what the page is for.

The preview asks you to sign in to Vercel

That is Vercel's Deployment Protection, on by default for previews (Session 1). Sign in with your company Vercel account. A 401 from a preview is Vercel's protection, not a fault in your page.

Before you go on · Session 3 is done whenTick each one

Knowledge check

CI turned green and the diff shows a test assertion was loosened. What do you do?

Knowledge check

Claude Code has failed the same way twice and says "let me try again". What is the best next step?

References

  1. OWASP Gen AI Security Project: Top 10 for LLM Applications. https://genai.owasp.org/llm-top-10/
  2. Vercel Docs: Environments and preview deployments. https://vercel.com/docs/deployments/environments
  3. Vercel Docs: System environment variables. https://vercel.com/docs/environment-variables/system-environment-variables
  4. Claude Code docs: Common workflows. https://code.claude.com/docs/en/common-workflows

Chapter 4 · 12 questions · 80% passes

Final assessment

Twelve questions across the session. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. Which five parts does the brief template (docs/briefs/TEMPLATE.md) have?
2. Where do rules that apply to every brief belong?
3. When are a brief's acceptance checks turned into tests?
4. A new test passes before the page it tests exists. What is wrong?
5. Claude Code reports "all 1,326 tests passed". What makes that believable?
6. Why should a test command not be piped into another command (npm test | tail) when reporting its result?
7. What does .github/workflows/ci.yml run from Session 3 on?
8. Which permission prompt should you answer "No, and tell Claude what to do differently"?
9. Claude Code has failed the same way twice and wants to try again. What do you do?
10. The pull request is green, but a test was changed to it.skip. What now?
11. A pull request seems to change hundreds of files you never asked about. What is the likely cause?
12. Why can prompt injection not be fixed by a better brief alone?