# 32.8 Set up once, and build with Claude Code (/affordable-self-improving-ai-workers/choosing-the-foundation/set-up-once-with-claude-code)

---
type: Document
title: "32.8 Set up once, and build with Claude Code"
description: "The tools you set up once for the whole part, the CLAUDE.md that pins the versions, and the build method every lab in this part follows: spec and failure tests first, Claude Code builds, you review."
status: stable
order: 432.08
ksor:
  owner: team:panaversity
  audience: [ public ]
  approval:
    by: process:panaversity
    at: 2026-11-30T08:18:55Z
chapter: "32"
part: IV
expert_status: manager
concepts: [ "32.8" ]
last_verified: 2026-11-29
generated:
  at: 2026-11-30T08:18:55Z
  by: human:zia
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** A building contractor does not lay every brick. The contractor draws the plan, says how each part will be checked, and inspects the work before signing it off. The builders are fast. The contractor is responsible.

**What you will learn.** What you set up once for the whole part, what goes in your `CLAUDE.md`, and the four steps of every build in this part.

**Why it matters.** Claude Code can write a durable worker in an afternoon. It can also write one that pays an invoice twice and looks fine until the first crash. The method on this page is how you get the first and not the second.

### What you set up once

You did most of this in Part III. Check each item:

1. **Claude Code,** signed in, as in Chapter 12.
2. **A free Cloudflare account,** and Wrangler, Cloudflare's command-line tool. Set a **spending notification** first, so a mistake can never cost you money without warning.
3. **A free Neon account,** for the database this part uses from its second chapter on.
4. **Node.js 24 or later.**
5. **No API key for the tests.** Every lab's tests use recorded model answers. This chapter's lab needs no model key at all.

### Your CLAUDE.md

Each lab folder has a `CLAUDE.md`. Claude Code reads it before every task. The important lines are these:

```markdown
# Versions (do not change without a task that says so)
- agents 0.34.x and @earendil-works/pi-durable 1.6.x, @earendil-works/pi-ai 1.6.x.
  Pi Durable is experimental: read node_modules/agents/docs/harnesses/pi.md and
  node_modules/@earendil-works/pi-durable/README.md before you use an API.
  Never guess a Pi API from memory.
- @openai/agents 0.22.x for the comparison worker.

# Rules
- One Durable Object per conversation. Create the Pi registry per object, never at module scope.
- A tool with side effects is replay-safe only if it saves its idempotency key with api.memo()
  before the outside call.
- Tests run with recorded model answers. Never put an API key in a test.
- Do not mark a task done until npm test passes.
```

The line about reading the docs matters most. Pi Durable is new and changes in minor releases. A model trained before the latest release may remember an older API. Telling Claude Code to read the installed package's own documentation fixes that.

Two words in it are Pi's own. The **registry** is the object in which you install the worker's tools. **`api.memo()`** saves a value the first time a tool runs, and gives back that same value when the tool runs again after a crash.

### The four steps of every build

**1. You write the spec.** One page: what the worker does, its tools, which tools change things outside, what needs approval, and its budget.

**2. You write the failure tests first.** Before any code exists, you say how the work could go wrong, and write a test for each case. For this chapter's worker:

- If the object dies right after a tool posts something, the post happens once.
- If a step is still waiting for approval when the runtime restarts, it is still waiting afterwards.
- The tests run without a key.

**3. Claude Code builds until the tests pass.** You give it the spec and the tests. It writes the code, runs the tests and fixes its own mistakes. You do not edit its code by hand; you tell it what is wrong.

**4. You review with a checklist.** Passing tests are not enough, because tests only check what you thought of. Read the code for the mistakes Claude Code makes most often in this part:

- An outside action with a new random key each time it runs.
- A tool marked `replay: "safe"` that is not safe to repeat.
- A Pi API that does not exist in the installed version.
- Code that keeps the Durable Object awake while it waits.

> **The invariant.** You write the spec and the tests; Claude Code writes the code; you review it. The engineer in charge is the one who decides what "correct" means.

**Check yourself.** Claude Code's code passes all your tests, but its payment tool calls `crypto.randomUUID()` inside the call to the ledger. Do you approve it? *(No. After a crash the tool would run again with a new key and pay twice. Ask for the key to be saved with `api.memo()` first, and add a test for it.)*
