# Build with agents: the workflow for your codebase

URL: https://developertoolkit.ai/en/workflows/build/
Description: Build with Claude Code, Codex, or Cursor: choose the workflow for your codebase shape, then plan read-only, slice changes, and stop on automated gates.

Building with AI coding agents turns an accepted specification into small, independently verified slices: the agent drafts a read-only plan, implements one slice per isolated worktree, and stops only when deterministic gates pass. Developers run the loop and tech leads define what finished code must prove across the Loop and Graph stations.

Point an agent at a two-million-line monolith without boundaries and it rewrites a shared helper imported by forty services. Local tests pass while downstream consumers break and the pull request outgrows human review. Codebase shape dictates context selection, slice size, and verification gates.

## Choose your build workflow

| Codebase constraint | Start with |
| --- | --- |
| Millions of lines where agents miss distant callers | [Million+ LOC strategies](/en/workflows/build/large-codebases/) |
| Undocumented legacy code moving to a new architecture | [Legacy modernization with agents](/en/workflows/build/legacy-modernization/) |
| Small, well-tested repo needing the baseline loop | [The lifecycle build workflow](/en/method/lifecycle/build/) |
| Parallel slices colliding on branches or local ports | [Git worktrees for parallel agents](/en/workflows/harness/git-worktrees/) |
| Slow, flaky, or undocumented verification commands | [Making a codebase agent-ready](/en/workflows/harness/agent-ready-codebase/) |

## The five-step build loop

1. **Start from an accepted contract.** Require numbered acceptance criteria and failing tests before application edits; see [plan and specify](/en/workflows/plan/).
2. **Plan read-only.** Map affected files, public contracts, and untested callers; a named engineer approves before edits start.
3. **Slice for reviewability.** Keep each pull request small and green; larger codebases require smaller slices, never longer prompts.
4. **Isolate each slice.** Run one slice per worktree or isolated environment; see [ephemeral environments](/en/workflows/harness/ephemeral-environments/).
5. **Stop on gates.** Tests, strict types, linters, architecture checks, and an [evidence bundle](/en/workflows/ship/evidence-bundle/) decide completion.

## Running the loop across tools

- **Claude Code:** Plan read-only, isolate slices in worktrees or subagents (`.claude/agents/`), enforce boundaries with `PreToolUse` and `Stop` hooks, and run automated code review. See [Claude Code docs](https://code.claude.com/docs).
- **OpenAI Codex:** Scope package context via nested `AGENTS.md`, separate `sandbox_mode = "read-only"` planning from `"workspace-write"` edits, and run slices in worktrees or cloud environments. See [Codex docs](https://developers.openai.com/codex).
- **Cursor:** Draft slices in Plan Mode, encode invariants in `.cursor/rules/*.mdc` or `AGENTS.md`, isolate work in Worktrees or Cloud Agents, and review with Bugbot. See [Cursor docs](https://cursor.com/docs).

## Verifying build discipline

Audit your repository's Loop and Graph readiness with `npx @wondelai/harness-audit` (see [Harness Audit](/en/harness-audit/)). Require fail-then-pass acceptance checks ([oracle strength](/en/workflows/test/oracle-strength/)), immutable test paths ([protecting the oracle](/en/workflows/test/protect-the-oracle/)), [architecture fitness functions](/en/workflows/test/fitness-functions/), and fresh [agent PR review](/en/workflows/ship/agent-pr-review/).

## What breaks in agent-driven builds?

- **Unread callers break downstream:** Diff edits files absent from the plan. *Recovery:* Reject the PR and rerun read-only blast-radius mapping.
- **One slice expands into a megadiff:** Changes span multiple subsystems. *Recovery:* Revert to the last green commit and re-slice.
- **Tests weaken to turn green:** Test or CI files change inside implementation PRs. *Recovery:* Protect oracles via `CODEOWNERS` and CI, then rerun cleanly.
- **Parallel sessions collide:** Merge conflicts or port contention. *Recovery:* Assign one worktree and isolated port block per slice.
- **Mid-build plan assumption fails:** Agent hacks around broken contracts. *Recovery:* Stop, update the plan with an engineer, and restart fresh.

## Official docs and next steps

- Official references: [Claude Code](https://code.claude.com/docs), [OpenAI Codex](https://developers.openai.com/codex), and [Cursor](https://cursor.com/docs).
- Next on the ladder: [spec-driven development](/en/workflows/plan/spec-driven-development/), [testing and verification](/en/workflows/test/), [review and ship](/en/workflows/ship/), and [Level 4: write specs](/en/ladder/level-4-write-specs/).
