Skip to content

Lesson 39 of 40AI at work

Capstone: The Full AI Workflow

Build one small feature end to end with Claude Code, from spec and plan to tests, review, pull request, CI and retro.

20 min read0/4 questions

Every lesson in this course taught one habit. This one puts them together on a single, realistic task, the way you would actually work on a team. The feature is small on purpose: a tag filter for the notes page of a Next.js app, so a user can click "work" and see only work notes. Small features are where sloppy AI habits do the most damage, because they feel too simple to plan, test or review. Follow each step, and notice which earlier lesson it comes from.

The workflow at a glance
  1. 1

    Spec

    Write what done means, in a few lines, before touching the tool.

  2. 2

    Context

    Make sure CLAUDE.md tells the agent how this repo works.

  3. 3

    Plan

    Plan mode: the agent reads and proposes, you approve or edit.

  4. 4

    Tests first

    Failing tests from the acceptance criteria.

  5. 5

    Small steps

    One slice at a time, green tests, commit.

  6. 6

    UI check

    A Playwright test proves the page works in a real browser.

  7. 7

    Review

    A reviewer subagent with fresh context reads the diff.

  8. 8

    Fix loop

    Fix real findings, rerun checks, stop when done is done.

  9. 9

    Ship

    Commit, pull request, AI review in CI, human approval.

  10. 10

    Retro

    Feed what you learned back into CLAUDE.md, skills and tests.

Step 1: write the spec

Before you open Claude Code, write down what you want. Not a novel: a goal, the acceptance criteria (testable statements that must be true when you are done), and what is out of scope. This is the lesson Prompting That Works applied to a whole feature: clear, specific, with the why.

specs/tag-filter.md
# Tag filter on /notes
 
Why: users with 200+ notes cannot find work notes quickly.
 
Acceptance criteria
- Each tag on the page is a button. Clicking it shows only notes with that tag.
- Clicking the active tag again shows all notes.
- Tag matching ignores case ("Work" matches "work").
- The active tag is in the URL (?tag=work) so the view can be shared.
- An unknown tag shows "No notes with this tag" instead of a blank page.
 
Out of scope: multiple tags at once, editing tags.

The out-of-scope line matters. Without it, an agent will happily build multi-tag filtering, a tag editor and a settings page. Remember from How LLMs Work that the model predicts a plausible continuation: if your request leaves room, it fills the room.

Step 2: check the project context

The model only knows what is in its context (Context Engineering). Open the repo's CLAUDE.md. If the project has none, run /init to generate a starter, then trim it. For this task it must at least say how to run tests and where things live:

CLAUDE.md
# Notes app
 
## Commands
- npm run dev / npm run test / npm run lint / npx playwright test
 
## Conventions
- Pure logic goes in src/lib, with unit tests next to it.
- Components are server components unless they need state.
- Search src/lib before writing a new helper.
 
## Gotchas
- Notes data comes from src/lib/notes.ts only. Do not fetch in components.

Keep it short: it loads into every session, so every line costs tokens on every turn (Tokens and Context, Token Budget). Start a fresh session for this feature with /clear so leftovers from earlier work do not crowd the context.

The repo, ready for AI work
  • notes-app/
  • CLAUDE.mdcommands, conventions, gotchas
  • specs/
  • tag-filter.mdthe spec from step 1
  • .claude/
  • settings.jsonpermission rules, hooks
  • agents/
  • code-reviewer.mdthe reviewer subagent
  • .github/
  • workflows/
  • claude.ymlAI review in CI
  • src/
  • lib/
  • filter-notes.ts
  • filter-notes.test.ts
  • app/notes/page.tsx
  • e2e/
  • tag-filter.spec.tsPlaywright check

Step 3: plan before you build

Start Claude Code in plan mode with claude --permission-mode plan, or press Shift+Tab until plan mode is on. In plan mode the agent reads and researches but changes nothing. Then:

