Skip to content

Building with AI agents means implementing an accepted spec in small slices: the agent drafts a read-only plan, builds one slice at a time in an isolated worktree, and stops when the gates pass. The loop is the same in Claude Code, Codex, and Cursor; the codebase’s shape changes the context, blast radius, and checks.

This section is for developers who run the agent and tech leads who define what a finished change proves. You point the agent at a ticket in a 2-million-line monolith, and it rewrites a shared helper that 40 services import. Unit tests pass; the pull request is unreviewable. The guides below prevent that for each kind of system.

Your situationStart with
The agent cannot hold the codebase and edits code it has not readMillion+ LOC strategies
One change cascades across packages that build and release togetherMonorepo workflows
You must replace old code whose behavior nobody has written downLegacy modernization
A change spans services, queues, and repositoriesDistributed systems development
Consumers depend on an API contract the agent must not breakAPI development
The change needs a schema migration or a slow query fixedDatabase design and queries

A greenfield feature in a small, well-tested repository needs only the core build loop.

What stays the same in every build workflow?

Section titled “What stays the same in every build workflow?”

Every guide adapts this loop; the lifecycle build page adds a plan.md template and hooks.

  1. Start from an accepted contract: a spec.md with numbered requirements and acceptance tests that fail now. Without one, go back to plan and specify.
  2. Plan read-only. The agent maps the files and blast radius into plan.md. A named engineer accepts it before code changes.
  3. Slice the work. Each slice is one reviewable pull request that leaves the build green. Large and legacy codebases need smaller slices, not bigger prompts.
  4. Implement in isolation: one slice per worktree, so parallel sessions cannot collide. See running parallel agents in worktrees.
  5. Stop on the gates, not the agent’s word. Tests, types, lint, and section checks pass in CI, and the pull request carries an evidence bundle.

How do you start a build session in each tool?

Section titled “How do you start a build session in each tool?”

Commands checked against Claude Code 2.1.286 and Codex CLI 0.157.1; Cursor from its documentation on 2026-08-28.

Terminal window
# Terminal: plan without editing files
claude --permission-mode plan
# Terminal: implement the accepted plan in a new git worktree
claude --worktree pay-412-refunds

In an open session, /plan switches to plan mode; Shift+Tab cycles through the permission modes until plan mode is on. For many independent slices, the bundled /batch skill fans them out across worktrees. Before you push, run /code-review to review the diff locally.

How do you know a build is done without reading every line?

Section titled “How do you know a build is done without reading every line?”

Trust checks the agent cannot change; save human attention for decisions.

  • Acceptance tests failed before and pass now. A test that never failed proves nothing; see how strong is your oracle.
  • The agent cannot edit the oracle. CI rejects acceptance-test changes in an implementation pull request; see protecting the oracle.
  • Machines check structure. Types, lint, and architecture fitness functions catch layering breaks.
  • Each guide adds its own gate: contract tests for APIs, a migration dry run for databases, characterization tests for legacy code, affected-project builds for monorepos.
  • A second agent reviews, a human signs off. The engineer who accepted plan.md approves the pull request against that plan and its evidence; see reviewing an agent’s pull request.

What breaks in agent-driven builds, and how do you recover?

Section titled “What breaks in agent-driven builds, and how do you recover?”
FailureSignalRecovery
The agent edits code it never readChanges in files missing from plan.mdReject the pull request; rerun the blast-radius prompt and add the missed callers
One slice grows into the whole featureA pull request too large to reviewRevert to the last green commit; split the rest into new slices
Tests pass because the agent changed themTest files change in an implementation pull requestProtect acceptance tests in CI; rerun the slice in a clean worktree
Parallel sessions collideMerge conflicts or overwritten workOne slice per worktree and branch; merge in plan order
The plan turns out wrong mid-buildThe agent patches around a false assumptionStop, correct plan.md, and restart the slice in a fresh session