AI Coding Agent ROI: Count What Survives the Merge

Measure AI coding agent ROI after the merge: cost per PR that survives 30 days, first-pass merge rate by task size, and escaped defects by severity.

Clint JohnsonPublished 8 min read

Key takeaways

  • Measure agent ROI as model spend plus reviewer minutes plus 30-day rework, divided by verified agent PRs that survive 30 days, and compare it to a human baseline.
  • Size agent tasks by how they are verified, not by lines or points, and track first-pass merge rate separately for each bucket.
  • Report clinical-safety escapes on their own line, and count a PR as verified only with replay results, a diff summary and an audit entry.

I don't care how much code an agent wrote. I care what it cost to get that code to still be standing a month after merge.

That's the only ROI question that matters in the healthcare integration code where I ship agent work, in eSpiral and MedScrub. An escaped defect there isn't a misaligned button. It's a CDS Hooks card shown at the wrong urgency, or an HL7v2 mapping that quietly drops a lab result. Lines of code, suggestion acceptance rate and PR count can't tell you which of those you shipped.

My rule for agent work comes from the Claude Code support loop I built for MedScrub. The agent works in a fresh worktree off a clean main. It writes a failing test first, opens a PR, and stops. It never merges its own work. For FHIR and HL7v2 interface code, a verification loop decides when the work is done: the FHIR Validator, replay diffs and terminology checks. The agent doesn't get to say done. It doesn't get to say it was worth it either.

So I measure after the merge. Add model spend, reviewer minutes and 30-day rework. Divide by the agent PRs still standing 30 days later. Track escaped defects on their own, split by severity.

Drop lines of code, acceptance rate and PR count

Lines of code reward bloat. Agents produce code almost for free, and every line is something a human has to review and maintain. When LOC goes up, your review load goes up. That's a cost, not a return.

Suggestion acceptance rate counts how often a human clicked accept. That mixes code quality with reviewer patience. It says nothing about what survives after merge.

PR count is the sneaky one, because it sounds like an outcome. Salesforce's headline number is exactly this metric. It reports that in April 2026, compared with a year earlier, merged PRs per developer rose 79% and incidents fell 5%. Those figures come from its internal Engineering 360 platform and can't be independently verified. A 79% jump in merged PRs shows something happened. It doesn't show what survived. A PR reverted in week two is rework you haven't paid for yet, and it still counts in that 79%.

Don't trust how fast it feels, either. In METR's randomized trial, experienced open-source developers believed AI tools made them 20% faster. They were measured 19% slower. If the people doing the work can't feel the difference, a dashboard built on their activity won't either. Measure outcomes.

Size tasks by how they get verified

Don't size agent tasks by lines, story points or how much of the codebase the agent has to read. Agents are good at exploring code file by file. Exploring a task is not the same as proving it. Ask one question instead: can a machine tell me this is right before a human reads it?

BucketWhat proves it's correctExample
Replay-verifiedReplaying captured messages and diffing output against mainRemap one HL7v2 field into a FHIR Observation
Test-verifiedUnit and integration tests, no replay corpusA new parser helper with clear inputs and outputs
Review-verifiedOnly a human reading it can tellLogic that decides whether a CDS card fires at all

Then track first-pass merge rate for each bucket. My definition: the PR merges with no logic changes after the first human review. Formatting nits don't count against it.

The mistake to avoid is a single blended rate. Easy replay-verified tasks flatter the number and hide a review-verified bucket that is failing. When a bucket's rate drops, you have two moves. Split those tasks smaller, or build the verification that moves them up a row. Usually that means adding replay fixtures. The second move compounds, because fixtures move some review-verified work into replay-verified work. Not all of it. Whether a CDS card should fire at all stays a human call.

Cost per surviving PR

Here's the ledger:

(model spend + reviewer minutes × loaded rate + 30-day rework hours × loaded rate) ÷ verified PRs that survive 30 days

  • Model spend includes abandoned PRs. You paid for those tokens.
  • Reviewer minutes go in even though they're hard to measure. Leave them out and your ledger becomes a vendor dashboard. Have reviewers log them, because PR timestamps can't tell you how long someone spent reading.
  • Rework means reverts, hotfixes and any follow-up PR linked to the original within 30 days.
  • Survives means merged, not reverted, and no linked fix inside the window.
  • Unverified PRs put their cost in the numerator and nothing in the denominator.
-- cost per surviving agent PR, cohort opened 30-60 days ago
SELECT
  (SUM(model_usd)
   + SUM(review_minutes) / 60.0 * :reviewer_rate
   + SUM(rework_hours) * :eng_rate)
  / NULLIF(COUNT(*) FILTER (WHERE survived_30d AND verified), 0)
  AS cost_per_surviving_pr
FROM agent_prs
WHERE opened_at >= now() - interval '60 days'
  AND opened_at <  now() - interval '30 days';

Then build the human baseline from human-authored PRs in the same window. Make two changes: replace model spend with author hours at the loaded rate, and drop the verified filter, since human PRs won't carry agent evidence. Divide the agent number by the human number to get relative cost per surviving PR. Without that baseline you have a cost, not a return.

The arithmetic, with made-up numbers

