Tutorial 2 — Your first live LLM Bench
Goal: drive a real Claude session against a small Go repo you build by hand, score the answer, and read the session.
You will learn: the claude-code Harness, testdata and sandboxes, contains-all and any-of, the latency ceiling, and what Session.WorkDir and Session.Calls look like in the JSON report.
Prerequisites: Tutorial 1 (you understand contains and the YAML shape), ANTHROPIC_API_KEY available — exported in your shell or in a ./.env file (see Settings and .env) — and the claude CLI on your PATH (which claude should resolve). madbench preflight <bench> verifies both before you spend anything.
Cost: roughly $0.002 per run on Haiku 4.5.
Why graduate from mock?
The mock Harness cannot test code understanding. This tutorial asks a real model "where is HandleLogin defined and where is it called from?" against a real Go module you assemble. Three things that did not exist in Tutorial 1 now matter:
- The agent has a working directory.
Session.WorkDiris a fresh tmpdir holding a copy of your testdata. The agent canRead,Grep, andGlobreal files. - The agent has a session. Every tool call is captured; you can assert "the agent used
Grepat least once." - The agent costs money and takes time. You bound this with
latencyceilings.
Step 0 — Create the project
mkdir codenav
cd codenav
Layout you are about to build:
codenav/
├── madbench.yaml
└── code/
├── go.mod
├── auth/login.go
├── routes/router.go
├── cmd/server/main.go
└── internal/session/store.go
Step 1 — Build the testdata
Fast path — you can skip the inline files below and curl the prebuilt testdata from madbench-examples:
curl -sL https://github.com/MadAppGang/madbench-examples/tarball/main \| tar -xz --strip-components=2 \'MadAppGang-madbench-examples-*/02-first-live-llm-eval/code'The command drops a
code/directory with the testdata files into your current directory. Then jump to Step 2. The inline walkthrough below is for readers who want to see the testdata structure as they type.
The testdata directory contains a tiny multi-file Go module. Two design choices worth naming up front: it must be small enough to fit in context, large enough to require navigation (a single 30-line file is too small — the agent answers from one Read and the Bench grades nothing interesting), and it should include a distractor symbol so a sloppy agent has a way to hallucinate that you can detect.
Create the directory tree and files:
mkdir -p code/{auth,routes,cmd/server,internal/session}
code/go.mod
module example.com/codenav
go 1.22
code/auth/login.go
package auth
// HandleLogin authenticates a user and returns a session token.
func HandleLogin(user, pass string) (string, error) {
if user == "" || pass == "" {
return "", ErrEmpty
}
return "token-" + user, nil
}
var ErrEmpty = &authErr{msg: "empty credentials"}
type authErr struct{ msg string }
func (e *authErr) Error() string { return e.msg }
code/routes/router.go
package routes
import "example.com/codenav/auth"
func Login(user, pass string) (string, error) {
return auth.HandleLogin(user, pass)
}
code/cmd/server/main.go
package main
import (
"fmt"
"example.com/codenav/auth"
)
func main() {
tok, _ := auth.HandleLogin("alice", "secret")
fmt.Println(tok)
}
code/internal/session/store.go
package session
// Store is an in-memory session table. Unrelated to HandleLogin —
// it's a deliberate distractor for the navigation eval.
type Store struct {
data map[string]string
}
func NewStore() *Store { return &Store{data: map[string]string{}} }
HandleLogin is defined in auth/login.go and called from routes/router.go and cmd/server/main.go. The internal/session/store.go file is the distractor — a perfect agent ignores it; a sloppy one might hallucinate "it is also called from store.go".
Step 2 — Write madbench.yaml
Back in the project root (codenav/):
description: "codenav — find HandleLogin and its callers"
harness:
type: claude-code # invoke the real claude CLI
model: claude-haiku-4-5-20251001 # cheap, fast, deterministic enough for nav
defaults:
sandbox: home # copy testdata to fresh tmpdir per Scenario
timeout: 120s # hard cap on wall-clock
capture: log # save stream-json into the report
scenarios:
- name: handle-login-nav
testdata: ./code
prompt: |
In the Go repo at the current working directory, find where
HandleLogin is defined and list every place it is called from.
checks:
- type: contains # the answer names the def file
value: "auth/login.go"
- type: contains-all # the answer names BOTH callers
value:
- "routes/router.go"
- "cmd/server/main.go"
- type: not-contains # guard: not the "I couldn't find it" failure mode
value: "not defined"
- type: any-of # at least one navigation tool was used
checks:
- type: session:tool-used
value: "Grep"
- type: session:tool-used
value: "Glob"
- type: session:tool-used
value: "Read"
- type: latency
threshold: 90000 # 90 seconds; sanity ceiling
Three lines that did not appear in Tutorial 1: type: claude-code under harness:, sandbox: home, and testdata:. Together they say: "Copy ./code into a fresh tmpdir, point the Harness's cwd at it, and let it work."
The testdata directory is read-only as far as your project is concerned. madbench copies it. The agent can do anything to its copy; your
code/directory never gets mutated. The copy is thrown away after the scenario.
homeis notcontainer. The sandbox level says what each Scenario gets its own copy of. Athomethat is the working tree and HOME — fast, and using your local Go toolchain — but the agent is still an ordinary process that can read any path on your machine.containerruns it in a container and is the only level that confines it. See sandbox levels.
Step 3 — Run it
madbench
Expected (timings vary):
Bench: codenav — find HandleLogin and its callers
Duration: 10.361s
✓ PASS handle-login-nav
✓ contains: contains: pass
✓ contains-all: contains-all: all 2 values found
✓ not-contains: not-contains: pass
✓ any-of: any-of: at least one child passed
✓ latency: latency: 10354ms (threshold: 90000ms)
1 passed, 0 failed
If the Bench hangs longer than ~30s with no output, the most likely cause is claude not on PATH or ANTHROPIC_API_KEY unset — run madbench preflight to check both, or see Troubleshooting at the end.
Step 4 — The five Checks, named
What is genuinely new since Tutorial 1:
| Check | What it grades |
|---|---|
contains-all | All N substrings appear in FinalOutput. The "AND" version of contains. |
any-of | Composite — passes if at least one child passes. |
session:tool-used | Did the agent invoke this tool name during the session? Searches Session.Calls, not FinalOutput. |
latency | Wall-clock ceiling in milliseconds. |
contains-all and not-contains together encode the failure modes you actually care about: missing one caller (the agent half-answered), or hallucinating "not defined" (the agent gave up and pretended the symbol didn't exist).
Step 5 — Why any-of for the session
A well-equipped agent (with AST tooling installed) might answer with two AST tool calls and never touch Grep. A bare Claude session uses Glob + Grep + Read. Both should pass — what you actually want to assert is "the agent used some navigation primitive," not "the agent used Grep specifically."
any-of says exactly that. It runs each child and passes if any child passes. Tutorial 4 introduces its sibling not-any-of for "the agent must NOT have used any of these tools."
Session Checks are about behavior, not output. A Check that only grades
FinalOutputcannot tell whether the agent actually did the work or hallucinated a plausible-looking answer.session:tool-usedis your cheap defense — it catches the agent that "answered" without ever opening a file.
Step 6 — Open the JSON report
madbench --report-json out/codenav.json
The fields you will return to often:
# Final answer text
jq '.results[0].session.finalOutput' out/codenav.json
# Session: every tool call in order
jq '.results[0].session.calls[] | {tool: .name, args: .args}' out/codenav.json
# Cost and latency
jq '.results[0].session.metrics' out/codenav.json
A typical session for codenav on bare Claude:
{ "tool": "Glob", "args": { "pattern": "**/*.go" } }
{ "tool": "Grep", "args": { "pattern": "func HandleLogin" } }
{ "tool": "Grep", "args": { "pattern": "HandleLogin\\(" } }
{ "tool": "Read", "args": { "file_path": "auth/login.go" } }
Four tool calls. The session is your debugger when an answer is correct but the Bench failed somewhere unexpected — or when the answer is wrong and you need to know what the agent saw.
Step 7 — Add a cost ceiling
This Bench runs against Haiku 4.5 with 3-5 tool calls and lands around $0.002. A cost ceiling at $0.01 would be all upside. Add it now — for your own Benches: add cost and latency ceilings on every live Scenario. They are the cheapest defense you have against "the agent went into a tool loop and burned $40 over the weekend."
Append to the checks: list:
- type: cost
threshold: 0.01 # adjust per task; this Bench is ~$0.002
The threshold-tuning rule of thumb: set ceilings at ~1.5–2× the observed max across 2-3 runs. The point is to catch pathological behavior, not to fit a single sample. Re-rolling for a "good" sample is how flaky tests get into CI.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Bench hangs, no output | claude CLI not on PATH | which claude, install via npm i -g @anthropic-ai/claude-code |
| Auth error in JSON | ANTHROPIC_API_KEY unset | export ANTHROPIC_API_KEY=sk-ant-... (or put it in ./.env) |
contains "auth/login.go" fails | Agent answered with a different path | Read finalOutput — it likely says "in the auth package" without the path. Tighten the prompt or relax the Check. |
latency: 95000ms (threshold 90000ms) on cold cache | Network slow, first run | Bump latency to 120000; the Bench-level timeout: 120s is the hard cap anyway. |
What you now know
| Concept | Why it matters |
|---|---|
harness: claude-code | Real LLM in the loop |
testdata: ./... | What the Harness sees as its working tree |
sandbox: home | The copy-and-throw-away mechanism |
Session.WorkDir | The fresh tmpdir; Harness's cwd |
Session.Calls | Every tool call, ordered |
contains-all / any-of | "All N must appear" / "1 of N must pass" |
session:tool-used | Behavior Check — did the agent use this tool? |
latency / cost ceilings | The cheapest pathological-behavior detector you have |
What you do not yet know
This Bench is read-only. The agent never writes a file. The next leap is letting the agent edit code — and proving the edits work by running tests. Tutorial 3 introduces the exec Check, the permission-mode decision tree, and anti-cheat Checks.
Previous: Tutorial 1 — your first Bench, no API key required Next: Tutorial 3 — codegen with exec Checks