How AI Code Ratio is calculated

Last updated: October 27, 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 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? Vendor dashboards count suggestions people accepted in the editor, including code that never shipped. 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

1. Find the sessions behind a PR. For each PR, Span looks only at sessions owned by the PR author. 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 each added or deleted line in the PR diff with the edits the agent made in those sessions, ignoring case and whitespace and using 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. A line an agent wrote and a person later changed counts as human.

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, so a PR's 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.

4. Keep only qualified PRs. A PR counts only when Span can vouch for the author's trace coverage. See How are PRs considered qualified in the AI Impact report when using traces?

5. Add it up.

AI Code Ratio = Σ capped AI lines ÷ Σ capped total lines (qualified merged PRs)

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

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. A steady stream of such PRs from an agent Span doesn't record raises the ratio.

  • Snapshotting leans toward AI, by design. It's an upper bound: hand edits during an active session count as AI-driven. If a session ends without a clean signal (a killed terminal, someone walking away), changes in the next few minutes (up to about 6) still 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.

  • Worked example: 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 counts as 1,200 lines (still 100% AI), so the ratio is 1,200 ÷ 1,800 = 67%. Line counting: a PR that adds 50 lines, deletes 10, and modifies 20 has 50 + 10 + 40 = 100 lines.

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.