These numbers are invented to show how the ledger behaves. They are not from my codebase. Assume a $150/hour loaded rate for everyone.

  • Agent cohort: $600 model spend. 1,800 reviewer minutes, which is 30 hours or $4,500. 20 rework hours, or $3,000. Total $8,100 over 30 verified PRs that survived 30 days. That's $270 per surviving PR.
  • Human cohort: 160 author hours ($24,000), 600 reviewer minutes ($1,500) and 8 rework hours ($1,200). Total $26,700 over 20 surviving PRs, or $1,335 per surviving PR.
  • Relative cost: 270 ÷ 1,335 ≈ 0.20.

Three things to notice. First, review is the biggest line on the agent side. Drop it and the agent's cost falls to $120 per PR, the flattering number a dashboard would show you. Second, if 10 of those 30 survivors had shipped without evidence, the denominator drops to 20 and the cost rises to $405. Third, compare within a bucket. If the agents took the replay-verified remaps and humans took the review-verified CDS logic, a 0.20 ratio is comparing different kinds of work.

Escaped defects, split by severity

An escaped defect is any bug found after merge. Count them per surviving PR, and never combine severities into one number.

  • Clinical safety. A CDS Hooks card on the wrong patient, or with the wrong indicator. The spec uses info, warning and critical to set how urgently the EHR shows a card, so a critical finding shipped as info is a safety failure. Also: an HL7v2 mapping that drops a result, puts a value in the wrong field, or loses a unit.
  • Data integrity and operations. Messages rejected and queued, duplicates, retry storms. These cost money, but nobody gets the wrong care.
  • Cosmetic. Bad labels, log noise, UI glitches.

Average these together and ten cosmetic fixes can hide one clinical-safety escape. Report clinical-safety escapes on their own line, with their own trend.

Attach a policy to that line. One clinical-safety escape from agent work drops its task bucket to review-verified. It stays there until the replay corpus has a case that would have caught the escape. That rule turns each escape into a fixture, so replay catches that case next time.

For the delivery side, use change fail rate and deployment rework rate as DORA already defines them, and split both by agent versus human authorship. Don't invent new names for numbers your team already knows.

The evidence bar before a PR counts

An agent PR needs three artifacts before it counts as verified work:

  1. Replay results. The change runs against a captured, de-identified fixture corpus, and the output is diffed against main. The PR either has zero unexpected diffs or lists every expected one.
  2. A diff summary. What changed, what was intentionally left alone, and which mappings or cards are affected. The reviewer checks the summary against the real diff. If the summary claims something the diff doesn't show, the PR fails.
  3. An audit entry. Which model, which session, which task, which commands ran, and who reviewed. In a healthcare codebase that trail is worth keeping even if nobody ever asks about ROI. Keep the fixtures de-identified, because a coding session is a bad place for PHI. A BAA covering the tool doesn't make your setup compliant. I covered that in Is Claude Code HIPAA Compliant?

If any of the three is missing, the PR is labeled unverified. It can still merge if a human signs off. But it carries its full cost in the ledger and adds nothing to the denominator. That gives people a reason to produce the evidence instead of skipping it.

Have the replay job run in CI on the PR's head commit and upload its report as an artifact. The gate pulls that report and checks the PR body:

# mark the PR unverified unless all three artifacts are present
sha=$(gh pr view "$PR" --json headRefOid -q .headRefOid)
run=$(gh run list --commit "$sha" --workflow replay.yml --json databaseId -q '.[0].databaseId')
fail() { gh pr edit "$PR" --add-label unverified; exit 1; }
gh run download "$run" -n replay-report || fail
jq -e '.unexpected_diffs == 0' replay-report.json >/dev/null || fail
body=$(gh pr view "$PR" --json body -q .body)
for s in "## Replay results" "## Diff summary" "## Audit entry"; do
  grep -qF "$s" <<<"$body" || fail
done

The script checks that the evidence exists. It can't check that the diff summary is honest. That stays a human job, and those are the review minutes worth paying for. It's also why I hire for agency over raw intelligence. Agents make code cheap. A reviewer who will reject a confident summary that doesn't match the diff is not cheap.

Put your effort into making verification cheap. Replay fixtures, evidence templates and audit entries move every number in this ledger. For the broader patterns, see what the teams shipping coding agents have figured out. The test is two lines on one dashboard. If relative cost per surviving PR is falling and the clinical-safety line stays flat at zero, the agent is earning its keep.

Questions people ask

How do you measure ROI of AI coding agents?

Add model spend, reviewer minutes times a loaded rate, and 30-day rework hours, then divide by verified agent PRs that survive 30 days without a revert or linked fix. Build the same number for human PRs from the same window, using author hours in place of model spend, and divide the agent number by the human number.

What metrics should you track for AI coding agents?

Drop lines of code, suggestion acceptance rate and PR count. Track cost per surviving PR, first-pass merge rate for each verification bucket, and escaped defects split by severity, with clinical-safety escapes on their own line.

How big should tasks for a coding agent be?

Size tasks by how they can be verified: by replaying captured messages, by tests, or only by human review. Track first-pass merge rate per bucket, and when a bucket's rate drops, split those tasks smaller or add replay fixtures.

What should a coding agent show before you trust its PR?

Replay results with no unexpected diffs, a diff summary the reviewer checks against the real diff, and an audit entry recording the model, session, commands run and reviewer. Without all three, the PR is labeled unverified and adds cost to the ledger but nothing to the denominator.