How AI Code Ratio is calculated

Last updated: November 12, 2026

AI Code Ratio is the share of your merged code that Span saw a coding agent write. Span works it out on its own servers from Agent Traces, by matching the edits in each author's recorded agent sessions against the merged pull request diff.

Why it matters

When leaders look at AI Code Ratio, the real question is usually: how much of our engineering work is driven by AI? Tool usage reports count suggestions people accepted in the editor, including code that never merged. AI Code Ratio looks only at code that merged, and credits a line to AI only when Span has evidence from the session that produced it.

How it works

Span calculates AI Code Ratio from Agent Traces, in five steps for each merged pull request.

1. Find the sessions behind a PR. For each PR, Span looks only at sessions owned by the PR author. A teammate's sessions never count toward your PR. A session is a candidate when it was active between 3 weeks before the PR opened and the merge, and it edited at least one file in the PR. Edits made after the merge never count. Span does not link sessions by commit SHA or branch name; the link comes from matching code.

2. Match lines. Span compares the PR's final diff with the edits the agent made in those sessions. Before comparing, it ignores differences in case and whitespace. It matches each added or deleted line using up to 3 surrounding lines as context. It also replays the agent's edits to find the agent's version of each file closest to what merged, and treats the remaining difference as human edits. Any other change to a line after the agent wrote it means the line no longer matches, so it counts as human. That includes a person editing it by hand and a formatter or linter changing punctuation, such as quote marks or trailing commas, outside an agent session.

Span works from the PR's diff as a whole, not from individual commits, and recomputes when new commits land. Squashing, rebasing, or splitting work into more commits doesn't change line matching, because Span matches against the whole-PR diff. It can change whether the PR counts as 100% AI, because that rule looks at each commit's agent author or co-author.

3. Count lines. Span counts lines in code files only, in any language. A modified line counts twice, once as the old line removed and once as the new line added:

Total lines = lines added + lines deleted + 2 × lines modified

It leaves out files that match your ignore rules in Settings → Metrics, non-code files (Markdown, plain text, CSV, JSONL, and files with no extension such as Makefile), and files where the PR only deletes lines. A PR's AI lines can never be more than its total lines.

4. Keep only qualified PRs. The ratio includes only qualified PRs that were merged, including ones later reverted. Qualified PRs are ones where Span can vouch for the author's trace coverage. A PR that doesn't qualify leaves both the top and the bottom of the ratio. See How are PRs considered qualified in the AI Impact report when using traces?

5. Add it up. Each PR's weight is capped at 1,200 lines, and a capped PR keeps its own ratio, so one very large PR can't set the number for everyone:

PR weight = min(total lines, 1,200)
Capped AI lines = AI lines × PR weight ÷ total lines
AI Code Ratio = Σ capped AI lines ÷ Σ PR weight   (qualified PRs that were merged, including ones later reverted, by merge date)

Long sessions and several PRs. One session can feed several PRs by the same author. Each PR gets credit for the lines that match it. If two sessions claim the same line, Span counts it once. A subagent's lines go to its parent session.

With Snapshotting. Snapshotting is in closed beta on macOS. Your Span account team can tell you whether your organization can join. For organizations in the beta, auspex compares the state of your Git repository over time, instead of only watching for file edits, and three rules decide attribution:

  1. Changes made while an agent session is active count as AI-driven. This includes direct edits, shell commands, scripts, generated files, and formatting or linting changes.

  2. Changes made and committed outside any active session count as human. The commit has to land before the next agent session touches that repository.

  3. Latency is unaffected. Measurement runs in the background, outside the agent's critical path.

Snapshotting example: you ask Cursor to update a component and it changes 100 lines. Before your next prompt, you edit 20 lines yourself, then prompt the agent again in the same session. All 120 lines count as AI-driven. If you had instead closed the session, made your 20-line edit, and committed it before starting a new session, those 20 lines would count as human.

Setup

  • Agent Traces must be on for your organization, with auspex installed on developer machines. Contact your Span account team to get started.

  • Snapshotting is in closed beta on macOS. Your Span account team can tell you whether your organization can join. For details, see Snapshotting: More complete AI code attribution with auspex.

