Module 7 · Scenario labs · Chapter 27
Scenario lab 2: Code Generation with Claude Code
- One small field, four layers: React form, API handler, repository data layer, tests beside the code.
- Each step is a decision: where conventions live, how work is shared, plan or direct, what CI checks.
- Shared setup beats personal setup. If CI cannot see a rule, the rule does not exist for the team.
The picture: a relay race. Every runner must hold the same baton, not a private copy.
One of the six official scenarios, drawn at random on exam day. It mixes domains. You should be able to:
- Lead domain: Domain 3, Claude Code Configuration and Workflows (20 percent). CLAUDE.md, path rules, commands, plan mode, CI use.
- Supporting domain: Domain 5, Context Management and Reliability (15 percent). Load the right context, in the right files, at the right time.
- Also touched: Domain 1 (agentic work across files), Domain 2 (tool access limits), Domain 4 (explicit review criteria and examples).
- For each choice, say why it fits and why the nearby options fail.
Harbor & Pine Outfitters is a made-up company. Owen Brandt owns the harbor-web monorepo and CI. Support wants a returns-reason field, to see why gear comes back.
- One developer adds it in a day. Tests pass on his laptop.
- CI fails on 6 files. His test style rule lives only on his machine, so the pipeline never saw it.
- Two reviewers spend a made-up 3 hours each redoing checks a clear setup would have caught in minutes.
The code was fine. The setup was private, partial and vague. This lab rebuilds it in the open.
- Decision 1: where the conventions live (chapter 13).
- Decision 2: how the repeatable work is shared (chapter 14).
- Decision 3: plan mode or direct edits (chapter 15).
- Decision 4: what the CI reviewer checks (chapters 16 and 17).
- Break-it lab: find three planted faults in the team setup.
- Worked example, then the final quiz, all in Scenario 2.
Next: where the conventions live.
Step 1: Put conventions where the whole team, and CI, can see them
Why this step: chapter 13 (CLAUDE.md hierarchy and path rules) is the base here. A rule in the wrong file helps one laptop only.
- Project
CLAUDE.md, checked intoharbor-web: stack, layer rules, how to run tests. Everyone and every CI run loads it. - Path rule in
.claude/rules/withpathsfrontmatter for test files: test style loads only when Claude touches a test. - Personal user file (
~/.claude/CLAUDE.md): fine for your own habits. Wrong home for team conventions.
Think of a shop noticeboard versus a note in one worker's pocket. The whole shift reads the board.
Where the picture breaks down:
- A noticeboard can go stale. Review the project file like code.
- Some pocket notes should stay private, such as editor habits.
# .claude/rules/tests.md (illustrative)
---
paths:
- "src/**/*.test.tsx"
- "src/**/*.test.ts"
---
Tests sit beside the code they test.
Name the case for the behaviour, not the method.
Cover the empty, invalid and happy path.
Quick check: where does the test convention belong?
Next: package the repeatable part as a command.
Step 2: Share the repeatable part as a command
Why this step: chapter 14 (Commands and skills) covers the repeatable slice of a job. Adding a field follows the same steps every time.
- Add the field to the form component.
- Add it to the API handler and its validation.
- Add it to the repository-pattern data layer.
- Add or update tests beside each changed file.
- Run the tests and report what changed.
That list becomes a project command in .claude/commands/, checked in like the rules. Anyone gets the same steps, order and checks.
# .claude/commands/add-field.md (illustrative)
---
description: Add one field across form, API, data layer and tests
argument-hint: [field-name] [field-type]
allowed-tools: Read, Edit, Grep, Glob, Bash
---
Add $1 ($2) in this order: React form, API handler,
repository data layer, then tests beside each file.
Run the test suite with Bash and report failures.
Note allowed-tools. The lab will test it: a command that cannot run the test runner cannot finish its own last step.
Next: plan first, because this change touches many files.
Step 3: Use plan mode when the change crosses layers
Why this step: chapter 15 (Plan mode and refinement) gives the rule. Direct edits suit a one-file fix. This change touches four layers.
- Plan mode first: Claude explores, lists the files, the order, and the risks. Owen reads and corrects the plan.
- Refine before code: the returns reason needs a fixed list of values, not free text. That decision is cheap in a plan, costly after edits.
- Then execute: approve the plan, run the command, watch the diff grow layer by layer.
Do this: predict before you reveal.
Rework across every layer already touched. One line in a plan ("fixed list of six reasons") would have prevented it. Plan mode pays when a wrong early choice multiplies across files.
Next: the picture, from plan to merged pull request.
Step 4: Follow the change from plan to merged pull request
Why this step: the exam tests the whole flow. Press Next to walk it.
- Plan mode lists every file across the four layers. Owen spots the fixed-list decision before any code exists.
- The shared command works in plan order: form, API handler, then the repository data layer. Project rules load throughout.
- Each changed file gets its test next door, in the style of the path rule scoped to test files.
- The CI reviewer checks the written criteria list, not a general feeling about the code.
- CI comments, tests pass, and a human approves. The machine advises, the person decides.
Next: what the CI reviewer should actually check.
Step 5: Give the CI reviewer criteria, not vibes
Why this step: chapters 16 (Claude Code in CI/CD) and 17 (Explicit criteria and few-shot) meet here. This reviewer once flagged too much, so developers ignored it.
- Write criteria as a checklist: field validated against the fixed list, test beside each changed file, no direct database calls outside the repository layer.
- Add a few examples: one passing snippet and one failing snippet per tricky criterion (few-shot).
- Drop the vague lines: "code looks clean" cannot be checked the same way twice.
Quick check: which CI instruction is checkable?
Worked example (all numbers made up): what the shared setup saves on this one change.
1. Files touched: 4 form + 3 API + 3 data layer + 4 test files = 14 files.
2. Without the command, a made-up 25 minutes of setup and test-style fixes per file batch, times 4 layers = 100 minutes.
3. With the command and rules loaded, made-up rework drops to 20 minutes total.
4. Saving: 100 - 20 = 80 minutes on one field.
5. The team ships a made-up 6 such changes a month: 6 x 80 = 480 minutes, or 8 hours a month.
The saving comes from shared files, not from anyone typing faster.
Next: the break-it lab, with three planted faults.
Step 6: Break-it lab, debug the team setup
Why this exercise: Scenario 2 rarely hands you a blank repo. It hands you a plausible setup with quiet faults.
Lab: Step 6 hands you a plausible harbor-web setup with three quiet faults. This lab runs in your browser and needs JavaScript enabled.
A habit worth copying: treat Claude Code config like code. Rules, commands and CI prompts go through pull request review, so a bad rule is caught like a bad function. Practice advice, not a measured statistic.
The Deployed Lab jobs page (snapshot 15 Nov 2026) lists 367 open FDE roles, median posted base about $243K, base pay only.
Mix-ups to avoid
- Personal file versus project file. Your user
CLAUDE.mdshapes your sessions only. Team conventions go in the repo. - Command versus skill versus rule. A rule loads by path, a command runs when invoked, a skill loads by relevance. Pick by trigger.
- Plan mode for everything. A one-line fix needs no plan. Plan mode earns its cost when a change crosses files or layers.
- More CI comments versus better criteria. A noisy reviewer gets ignored. Fewer, explicit criteria get acted on.
- allowed-tools as decoration. The list is enforced. If work needs the test runner, include the tool that runs it.
Chapter quiz
Five questions. Score 70% or more to mark this chapter complete.
Review this chapter in 5 minutes
Watch the whole chapter recapped: conventions in the repo, a shared add-field command, plan mode, and explicit CI criteria.
- Scenario 2 mixes domains: Domain 3 leads, Domain 5 supports, with touches of 1, 2 and 4.
- Team conventions live in the repo: project
CLAUDE.mdplus path rules withpathsfrontmatter. - A personal user file never reaches teammates or CI. That was planted fault 1.
- Repeatable multi-layer work becomes a shared command in
.claude/commands/. allowed-toolsmust cover every step, includingBashfor the test runner. Planted fault 2.- A rule with no
pathsfires everywhere. Planted fault 3. - Many files or layers means plan mode first, refine, then execute.
- CI review runs on explicit criteria with examples, not vibes.
- Made-up worked example: shared setup saved 80 minutes on one field, 8 hours over a made-up 6 changes a month.
Decision rule: for any Scenario 2 setup, ask three questions: can the team and CI load it, can it run every step it promises, and does it load only where it applies?
Independent exam preparation. Not affiliated with or endorsed by Anthropic.
Review
Glossary
- Project CLAUDE.md
- Checked-in instructions at the repo root that every session and CI run loads. Example: harbor-web layer rules.
- User CLAUDE.md
- Your personal instruction file, loaded only for you. Example: your own shorthand habits.
- Path rule
- A file in
.claude/rules/withpathsfrontmatter, loaded only for matching files. Example: test style for*.test.tsx. - Slash command
- A saved, named workflow in
.claude/commands/that anyone on the team can invoke. Example:/add-field. - allowed-tools
- The enforced list of tools a command or skill may use. Example: Read, Edit, Grep, Glob, Bash.
- Plan mode
- A mode where Claude explores and proposes steps before editing. Example: listing 14 files before the field change.
- Repository pattern
- Data access kept in one layer, so handlers never call the database directly. Example: the harbor-web data layer.
- CI reviewer
- Claude Code running in the pull request pipeline, commenting against set criteria. Example: flagging a reason outside the fixed list.
- Explicit criteria
- Review rules written so two runs reach the same verdict. Example: a test file beside every changed file.
- Few-shot example
- A worked example inside instructions that shows the wanted behaviour. Example: one passing and one failing snippet per criterion.
Next: "Scenario lab 3: Multi-Agent Research System".