Read specs/tag-filter.md. Explore how the notes page loads and renders notes.
Propose a plan: which files change, which tests you will add, and in what order.
Do not write code yet.

Read the plan like a code review. Does it put the filter logic in src/lib as CLAUDE.md asks? Does it reuse the existing notes loader? Did it invent anything out of scope? Press Ctrl+G to edit the plan in your editor if you want to change it directly. A two-minute correction here saves an hour of unpicking code later.

Quick check
The plan proposes a new useTagStore state library to hold the active tag. The spec says the tag lives in the URL. What do you do?
Need a nudge? A hint rules out a wrong answer.

Step 4: tests first

Approve the plan, switch out of plan mode, and ask for failing tests first (Testing with AI):

Write unit tests for filterNotes in src/lib/filter-notes.test.ts, one per acceptance
criterion that is pure logic. Run them and confirm they fail. Do not implement yet.

Then read the tests before anything else. Do they check real behaviour from the spec, or just whatever the code will happen to do? A test that only mirrors the implementation proves nothing. Here is the same idea in Python so you can run it: four tests written from the spec, a first attempt that misses one criterion, and a fix aimed only at the failure.

Python
# Step 1: the tests, written from the spec before any implementation.NOTES = [ {"title": "Standup", "tags": ["work"]}, {"title": "Groceries", "tags": ["home"]}, {"title": "Q3 plan", "tags": ["work", "planning"]},] def check(name, got, want): status = "PASS" if got == want else "FAIL" print(f"{status} {name}: got {got}") def run_tests(filter_notes): titles = lambda notes: [n["title"] for n in notes] check("no tag shows every note", titles(filter_notes(NOTES, None)), ["Standup", "Groceries", "Q3 plan"]) check("one tag filters", titles(filter_notes(NOTES, "work")), ["Standup", "Q3 plan"]) check("tag match ignores case", titles(filter_notes(NOTES, "Work")), ["Standup", "Q3 plan"]) check("unknown tag gives empty list", titles(filter_notes(NOTES, "travel")), []) # Step 2: a first attempt. Run the tests: one fails.def filter_notes_v1(notes, tag): if tag is None: return notes return [n for n in notes if tag in n["tags"]] print("first attempt")run_tests(filter_notes_v1) # Step 3: fix only what the failing test points at.def filter_notes_v2(notes, tag): if tag is None: return notes wanted = tag.lower() return [n for n in notes if wanted in (t.lower() for t in n["tags"])] print("after the fix")run_tests(filter_notes_v2)
Output
Press Run (⌘ Enter) to see what happens.

Step 5: build in small steps

Now ask for one slice at a time: "Implement filterNotes until the unit tests pass. Change nothing else." Then the page. Then the empty state. After each green slice, look at the diff and commit. Small commits give you safe points to return to, and small diffs are diffs you can actually read (Clean Code with AI).

If a step goes wrong, do not argue with the agent for ten turns. Press Esc to stop it, use /rewind to go back to a checkpoint, and after two failed corrections, /clear and write a better prompt. Long sessions full of failed attempts also fill the context with noise, which makes the next answer worse.

Step 6: check the UI in a real browser

Unit tests prove the logic. They do not prove that clicking a button on the real page works. Ask for an end-to-end test with Playwright, which drives a real browser:

e2e/tag-filter.spec.ts
import { test, expect } from "@playwright/test";
 
test("clicking a tag filters notes and updates the URL", async ({ page }) => {
  await page.goto("/notes");
  await page.getByRole("button", { name: "work" }).click();
  await expect(page).toHaveURL(/tag=work/);
  await expect(page.getByRole("listitem")).toHaveCount(2);
});

Run it with npx playwright test. A Playwright suite is repeatable and runs in CI. For a quick visual check during development, Claude can also drive Chrome (started with claude --chrome) to take screenshots and compare them against what you expect.

Step 7: a reviewer with fresh eyes

The session that wrote the code is the worst reviewer of it: its context is full of its own reasoning. Use a separate reviewer subagent with its own context window (Subagents and Orchestrators):

