Chapter 3 · 7 lessons
Superstar Practices
The habits that separate 10× from busy: spec-driven development, TDD with agents, parallel agents on worktrees, model routing and cost, debugging with evidence, and agents in CI.
Cursor · Claude Code · OpenAI Codex · GitHub Copilot
Show all 7 lessonsHide list
Lesson 1 of 7
Spec-Driven Development
The single biggest multiplier is not a tool — it is writing down what 'done' means before the agent starts. Agents are excellent at executing a clear spec and confidently wrong on a vague one. A spec turns a guessing game into a checklist the agent (and your reviewer) can verify.
spec.md WHAT and WHY: goal, users, constraints, acceptance criteria │ (you write or review this — 10 minutes) ▼ plan.md HOW: files, data model, risks (agent drafts, you approve) │ ▼ tasks.md small, ordered, independently testable steps │ ▼ implement one task per run / thread; tests first │ ▼ verify acceptance criteria → tests → diff review
| Spec section | Example |
|---|---|
| Goal | Users can export their study plan as a PDF from /study |
| Non-goals | No email delivery; no custom themes |
| Constraints | Server-side render; no new dependencies over 200 KB; reuse PlanCard |
| Acceptance criteria | Export button visible when plan has ≥ 1 task; PDF includes dates; works offline-cached |
| Test plan | Unit test for formatter; Playwright test clicks Export and checks download |
- GitHub Spec Kit and AWS Kiro popularized this flow (spec → plan → tasks); you can run it with plain Markdown in any tool
- Plan mode in Cursor, Claude Code, and Copilot produces the plan step for you — review it like a design doc
- Keep specs in the repo (docs/specs/) so cloud agents and teammates get the same input
Signal
'I spend ten minutes on acceptance criteria so the agent can spend an hour without me' is the sentence that separates agent drivers from chat users.
Lesson 2 of 7
TDD With Agents
Tests are the most reliable way to tell an agent what correct means — and the fastest way for you to verify it. The trick is ordering and protection: tests first, reviewed by you, then implementation that is not allowed to change them.
- Ask the agent to write failing tests from the acceptance criteria only — no implementation yet
- Run them, confirm they fail for the right reason, and review them (this is where your judgment matters most)
- Commit the tests
- Ask the agent to make them pass without modifying test files
- Protect test files with a hook or explicit instruction; re-run the full suite
Step 1: "Write failing Vitest tests for the acceptance criteria in
docs/specs/pdf-export.md. Do not implement anything.
Run them and show me the failures."
Step 2: (you review + commit tests)
Step 3: "Make the tests in tests/pdf-export.test.ts pass.
Do not edit any file under tests/. Run the full suite
before you finish."Failure mode
Agents that cannot make a test pass will often weaken the assertion, add a skip, or mock the thing under test. Look for that in every diff — or block it with a hook.
Lesson 3 of 7
Parallel Agents and Git Worktrees
Once tasks are small and specified, the bottleneck becomes you waiting. Top developers run two to four agents at once on independent tasks, each in its own working copy, and spend their time reviewing instead of watching.
git worktree add ../app-export -b feat/pdf-export git worktree add ../app-flaky -b fix/flaky-auth-test git worktree add ../app-docs -b docs/api-reference ~/app main (you review here) ~/app-export agent A → PR #1 ~/app-flaky agent B → PR #2 ~/app-docs agent C → PR #3 git worktree remove ../app-docs # after merge
| Option | Isolation | Best for |
|---|---|---|
| Git worktrees + local agents | Separate directory and branch per task | Tasks that need your local environment |
| Built-in parallel agents | Cursor and the Codex app manage worktrees for you | Comparing attempts or running a few tasks side by side |
| Cloud agents | Separate VM per task | Well-scoped tickets you want back as PRs |
- Only parallelize tasks that do not touch the same files — merge conflicts erase the gains
- Give each worktree its own dev-server port and database to avoid collisions
- Best-of-N: run the same hard task in two worktrees with different models or prompts and keep the better diff
- Your throughput is capped by review speed — keep PRs small
Lesson 4 of 7
Model Routing and Cost
Using the strongest model for everything is slow and expensive; using the cheapest for everything costs you rework. Route by task shape and track what you spend.
| Task | Model tier | Why |
|---|---|---|
| Codebase search, summarizing, renames | Fast / cheap | Mechanical; speed matters more than depth |
| Feature implementation from a clear spec | Default agent model | Balanced cost and reliability |
| Architecture, tricky bugs, security review | Strongest reasoning model | Mistakes here are the most expensive |
| High-volume CI jobs (triage, lint-fix) | Cheap with tight turn limits | Runs on every PR; cost multiplies |
- Most tools support per-agent or per-subagent model choice — use a cheap model for explorer subagents
- Cap turns and budgets in headless runs (for example --max-turns in Claude Code)
- Long sessions cost more per turn because context grows — fresh threads are also a cost control
- Review weekly usage dashboards; set team spend alerts
Refresher
Token math and caching are covered in the AI & FDE track's Production AI chapter and cost studio.
Lesson 5 of 7
Debugging With Evidence
Agents guess fixes fast and wrong when they lack runtime evidence. The superstar move is making the agent reproduce, instrument, and prove the cause before it touches the fix.
- Reproduce: a failing test or script that shows the bug on demand
- Hypothesize: list 2–3 candidate causes, each with a way to confirm or rule out
- Instrument: add targeted logs or breakpoints; collect the output
- Fix the confirmed cause only; keep the reproduction as a regression test
- Remove instrumentation; review the diff
| Tool help | How |
|---|---|
| Debug mode | Cursor's Debug mode is built around instrument → reproduce → fix |
| Browser evidence | Browser tools or Playwright MCP let the agent click through and read console errors |
| Logs and traces | Point the agent at the log file or trace ID instead of describing the error |
Red flag
A fix that adds a try/catch or a null check without explaining why the value was null is a symptom patch. Ask for the root cause.
Lesson 6 of 7
Agents in CI: Issue → PR → Review → Merge
Level 5 developers put agents into the delivery pipeline so the team benefits without anyone opening a chat window.
| Stage | Agent job | Options |
|---|---|---|
| Issue | Triage, label, ask for missing repro steps | claude-code-action, codex-action, Copilot |
| Implementation | Turn a well-specified issue into a PR | Copilot cloud agent, Cursor cloud agents (SDK/API), Codex cloud |
| Review | First-pass bug and security review on every PR | Copilot code review, Cursor Bugbot, claude-code-action review prompt |
| Fix-the-build | Read CI failure logs, propose a minimal fix PR | Headless claude -p / codex exec in a workflow |
- anthropics/claude-code-action@v1 takes a prompt plus claude_args (for example --max-turns and --allowedTools)
- openai/codex-action@v1 runs codex exec with a sandbox setting and a safety strategy
- Give CI agents least-privilege tokens and read-only tools unless the job must push
- Never let untrusted PR content drive an agent that holds write secrets
Starter kit
Copy-paste workflows for PR review with Claude Code and Codex are in the Starter Kit.
Lesson 7 of 7
Worked Example: A Bug Fix With TDD and Evidence
Bug report: 'Streak resets at midnight for users in Asia.'
you: fix the streak bug
agent: The issue is likely timezone handling. I've added a try/catch
and default to UTC if the date is invalid.
you: (merges) → bug persists; now errors are silently swallowedyou: Reproduce first: write a failing test for a user in Asia/Tokyo
completing a task at 23:30 and 00:30 local. Don't fix yet.
agent: tests/streak.test.ts: 1 failing — streak resets at 00:30 local.
Evidence: computeStreak() uses new Date().getDate() (server UTC).
you: commit tests. Now fix without editing tests/.
agent: Use the user's IANA zone via Intl; 1 file changed; suite 212 passed.
reviewer subagent: LGTM — also check the weekly summary job (same pattern).- Reproduction turned a guess into evidence (server-UTC date math)
- Tests were committed before the fix, so they could not be weakened
- A clean-context reviewer found a second instance of the same bug
Takeaway
Reproduce → prove → fix → keep the test. Never accept a try/catch as a root cause.