You see AI Code Ratio on the AI Effectiveness Overview, in AI insights → Comparison, in custom dashboards, and on each PR. The PR author can see line-by-line attribution on their own PRs.

Things to know

  • It needs session evidence. Without traces from the author's machine, Span can't attribute a PR. Authors with no traces drop out instead of showing 0%.

  • Hand edits after the agent count as human. Heavily edited AI code lowers the ratio. Without Snapshotting, code an agent wrote through a raw shell command (for example a sed script) may not be attributed.

  • Small PRs work the same way. There is no minimum size. A PR where less than 20% of the lines match the author's sessions qualifies only when the author's traces ran without a gap around it.

  • Agent-authored PRs count as 100% AI. When every commit carries an agent author or co-author, Span counts the whole PR as AI, unless the PR’s linked sessions show the same tools, in which case Span uses the line match.

  • Snapshotting attributes changes made during an active session to the agent. Hand edits during an active session count as AI-driven. Uncommitted hand-written work still in the repository when a later session starts counts as AI-driven. Expect the ratio to rise and trend charts to step up when Snapshotting starts.

  • New PRs take a few hours. Attribution and qualification run a few hours (usually 2 to 6) after a PR merges, so the last day or so can look incomplete.

Why the ratio can look lower than expected

  • Tools Span doesn't record. Span only sees sessions from AI tools that auspex records. Code written with another tool, or accepted from inline editor suggestions, counts as human on a qualified PR. See Understanding Agent Traces in Span (auspex) for the tools auspex records.

  • Edits after the session. Hand edits, review fixes, and formatter or linter changes made outside an agent session turn matching lines into human lines.

  • The 1,200-line cap. A very large PR that is mostly AI counts as 1,200 lines. If you divide raw AI lines by raw total lines yourself, you get a higher number when large AI PRs exist.

  • Comparing with accepted lines. Vendor reports of accepted AI lines include code that never merged or was later rewritten, so they run well above AI Code Ratio. See Understanding Accepted AI Lines vs. All Merged Lines in the AI Tool Adoption report.

  • Comparing with all merged PRs. Only qualified PRs count. A developer you know uses AI can show few or no PRs when their traces had gaps, their PRs opened before their traces started, or their PRs carry agent markers on only some commits.

  • Recent rollouts or measurement upgrades. After AI Code Ratio capture changes are enabled, organization-level ratios can stay temporarily lower for several days because newly merged PRs may still come from sessions that started before the new capture method was on. Wait for enough newly captured sessions and PRs to flow through before treating the new value as the long-term baseline; in some cases, this has taken about a week, depending on team workflow and merge patterns.

Worked example: the cap. PR A has 3,000 lines, all AI-written. PR B has 600 lines, none AI-written. Uncapped, the ratio would be 3,000 ÷ 3,600 = 83%. With the cap, PR A's weight is 1,200 and its capped AI lines are 3,000 × 1,200 ÷ 3,000 = 1,200 (still 100% AI). PR B keeps its 600 lines. The ratio is 1,200 ÷ (1,200 + 600) = 67%.

Worked example: line counting and matching. A PR adds 120 lines, deletes 20, and modifies 30, so it has 120 + 20 + 2 × 30 = 200 lines. 150 of those lines match the agent's edits in the author's session, and the author wrote the other 50 by hand. That PR is 150 ÷ 200 = 75% AI. If a formatter then rewrote the quote marks on 30 of the agent's lines outside the session, those 30 lines no longer match, and the PR is 120 ÷ 200 = 60% AI.

Tip: with Snapshotting on, make hand-written edits outside an active agent session and commit them before starting the next one if you want them counted as human.

Related articles

How are PRs considered qualified in the AI Impact report when using traces?

Snapshotting: More complete AI code attribution with auspex

Understanding Agent Traces in Span (auspex)

Understanding Accepted AI Lines vs. All Merged Lines in the AI Tool Adoption report

Need help?

Contact your Span account team or reach out to support@span.app.