An evaluation infrastructure layer for autonomous coding agents.
AI coding-agent optimization is an empirical control problem, not a configuration problem.
Intuitive optimization strategies — appending a "be token-efficient" system prompt, banning a tool to force cheaper behavior — routinely make things worse, not better. A system-prompt tweak invalidates the prefix cache for every subsequent turn and gets billed as fresh cache-creation tokens. An instruction warning an agent away from one failure mode can itself act as a hint that primes exploratory behavior it wouldn't otherwise exhibit. A tool restriction can push the agent toward an entirely different, far more expensive capability instead of the cheaper one you intended.
None of this is visible from reading a config diff. It's only visible by running the same task under different conditions, on the real CLI, enough times to separate signal from noise, and measuring cost-per-successful-task — not cost-per-attempt, not token count in isolation, and never without checking that the cheaper arm actually got the answer right. This repository is that measurement harness, plus a small MCP plugin built on top of what it found.
Every run is a real claude -p --output-format stream-json invocation — the actual CLI, not the Agent SDK — so nothing about hooks, skills, plugin behavior, or tool schemas is reimplemented or approximated. Three properties keep the resulting numbers honest:
- Isolated git worktrees. Each run gets a fresh
git worktreechecked out from the task fixture's pinned commit. The agent can do anything it wants inside it; the fixture itself is never mutated, and the worktree is destroyed afterward. - Interleaved A/B batching. Repetitions alternate arm order (
rep0: A→B,rep1: B→A, ...) rather than running all of arm A before any of arm B, so neither arm systematically lands earlier or later in the batch — which matters because prompt-cache warmth and provider load both drift over the course of a run. - Pristine holdout evaluation. Verification never runs inside the agent's own workspace. The harness extracts the agent's edits as a
git diff, applies that diff to a second, untouched worktree, and only there runs the visible acceptance test and a hidden holdout test the agent never had filesystem access to.
graph TD
subgraph Agent Environment
A[Claude Code CLI] -->|Executes Task| B(Worktree A: Agent Mutable State)
end
B -->|1. Extract Changes: git diff| C{Patch Extraction}
subgraph Evaluation Environment
C -->|2. git apply| D(Worktree B: Pristine Pinned Commit)
E[Isolated hidden_tests/] -->|3. Inject holdout_test.sh, agent session already ended| D
D -->|4. Execute| F[acceptance_test.sh + holdout_test.sh]
end
F --> G[(Run Ledger: Cost, Tokens, Pass Rate)]
classDef pristine fill:#e1f5fe,stroke:#0277bd,stroke-width:2px;
classDef agent fill:#ffebee,stroke:#c62828,stroke-width:2px;
class D pristine;
class B agent;
hidden_tests/holdout_test.sh lives outside the fixture entirely, so the agent's worktree — checked out from the fixture's pinned commit — never contains it at any point the agent could read it, under any tool permission. It only gets copied into Worktree B after the agent's session has fully terminated.
Three intuitive optimizations, tested against the same harness, that didn't do what they were supposed to:
- The Prompt Tax. Appending a "be token-efficient, avoid re-reading files" system prompt to the optimized arm didn't reduce cost — it increased it by 13%. The added instruction text broke prefix-cache reuse across turns, and the resulting cache-creation tokens (billed at a premium over cache-read) outweighed whatever tokens the instruction saved.
- The Observer Effect. Warning an agent away from a specific inefficiency ("never cat a whole log file") didn't prevent that inefficiency — the warning itself acted as a hint, priming defensive, exploratory probing of the exact file it was told to be careful with, that the unprompted baseline never bothered to open at all.
- The Capability Trap. Disallowing
Bashon a ~50-file repository to force cheaper native-tool usage caused a 160% cost explosion, not a reduction. Denied a shell, the agent spawned nested subagents to route around the restriction — a completely different, far more expensive capability than the one the restriction was meant to encourage, and one the harness's turn-accounting didn't even attribute correctly until this run's raw log was traced by hand.
Blanket restrictions and prompt tweaks are gambles. What actually worked was deciding per task whether it was safe to use a cheaper model at all, via a single pre-flight classification call (harness/route_task.py):
- LOCALIZED tasks — the prompt already names or implies the file to edit — route to Haiku: -70% mean cost, -76% Cache-Creation Tax, no drop in visible or hidden holdout pass rate.
- DIAGNOSTIC tasks — the prompt only describes a symptom and the fix requires cross-file investigation — fall back to Sonnet.
- The router requires confidence ≥ 0.80 before it will commit to LOCALIZED; anything less falls back to Sonnet. The two failure modes aren't symmetric — a wrong DIAGNOSTIC-routed-to-Sonnet call just costs a little more than necessary, while a wrong LOCALIZED-routed-to-Haiku call risks a confidently-wrong fix nobody notices — so the default under uncertainty has to be the expensive, safe model, not the cheap one.
Known limitation, reported rather than smoothed over: the threshold is a mitigation, not a solved problem. On a task whose prompt happens to name a file even though the actual bug requires diagnostic reasoning, the classifier's confidence landed right at the 0.80 boundary and was genuinely unstable across repetitions (routing to Haiku in 2 of 5 runs, Sonnet in the other 3, on the identical prompt). The threshold caught the low-confidence cases correctly; it does not fix a classifier that's confidently looking at the wrong signal.
mcp-plugin/ packages the same classifier as a standalone MCP server, so a live Claude Code session can ask "should this be a cheap-model task?" before spending money running it — no fixture directory or harness setup required, just a prompt.
Install it:
cd mcp-plugin && npm install
claude mcp add agent-finops -- node "$(pwd)/index.js"It exposes one tool, analyze_task_complexity(prompt, file_tree?), returning the classification, confidence, reasoning, recommended model, and the exact cost of the classification call itself.
# 1. Reconstruct each fixture's local git repo (see scripts/init_fixtures.sh for why
# this is a separate step rather than something checked into the repo).
./scripts/init_fixtures.sh
# 2. Run a batch: N repetitions, interleaved, per arm.
cd harness
python3 run_experiment.py --task-dir tasks/fix-calc-bug --arms baseline routed --n 5
# 3. Aggregate and compare.
python3 aggregate.py --task-dir tasks/fix-calc-bug --arm baseline --output results/fix-calc-bug/baseline/summary.json
python3 aggregate.py --task-dir tasks/fix-calc-bug --arm routed --output results/fix-calc-bug/routed/summary.json
python3 compare.py --baseline results/fix-calc-bug/baseline/summary.json \
--optimized results/fix-calc-bug/routed/summary.json \
--output results/fix-calc-bug/comparison.jsonSee harness/ARCHITECTURE.md, harness/DATA_MODEL.md, and harness/IMPLEMENTATION_PLAN.md for the full design rationale and schema.