.claude/agents/code-reviewer.md
---
name: code-reviewer
description: Reviews code changes for bugs, security issues and duplication. Use after any code change.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior reviewer. Read the diff with `git diff`. Report only real problems...

Then: "Use the code-reviewer subagent on my changes, against specs/tag-filter.md." It reads the diff and the spec in its own context and sends back only a summary. If you keep writing the same kind of test by hand, that is a sign it should become a skill (Writing Skills), so the next feature gets it for free.

Match the pairs0/4 matched

Match each workflow step to the lesson it comes from.

Choose an item, then its match on the other side.

Step 8: the fix loop, with an exit

Now run the loop from The Build, Review, Test Loop: fix the reviewer's real findings, rerun lint, type check, unit tests and Playwright, review again. Two rules keep it from running forever:

  • A definition of done. Every acceptance criterion has a passing test, lint and types are clean, the reviewer has no remaining real issues, and the diff contains nothing out of scope.
  • A limit. If two rounds do not converge, stop and look yourself. The problem is usually the spec or the plan, not the code.

Hooks can make the checks automatic: a hook that runs after edits can format files, and a Stop hook that exits with code 2 can block the agent from declaring itself finished until the tests pass. Finish with /simplify or a request to remove anything unused, then read the final diff yourself, every line.

The fix loop
Build: one small sliceBuildone small sliceChecks: lint, types, testsCheckslint, types, testsReviewer: fresh contextReviewerfresh contextYou: read the diffYouread the diffPull request: CI + approvalPull requestCI + approvalrungreenfindingscleanapprove

Every slice runs the automated checks first. Red means back to build, no review needed yet.

1/5

Step 9: commit, pull request and AI review in CI

Ask Claude to commit with a message that explains why, then open a pull request that links the spec and lists how it was tested (it can use the GitHub CLI, gh, if you have it installed). Before pushing, check your permission rules: git push in the ask list means you approve that step explicitly.

On GitHub, a second AI review runs in CI. /install-github-app sets up the Claude GitHub App and a workflow using anthropics/claude-code-action@v1. Mention @claude in a PR comment to ask it a question or request a change. Check the official docs for the current workflow options. The CI review is another set of eyes, not a replacement for a human approval: a teammate still reads the PR and merges it.

Put it in order7 steps

Put the workflow in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

Step 10: the retro

After the merge, spend five minutes on a retro (retrospective: a short look back at what worked). Ask:

  • Where did the agent go wrong, and why? If it invented a helper that already existed, add "search src/lib first" to CLAUDE.md, if it is not there yet.
  • What did I repeat? A prompt you typed three times is a candidate for a skill or a subagent.
  • What did it cost? /usage shows cost and usage for the session. If a simple feature burned a lot of tokens, look for the cause: a huge file read, a long failed detour, a bloated CLAUDE.md (Token Budget).
  • What would have caught the bug earlier? Add that check: a test case, a lint rule, a hook.

The retro is what makes the next feature faster. Every fix to CLAUDE.md, every new skill and every new test is context the next session starts with.

Quick check
During review you found the agent wrote a new date formatter when src/lib/dates.ts already had one. What is the best retro action?
Need a nudge? A hint rules out a wrong answer.

That is the whole workflow, from spec to retro, on one feature. The wrap-up that follows steps back to the full course and shows the product side, building a feature that is itself AI, as one system.

Key terms
spec
A short written description of a feature: the goal, acceptance criteria and what is out of scope.
acceptance criteria
Testable statements that must be true for a feature to count as done.
plan mode
A read-only Claude Code mode where the agent researches and proposes a plan without changing files.
end-to-end test
A test that drives the real app, often in a browser, the way a user would.
definition of done
An agreed checklist that decides when a loop of fixes can stop.
pull request
A proposed change on GitHub that others review, and CI checks, before it is merged.
retro
A short look back after finishing work to decide what to change next time.