← Back to Blog

AI Coding Cost per Commit: Token Math for Feature Branches vs Main Merges

By Eric Bush · July 1, 2026 · 9 min read

Cascading rows of chocolate bar wrappers, evenly spaced

Why Per-Commit Cost Is a Useful Unit

Per-token cost is what the vendor bills you. Per-task cost is what a coding agent charges to complete a specific feature. But per-commit cost is the unit that actually maps to git history — every commit is a discrete unit of shipped work, and knowing what each cost lets you tell an engineering manager exactly where the token budget is going.

The catch is that commits vary in size by orders of magnitude. A typo fix and a full-feature merge both count as one commit but have entirely different token profiles. Here's how to make the math useful anyway.

The Five Commit Types and Their Token Signatures

Based on typical Claude Code and Cursor session data, commits fall into five cost bands. Estimates below assume Claude Sonnet 5 promo pricing ($2/M input, $10/M output):

Commit type Typical input Typical output Cost
docs: typo fix 15K 200 $0.032
chore: dependency bump 40K 2K $0.10
fix: bug fix 120K 8K $0.32
feat: single-feature 400K 25K $1.05
refactor: multi-file 800K 60K $2.20

Two commits with the same one-line diff can cost 10× different amounts, because most of the input is the agent reading surrounding context, not the diff itself. That's the punchline: commit size doesn't predict cost — investigation depth does.

Feature Branches Are Cheaper per Commit Than Direct-to-Main

Counterintuitive but consistent in the data: pushing many small commits on a feature branch tends to cost less per commit than direct-to-main because agents on feature branches accumulate cache. The system prompt, project structure, and open-file context all stay warm across successive commits.

In a feature branch with 8 commits worked on across two hours, cache hit rate for stable context can reach 70%. Cache reads price at roughly 10% of write cost. Practically:

  • First commit in session: pays full write cost on system prompt + project structure (~$0.30–0.60 of overhead).
  • Commits 2–8 in the same session: overhead drops to ~$0.03–0.06 each.
  • Total 8-commit session: ~$2.50 vs. ~$6.00 spread across 8 separate sessions.

Direct-to-main workflows tend to have shorter, more isolated sessions. Cache benefits never materialize. The token bill can be 2–3× higher for the same total output.

The Merge Commit Cost Nobody Tracks

A merge to main from a feature branch has its own hidden cost — code review by an AI reviewer. If your PR flow includes an AI code review pass (BugBot, CodeRabbit, Copilot, or a home-grown Claude-based reviewer), that's an extra 200K–500K input tokens for the reviewer to load context, plus 5K–15K output for review comments.

Merge-time cost profile:

  • AI code review: $0.60–1.50 per PR
  • Automated changelog generation: $0.10–0.30 per PR
  • Test regeneration if needed: $0.50–2.00 per PR
  • Total merge-time overhead: $1.20–3.80 per PR

Squash-merge workflows compress this into a single fat commit and hide the underlying per-commit spend. Merge-commit-preserving workflows leave the granular data intact but need explicit instrumentation to attribute cost to specific commits.

Attributing Cost to Commits Programmatically

Most teams track total monthly LLM spend. Very few attribute individual commit cost. The minimal setup:

  1. Add a git hook that captures session start/end timestamps around each commit.
  2. Route agent traffic through a gateway (LiteLLM, Portkey, or the new Anthropic Claude apps gateway) that logs per-request tokens.
  3. Correlate token spend to timestamps via a nightly aggregation script.
  4. Annotate git log output with cost per commit in your team dashboard.

This is roughly a half-day of engineering effort. The payback is finding the outliers — commits that cost 10× the median usually indicate agent trajectory bugs (retry loops, wrong-file investigation, oversized diffs) worth fixing.

Rules of Thumb for Cost-Aware Committing

  • Work on feature branches when possible — cache reuse cuts costs significantly.
  • Don't restart the agent mid-branch unless you have to. Long sessions are cheaper than fresh ones.
  • Group related small commits into one session. Two typos in one session is cheaper than two typos in two.
  • Instrument your gateway before optimizing. Guessing at cost drivers usually finds the wrong culprit.
  • Watch for the “refactor” outlier — one big refactor commit can cost more than a week of features.

Want to calculate exact costs for your project?

Frequently Asked Questions

What's the average cost per AI-generated commit?

Highly variable. Typo fixes run $0.03; single-feature commits around $1; multi-file refactors $2 or more. On Claude Sonnet 5 promo pricing, a typical mixed-commit developer day lands around $8–15.

Why do commits with the same diff size cost so differently?

Most token cost is investigation, not diff generation. An agent reading 400K tokens of context to write one line costs 40× more than an agent that already has the context cached.

Do feature branches really save money over direct-to-main?

Yes, primarily through prompt cache reuse across multiple commits in a single session. Cache hits price at ~10% of write cost, so long sessions on a feature branch amortize context loading.

How do I track cost per commit specifically?

Route agent traffic through a gateway that logs per-request tokens, add git hooks to capture session boundaries, and correlate the two via timestamp aggregation. About half a day of setup for the first working version.

What's the hidden merge-time cost per PR?

Between $1.20 and $3.80 per PR when you factor in AI code review, changelog generation, and test regeneration. Squash-merge workflows hide this by folding it into the merged commit's cost.