Skip to content

How to calculate AI coding cost per commit or pull request

Learn how to price coding-agent usage, calculate cost per commit and pull request, and build benchmarks that account for unshipped work.

By Brayden Yancy · · 5 min read

An invoice can tell you what you paid for coding agents. If the bill goes up, the question I want to answer is where the extra spend went. Did one repository get busier? Did more work reach the default branch? Did an agent spend the afternoon on a branch that never merged?

In the first sample I published, I recorded 2.86 billion tokens and about $4,099 in estimated usage across 944 commits. Dividing those figures gives about $4.34 per commit for that sample. To use the number as a benchmark, you need a way to follow the spend back to the work and show what the average leaves out. See the original sample.

Price each usage event

Start with the token counts and the rates for the model that handled the event. Price fresh input, output, cache reads, and cache writes separately. For example, suppose a turn uses 20,000 fresh input tokens, 2,000 output tokens, 120,000 cached input tokens, and 4,000 cache-write tokens. At illustrative rates of $3, $15, $0.30, and $3.75 per million, its estimated cost is $0.060 + $0.030 + $0.036 + $0.015 = $0.141.

Use the same rate basis for both sides of a benchmark. A model price change can move the dollar estimate even when usage is unchanged. Keep subscription fees and provider invoice totals separate. If a required rate or token detail is missing, report the known charges and the pricing coverage. An unknown charge can materially change the result. Read how GreenAI reports estimated cost and coverage.

Trace usage to commits, branches, and pull requests

A usage event usually has no commit hash. Centrail uses repository identity, event time, Git branch, and authorship to find a recorded commit at or after the event. It prefers your own commit on the session’s branch, then any commit on that branch, then your own commit elsewhere in the repository, and finally the earliest remaining candidate. Within each preference, the earliest commit wins. If no candidate exists, the usage stays unlinked. Commit matching currently covers Claude Code and Codex. Other captured agent usage can still contribute to cost totals.

From there, GreenAI can show the estimated cost of individual commits and roll them up by repository and branch. In personal scope, it can also associate usage with a uniquely matched, recorded merged GitHub pull request. A branch name alone cannot establish pull request membership. The allocation uses recorded evidence and can change as more Git history arrives. Establishing who or what wrote a change takes different evidence. Read the full Git attribution method.

Worked example from the GreenAI demo

In one seven-day view of the public demo, the dashboard had $2,413.44 in known estimated cost. The sample had 21,744 fully priced events out of 21,809. The Git view accounted for the known cost as follows.

  • Shipped: $1,694.83 across 56 linked commits that reached the default branch.
  • In flight: $277.97 across 19 linked commits.
  • Unshipped: $174.99 across 12 linked commits.
  • Unchecked: $136.03 across 6 linked commits whose ship status was unavailable.
  • Unlinked: $129.62 in known cost without a recorded commit match.

The four linked groups add up to $2,283.82 across 93 commits. Allocated cost per commit is $2,283.82 ÷ 93 = $24.56. The shipped subset averages $1,694.83 ÷ 56 = $30.26 per shipped linked commit. Linked cost represents 94.6% of known cost, and the shipped subset represents 70.2% of known cost. Each figure answers a different question about the same usage. The demo uses sample data. Open the GreenAI demo and drill into Git work.

Handle the cases that change the result

  • PRs crossing the date boundary. If a PR has $8 of matched usage before your selected week and $22 during it, the week’s PR figure is $22. A lifetime view would need both periods and any additional captured usage. The reporting window follows usage dates.
  • Squashes and rebases. Keep the connection between the original work and the change that landed. Centrail uses patch hashes and, when available, GitHub evidence to recognize rewritten work. A squash can change the commit count, so use the same counting convention across benchmark runs.
  • Closed work and missing matches. A closed, unmerged PR and a session with no commit evidence represent different cases. Keep unshipped or abandoned spend visible. If a commit disappears with no equivalent, Centrail can preserve its allocation in an abandoned group. Abandoned and unlinked usage stay outside allocated cost per commit.
  • Ambiguous pull requests and missing prices. Keep ambiguous spend separate instead of counting it under multiple PRs. If no commits received an allocation, the cost-per-commit average is unavailable.

Benchmark comparable work

Choose a unit that reflects the question. Cost per linked commit helps investigate Git work within a repository. For a workflow or model benchmark, select comparable issues, define success in advance, and count the cost of every attempt, including retries. Keep the model rates, date range, and capture scope consistent where the comparison calls for it. Report the completion rate, cost per completed task, and median and range of task costs. Add review or rework time if it matters to the decision.

For example, suppose two workflows each finish three comparable issues. The first costs $10, $12, and $38 per completed issue, plus $15 on an abandoned attempt. Its total cost per completed issue is ($60 + $15) ÷ 3 = $25, and its median completed issue costs $12. The second costs $14, $15, and $21, with no abandoned spend. Its total cost per completed issue is $50 ÷ 3 = $16.67, and its median is $15. In this illustrative sample, the second workflow costs less overall, even though the typical completed issue costs more. With three issues, that is a reason to investigate the expensive attempt and run more cases.

GreenAI supplies the usage, pricing coverage, Git allocations, and ship status you can investigate by repository and branch. For a completed-task benchmark, bring the issue records and acceptance criteria as well. I would start with one repository, open the underlying Git work, and check whether the same conclusion holds after accounting for unlinked usage and work that never shipped. Try the Git work view with sample data.