Exploration answers, graded by evidence

Use a read-only prompt pack for exploring an unfamiliar repo, then grade the answers: each claim against what the transcript shows Claude actually read, grepped or only saw in a listing, and each file:line citation against the repo. Session: Exploration with Claude Code and Architecture Exploration.

  • Python 3.9+
  • standard library only
  • offline: the explore_readonly fixture
  • samples/answer_cited.md
python3 delivery-1/explore_report.py

The run has three parts. It prints the pack and the map prompt with its answer contract (bullets that end in a file:line, an evidence table, unknowns, next questions). It grades the recorded run's uncited answer against its own transcript. Then it checks the citations in a sample answer that follows the contract.

┌─────────────────────────┐
│ Exploration prompt pack │
└─────────────────────────┘
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   
[1] One prompt in full: 'map'
  --- prompt 'map' ---
  What are this repository's modules, what is each one responsible for, and where are the entry points?
  
  Answer from the code only, and cite only lines you actually read. Format the reply as:
  
  ## Answer
  - 3 to 6 bullets. End every bullet with the file:line it rests on, in parentheses, e.g. (tinyapp/cart.py:33).
  
  ## Evidence
  | claim | file:line | what the line shows |
  |---|---|---|
  
  ## Unknowns
  - what you could not confirm from the code, and which file you would read next
  
  ## Next questions
  - up to 3 questions for the owner
  --- how to run it ---
  interactive, read-only:  /plan What are this repository's modules, what is each one respons...
  via the Explore subagent: "Use the Explore subagent (very thorough) to answer: What are this repository's modules, what..."
  headless (read-only, capped):
    claude -p <prompt 'map' above> --output-format stream-json --verbose --max-turns 8 --max-budget-usd 0.25 --permission-mode dontAsk --tools Read,Grep,Glob --allowedTools Read,Grep,Glob --disallowedTools 'mcp__*' --strict-mcp-config --settings '{"disableAllHooks":true}' --no-session-persistence

┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Grade a recorded run against its own transcript · common/fixtures/stream/explore_readonly.jsonl │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
  run: success, 4 turns, tool calls {'Glob': 1, 'Grep': 1, 'Read': 2}
