# delivery-1: product engineering with Claude Code

Two labs for the session page `delivery/01-product-mechanics.html`, covering the systems-thinking and leverage topics. Both run offline by default. They read `common/samples/tiny-app` without writing to it, and their output goes to `delivery-1/out/` or a temp dir.

| Lab | What you build | Run (from `labs/`) |
|---|---|---|
| `explore_report.py` | Three things: a codebase-exploration prompt pack (map, flow, conventions, impact, tests, history, unknowns); an answer contract with a `file:line` on every bullet; and a grader that checks each claim against the transcript (what Claude actually read, grepped or only saw in a listing) and each citation against the repo. | `python3 delivery-1/explore_report.py` |
| `variants.py` | A plan for N competing prototypes, one `claude --worktree` session each, with the same acceptance check and per-variant budget caps. It generates a run script you review and run yourself, then ranks the results through a gate first and a weighted score second. `--materialize` creates real git worktrees in a temp copy and removes them. | `python3 delivery-1/variants.py` |

`run_all.txt` runs `explore_report.py`, `variants.py` and `variants.py --materialize`. The last one skips cleanly when git isn't installed.

## explore_report.py

```bash
python3 delivery-1/explore_report.py                               # pack, then grade the recorded run and the cited sample
python3 delivery-1/explore_report.py --list
python3 delivery-1/explore_report.py --prompt impact               # print one prompt and the commands to run it
python3 delivery-1/explore_report.py --transcript run.jsonl        # grade your own `--output-format stream-json --verbose` run
python3 delivery-1/explore_report.py --answer my_answer.md --repo /path/to/repo
python3 delivery-1/explore_report.py --real --prompt map --model haiku --max-budget-usd 0.05   # costs money
```

The prompt pack (from `--list`):

```text
id           prompt                   when                                                tools                                             runs
map          Map the codebase         first session in an unfamiliar repo                 Read,Grep,Glob                                    headless
flow         Trace a flow             before changing behavior that crosses modules       Read,Grep,Glob                                    headless
conventions  Find the conventions     before the first edit                               Read,Grep,Glob                                    headless
impact       Blast radius             before changing a function's signature or behavior  Read,Grep,Glob                                    headless
tests        What the tests pin       before trusting a green suite                       Read,Grep,Glob                                    headless
history      Why is it like this?     before 'fixing' something that may be intended      Read,Grep,Glob,Bash(git log *),Bash(git blame *)  interactive
unknowns     Surprises and questions  before writing a brief                              Read,Grep,Glob                                    headless
```

Every prompt can run read-only in three ways:

- interactively in plan mode (`/plan ...`)
- through the Explore subagent ("quick", "medium" or "very thorough")
- headless, with the capped command that `common/cc.py` builds: `--tools Read,Grep,Glob --allowedTools Read,Grep,Glob --permission-mode dontAsk`, MCP and hooks off, `--no-session-persistence`

Grading the recorded run (`common/fixtures/stream/explore_readonly.jsonl`) against its own transcript, from a real run of the lab:

```text
[2] What Claude saw (from tool_use inputs and their results)
  read: tinyapp/cart.py, tinyapp/pricing.py
  grepped: tinyapp/cli.py (3 hits)
  listed only: tinyapp/__init__.py
[3] Claims in the final answer, graded
#  evidence   claim
1  read       `pricing.py`: `money()` formatting, `tax_for()` (basis points, rounded...
2  read       `cart.py`: `Cart` and `LineItem`; subtotal, discount, tax (after disco...
3  grepped    `cli.py`: `parse_item()`, `receipt()` and `main()`, a receipt printer.
4  listed     `__init__.py`: re-exports the public API.
                rests on a file name from a Glob listing: tinyapp/__init__.py
5  no anchor  All amounts are integer cents.
                names no file or symbol: say where it comes from
  evidence score 0.48  ██████████████················  read 2, grepped 1, listed 1, no anchor 1
```

The answer may well be right, but claim 4 rests on a filename. Checking the citations in `samples/answer_cited.md`, which follows the contract, catches the one that drifted:

```text
9  drift     `Cart.remove()` returns True when it removed a line (tinyapp/cart.py:1...
               tinyapp/cart.py:12 doesn't show what the claim says: 'sku: str'
  evidence score 0.92  ████████████████████████████··  cited 8, drift 1
```

### Real mode

A recorded real run (2026-10-20, Claude Code v2.1.303) used `python3 delivery-1/explore_report.py --real --prompt map --model haiku --max-budget-usd 0.05 --max-turns 6`. It ran in a temp copy of tiny-app with read-only tools:

```text
[real] This run calls the model through your Claude Code login and costs money: capped at $0.05 (client-side estimate) and 6 turns. Working dir: /var/folders/.../cc-lab-oaa4jqo_/tiny-app
  outcome: success in 7 turns, 6 tool calls, $0.0037 (client-side estimate)
  read: README.md, tinyapp/__init__.py, tinyapp/cart.py, tinyapp/cli.py, tinyapp/pricing.py
  grepped: -
  listed only: CLAUDE.md, tests/__init__.py, tests/test_cart.py, tests/test_pricing.py
```

Haiku followed the contract: five bullets, each ending in a citation, and an Unknowns section that names the test files it didn't read. The answer is saved verbatim as `samples/answer_real_haiku.md`.

That run also exposed two false "drift" verdicts. One single-citation bullet covered several facts, and another cited a code line whose explanation sits in the comment above it. The citation check now looks at two lines on each side of the cited line. The run also listed `CLAUDE.md` without reading it, because CLAUDE.md is loaded into context at launch, so transcript grading now counts CLAUDE.md as read. Re-checking the saved answer:

```text
$ python3 delivery-1/explore_report.py --answer delivery-1/samples/answer_real_haiku.md
  evidence score 1.00  ██████████████████████████████  cited 5
```

Real runs now also save `out/explore_real.jsonl`, so you can grade them again later with `--transcript`.

## variants.py

```bash
python3 delivery-1/variants.py                     # plan + rank the recorded results in samples/variant_results.json
python3 delivery-1/variants.py --collect DIR       # rank what out/run_variants.sh wrote (printed at the end of the script)
python3 delivery-1/variants.py --materialize       # real worktrees in a temp copy, then cleanup
python3 delivery-1/variants.py --spec my_variants.json --json
```

The lab never starts Claude Code. It writes:

- `out/run_variants.sh`: one `claude -p "<prompt>" --worktree <name> --permission-mode acceptEdits --tools Read,Edit,Write,Glob,Grep,Bash --allowedTools "Bash(<check> *)" --disallowedTools "mcp__*" --strict-mcp-config --settings '{"disableAllHooks": true, "worktree": {"baseRef": "head"}}' --model ... --effort ... --max-turns N --max-budget-usd X --output-format json` per variant, all run in parallel. The header spells out what runs without asking: acceptEdits approves edits and `mkdir`/`touch`/`rm`/`rmdir`/`mv`/`cp`/`sed` inside the worktree, read-only commands never prompt, and the acceptance check plus your own allow rules are allowed. `disableAllHooks` is there because a `-p` run shows no workspace-trust dialog, so a clone's committed hooks would run. The script `cd`s to the repo root and refuses to run while the caps exceed the spec's budget, unless you set `ALLOW_OVER_BUDGET=1`.
- one prompt per variant in `out/variants/`
- `out/variants_plan.md`

After each run, the script runs the acceptance check inside the worktree and records `git diff --shortstat`.

Excerpt from a real run of the lab (the results are illustrative, from `samples/variant_results.json`):

```text
[1] One worktree session per approach
  ...
  distinct: no two hypotheses share more than 11% of their words (warning at 50%, or 30% with the same files)
[4] Budget
  caps: $0.60 + $0.60 + $0.60 = $1.80 against $1.50 allowed
  over budget by $0.30: lower a cap or drop a variant. The generated script refuses to run until you do (or set ALLOW_OVER_BUDGET=1).
[5] Rank the results (delivery-1/samples/variant_results.json; gate first, then score)
rank  variant            gate  score  why
1     receipt-label      pass  1.00   criteria 100%, 10 lines, $0.21, 7 turns
2     cart-applied-code  pass  0.66   criteria 100%, 35 lines, $0.43, 11 turns
-     receipt-json       fail  -      run ended error_max_turns (max_turns); acceptance check exits 1; misses MUST: hides-unknown, suite-green
  evidence checklist (yes / no / ? = not reviewed yet):
variant            result  check  diff         shows-code  hides-unknown  suite-green  api-unchanged  small-diff
receipt-label      yes     yes    +9 -1 in 2   yes         yes            yes          yes            yes
cart-applied-code  yes     yes    +31 -4 in 3  yes         yes            yes          yes            yes
receipt-json       no      no     +58 -6 in 2  yes         no             no           yes            yes
  winner: receipt-label
  note on cart-applied-code: Cart.applied_code is the idea worth keeping: one place decides whether a code applied.
  next: git diff HEAD...worktree-receipt-label    # review it, then merge or cherry-pick
        git worktree unlock .claude/worktrees/cart-applied-code; git worktree remove .claude/worktrees/cart-applied-code && git branch -D worktree-cart-applied-code
```

When two variants test the same idea, the plan warns before anything runs. For example, a copy of `receipt-label` with `"model": "opus"` produces:

```text
  warning: receipt-label vs receipt-label-opus may differ only in trivia (same approach; they differ only in model). Each variant should test a different idea; comparing models or effort on one approach is an eval, not a product variant.
```

`--materialize`, from a real run (git 2.x, temp copy of tiny-app):

```text
worktree (relative to the repo)      branch
.                                    main
.claude/worktrees/cart-applied-code  worktree-cart-applied-code
.claude/worktrees/receipt-json       worktree-receipt-json
.claude/worktrees/receipt-label      worktree-receipt-label
[2] Isolation: an edit in one worktree doesn't show up in another
  git status in receipt-label: M tinyapp/cli.py
  git status in receipt-json: clean
  git status in the main checkout: clean
[3] Untracked files don't follow you: .env.local
  main checkout: present
  .claude/worktrees/receipt-label: missing
```

The headless commands use only documented flags, but the generated `run_variants.sh` itself has not been run. It starts three write-capable sessions, which is beyond this lab's two-call real-run budget. Run it on a scratch clone first.

## Docs

- Explore subagent: https://code.claude.com/docs/en/sub-agents
- Plan mode: https://code.claude.com/docs/en/permission-modes
- Headless and stream-json: https://code.claude.com/docs/en/headless
- CLI flags (`--tools`, `--allowedTools`, `--worktree`, `--effort`, caps): https://code.claude.com/docs/en/cli-reference
- Tool input/output shapes: https://code.claude.com/docs/en/agent-sdk/typescript
- Worktrees, `.worktreeinclude`, `worktree.baseRef`: https://code.claude.com/docs/en/worktrees
- Ways to run work in parallel, and `/batch`: https://code.claude.com/docs/en/agents
- Costs: https://code.claude.com/docs/en/costs