[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

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Check the citations in an answer that follows the contract · delivery-1/samples/answer_cited.md │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
[4] Each file:line is looked up in the repo; the line must show what the claim says
#  evidence  claim                                                                    
─  ────────  ─────────────────────────────────────────────────────────────────────────
1  cited     `money()` formats integer cents as dollars (tinyapp/pricing.py:13).      
2  cited     `tax_for()` rounds half up with integer math: `(subtotal_cents * bps +...
3  cited     `apply_discount()` looks a code up by its exact key, so a lower-case c...
4  cited     `Cart.add()` merges a line only when both the SKU and the unit price m...
5  cited     Tax applies after the discount (tinyapp/cart.py:57).                     
6  cited     `receipt()` prints the item lines, then subtotal, discount, tax and to...
7  cited     The public API is `Cart`, `LineItem`, `apply_discount`, `money` and `t...
8  cited     The tests run with `python3 -B -m unittest` (CLAUDE.md:7).               
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

┌────────────┐
│ Comparison │
└────────────┘
answer                                         evidence  cites file:line  checked against
─────────────────────────────────────────────  ────────  ───────────────  ───────────────
common/fixtures/stream/explore_readonly.jsonl  0.48      no               the transcript 
delivery-1/samples/answer_cited.md              0.92      yes              the repo       

The recorded answer may well be right; the point is that nobody can tell without re-reading the code. Ask for the contract, then grade it.
wrote delivery-1/out/answer_template.md, delivery-1/out/explore_recorded.md, delivery-1/out/explore_answer_cited.md
  1. history is the one prompt that isn't headless: it needs Bash(git log *) and Bash(git blame *), and the lab's headless helper pre-approves read tools only.
  2. The headless form of every read-only prompt. --tools limits which tools exist, --allowedTools pre-approves them, and dontAsk denies anything else instead of prompting. MCP and repo hooks are off, and the run is capped by turns and dollars.
  3. The grader rebuilds what Claude saw from the tool_use inputs and their results: two files read, one grepped, and __init__.py seen only as a name in a Glob listing.
  4. Claim 4 may well be true, but it rests on a filename. Nothing in this transcript shows the re-exports.
  5. drift: the citation resolves, but line 12 of cart.py (and the lines around it) is sku: str, not Cart.remove(). A citation can be checked, so it can also fail the check.
  6. 0.48 for the uncited answer, graded against the transcript. 0.92 for the cited one, checked against the repo alone, with no transcript needed.
  • python3 delivery-1/explore_report.py --prompt impact prints the blast-radius prompt instead of map, with its three read-only ways to run it: /plan, the Explore subagent, or headless.
  • --answer delivery-1/samples/answer_real_haiku.md checks a saved answer from a real Haiku run of map: evidence score 1.00, cited 5.
  • --transcript common/fixtures/stream/tool_error_recovery.jsonl grades another recorded run. Its Read of tinyapp/discounts.py failed, and the only claim names that file, so the claim is unseen and the score is 0.00. A claim scores at the weakest file it names.
  • Break it: copy samples/answer_cited.md, change (tinyapp/pricing.py:13) to :99 and (tinyapp/cart.py:57) to (tinyapp/taxes.py:5), and pass the copy with --answer. Both claims become bad cite, one past the end of the 32-line file and one in a file that doesn't exist, and the score drops from 0.92 to 0.70.
  • In your own repo, run the map prompt in plan mode, save the answer, and grade it with --answer FILE --repo DIR. How many claims are cited?

Run one pack prompt against your own Claude Code, then grade the real answer against the real transcript. It costs money, runs with read-only tools in a temp copy of tiny-app, and is capped (defaults: 8 turns, $0.25):

python3 delivery-1/explore_report.py --real --prompt map --model haiku --max-budget-usd 0.05

A recorded run of this command with --max-turns 6 (2026-10-20, Claude Code v2.1.303) reported success in 7 turns, 6 tool calls and $0.0037. Read num_turns from the result; don't predict it from the cap. The budget is checked against Claude Code's client-side estimate, and spend can pass the cap by up to one response. Real runs save out/explore_real.jsonl, so you can grade them again later with --transcript.

--repo PATH runs in that repo instead of a temp copy, and its .claude/settings.json env and apiKeyHelper still apply with hooks off, so use it only on a repo you trust.

  • Evidence levels run cited > read > grepped > drift > listed > no anchor > unseen. An answer that sounds complete can rest on file names.
  • The contract is what makes grading cheap. Without citations you need the transcript to grade an answer; with them you need only the repo, and a wrong line shows up as drift.
  • The grader counts the project CLAUDE.md as read, because a main session loads it at launch (memory). The built-in Explore and Plan subagents start without your CLAUDE.md files (subagents), so a claim about CLAUDE.md in an Explore answer needs its own Read.
  • For real work, ask for file:line on every bullet and an Unknowns section. That turns "the code is clean" into something you can check.

Parallel variants in worktrees, gate first

Plan three competing prototypes for one product question, each in its own claude --worktree session with the same acceptance check and its own cap. Then rank recorded results: a hard gate first, a weighted score second, and a checklist of the evidence behind each. Session: Parallel Variants and Tradeoffs.

  • Python 3.9+
  • standard library only
  • offline: samples/variants.json and samples/variant_results.json
  • git, for --materialize only
python3 delivery-1/variants.py

The lab never starts Claude Code. It writes out/run_variants.sh, one prompt per variant in out/variants/, and out/variants_plan.md. The results it ranks in step 5 are illustrative, from samples/variant_results.json.

┌──────────────┐
│ Variant plan │
└──────────────┘
  problem: Receipts should show which discount code was applied, so shoppers can tell why the total dropped.
  acceptance check: `python3 -B -m unittest` (the same check in every worktree)
[1] One worktree session per approach
variant            worktree                             branch                      model/effort   turns / $ cap
─────────────────  ───────────────────────────────────  ──────────────────────────  ─────────────  ─────────────
receipt-label      .claude/worktrees/receipt-label      worktree-receipt-label      sonnet/medium  12 / $0.60   
cart-applied-code  .claude/worktrees/cart-applied-code  worktree-cart-applied-code  sonnet/medium  12 / $0.60   
receipt-json       .claude/worktrees/receipt-json       worktree-receipt-json       sonnet/high    12 / $0.60   
  receipt-label: Smallest change: receipt() writes 'discount (WELCOME10)' instead of 'discount'.
  cart-applied-code: Model change: Cart exposes applied_code (the code when it matched, else None) and every surface reads it.
  receipt-json: New surface: a --json receipt that includes the code; the text receipt renders from the same dict.
  distinct: no two hypotheses share more than 11% of their words (warning at 50%, or 30% with the same files)
  shared files: tests/test_cart.py (receipt-label, cart-applied-code); tinyapp/cli.py (receipt-label, cart-applied-code, receipt-json). Fine for throwaway prototypes: you merge one variant, not all.
[2] Setup once per repo
  echo '.claude/worktrees/' >> .gitignore      # the repo also needs at least one commit
  echo '.env.local' >> .worktreeinclude        # gitignored files a fresh checkout needs
  The run script passes --settings '{"worktree": {"baseRef": "head"}}' so every variant starts from your HEAD; the default "fresh" starts from the remote default branch.
[3] Commands
  interactive: claude --worktree receipt-label     then paste out/variants/receipt-label.prompt.txt
  headless (per variant, from the generated script):
    claude -p <out/variants/receipt-label.prompt.txt> --worktree receipt-label --permission-mode acceptEdits --tools Read,Edit,Write,Glob,Grep,Bash --allowedTools 'Bash(python3 -B -m unittest *)' --disallowedTools 'mcp__*' --strict-mcp-config --settings '{"disableAllHooks": true, "worktree": {"baseRef": "head"}}' --model sonnet --effort medium --max-turns 12 --max-budget-usd 0.6 --output-format json
  -p runs never clean up their worktree, so every variant is still there to diff and test afterwards.
[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).
  Running several sessions at once multiplies token usage; each cap is checked against a client-side estimate and can overshoot by one response.
[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
  weights: criteria 0.40, diff 0.25, cost 0.20, turns 0.15 (diff, cost and turns scored relative to the best passing variant)
  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 receipt-label: The code is read from cart.discount_code, so a mistyped code that doesn't apply could still be printed if the discount were non-zero for another reason.
  note on cart-applied-code: Cart.applied_code is the idea worth keeping: one place decides whether a code applied.
  note on receipt-json: Ran out of turns while fixing the text receipt it had re-rendered from the dict.
  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
        git worktree unlock .claude/worktrees/receipt-json; git worktree remove .claude/worktrees/receipt-json && git branch -D worktree-receipt-json

wrote delivery-1/out/run_variants.sh, delivery-1/out/variants_plan.md and 3 prompt file(s) in delivery-1/out/variants/
  1. The distinctness check runs before any money is spent. Variants that share most of their hypothesis words would differ only in trivia, and you'd pay three times for one idea.
  2. One generated command per variant. acceptEdits plus a --tools list, only the acceptance check pre-approved, MCP blocked, the clone's hooks off, and worktree.baseRef "head", so each variant branches from your work rather than the remote default branch.
  3. The caps add up to $1.80 against a $1.50 budget, so the generated script refuses to run until the plan fits.
  4. The gate removes receipt-json before any scoring: it ended in error_max_turns and its check exits 1. Scores only rank variants that already work.
  5. The loser holds the idea worth keeping. A rubric ranks; you decide, and you port the idea through a new plan rather than merging two variants.
  6. Cleanup for the losers starts with git worktree unlock, because worktrees made by claude -p --worktree keep Claude Code's lock until a later session's stale-lock sweep releases it.

--materialize builds the same layout with real git in a temp copy of tiny-app, shows what isolation does and doesn't give you, and removes everything:

python3 delivery-1/variants.py --materialize
┌───────────────────────────────────────────────────────────────────────────────┐
│ Materialize: the worktree layout Claude Code uses, in a temp copy of tiny-app │
└───────────────────────────────────────────────────────────────────────────────┘
  $ printf '.claude/worktrees/\n.env.local\n' > .gitignore && git commit -m 'ignore worktrees and local env'
  $ echo DEMO_ONLY=1 > .env.local          # untracked and gitignored, like a real local secret file
[1] One worktree per variant (what `claude --worktree <name>` creates)
  $ git worktree add -b worktree-receipt-label .claude/worktrees/receipt-label HEAD
  $ git worktree add -b worktree-cart-applied-code .claude/worktrees/cart-applied-code HEAD
  $ git worktree add -b worktree-receipt-json .claude/worktrees/receipt-json HEAD
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
  Claude Code copies gitignored files listed in .worktreeinclude (gitignore syntax) into new worktrees:
    echo .env.local >> .worktreeinclude
[4] Cleanup: this demo removes all three (in a real run, keep the winner's branch until it's merged)
  $ git worktree remove --force .claude/worktrees/receipt-label && git branch -D worktree-receipt-label
  $ git worktree remove --force .claude/worktrees/cart-applied-code && git branch -D worktree-cart-applied-code
  $ git worktree remove --force .claude/worktrees/receipt-json && git branch -D worktree-receipt-json
  worktrees left: 1 (the main checkout)
  `--force` is here only because step 2 left an edit; without it git refuses to remove a dirty worktree, and Claude Code prompts before removing a named or dirty one. Worktrees a -p run created keep Claude Code's lock until a later session's stale-lock sweep releases it: run `git worktree unlock <path>` first.
  1. The layout claude --worktree <name> creates: .claude/worktrees/<name> on branch worktree-<name>. Gitignore .claude/worktrees/.
  2. An edit in one worktree doesn't show up in another worktree or in the main checkout.
  3. A worktree is a fresh checkout, so a gitignored .env.local is missing. List it in .worktreeinclude and Claude Code copies it in.
  4. --force is here only because step 2 left an edit. In real use, unlock a -p worktree first and keep the winner's branch until it's merged.
  • Make the plan fit: in a copy of samples/variants.json, set each max_budget_usd to 0.50 and run --spec on the copy. Step 4 reads caps: $0.50 + $0.50 + $0.50 = $1.50 against $1.50 allowed, and the over-budget line is gone.
  • Break it: add a copy of receipt-label named receipt-label-opus with "model": "opus". Step 1 warns that the two "may differ only in trivia" because they differ only in model, and step 4 is now over budget by $0.90. Comparing models on one approach is an eval, not a product variant.
  • Read out/run_variants.sh before you consider running it. Its header lists what each session may do without asking, and its over-budget check exits 1 before any session starts.
  • Change the WEIGHTS in variants.py so cost dominates. Which variant wins, and would you ship it?

There is no --real here. out/run_variants.sh starts three write-capable sessions in parallel, and it hasn't been run as part of the course. Each session is capped, but parallel sessions multiply token usage. Run it only in a scratch clone with at least one commit, then rank what it wrote with --collect DIR.

  • Each variant should test a different idea. Model or effort changes on one approach belong in an eval.
  • Gate before score. The run must have succeeded, read in the docs' order: stop_reason isn't "refusal", then terminal_reason, then subtype (ResultError). The acceptance check must also exit 0, and every MUST criterion must hold. Only then do the weights apply.
  • ? in the checklist marks evidence nobody has collected or reviewed yet. Fill it in by reading each diff before you trust the ranking.
  • -p runs never clean up their worktrees, so all three stay around to diff and test, still locked until a later session's stale-lock sweep (worktrees). That's useful for comparing them, and it means you clean up by hand.
  • Variants aren't /batch. /batch decomposes one change into 5 to 30 independent units and publishes every one (commands); variants are competing answers to one question, and you keep one.