Here is a commit from our own repo. It adds a feature: 7 files, 187 lines. An agent made it, and the prompt that made it was:

Merge and deploy

That prompt explains nothing. It did not design the feature and it did not write a single line of it. The code was written one prompt earlier, in answer to this:

Yes, add it

And that one only makes sense if you read the prompt before it, where the actual question was asked.

This is the normal shape of work with a coding agent. You talk for a while, the agent edits files across several prompts, and at some point you say "commit it" or "ship it". Git records one author, one message and one timestamp for the lot. git blame will then point every line at that commit, and through it at the least informative prompt in the whole conversation.

We build Origin, a tool that records agent sessions next to the git history, so we had to solve this properly. This post is about how.

Record turns, not commits

The first decision is the unit. A commit is the wrong one, because it is whatever happened to be in the working tree when someone said "commit". The right unit is a turn: one prompt, plus everything the agent did before it stopped and waited for you again.

Most coding agents (Claude Code, Codex, Cursor and others) let you hook into three moments, and those are enough:

  • A prompt is submitted. Open a turn and save a baseline of the working tree.
  • A tool is used. If it was an edit, store the file with its old and new content.
  • The agent stops. Close the turn. Store its diff against the baseline, and any commits made while it was open.

Now every turn has its own diff, independent of when a commit happened. A session is a list of turns. A commit is something that occurred during one of them.

Ask about the work, not the turn

With that in hand, "which prompt is behind this commit?" splits into two questions with two different answers:

  1. Which turn ran the commit?
  2. Which turns wrote what is in it?

For our example the answers are prompt 3 and prompt 2. So the page for that commit shows both, and labels them:

A commit page: the changed files, the diff, and two prompts on the right. Prompt 2 is labelled "Wrote the changes, committed by #3". Prompt 3 is labelled "Made the commit".
Prompt 2 wrote the changes. Prompt 3 only made the commit.

There are three possible labels: wrote the changes (and another prompt committed them), made the commit (and changed nothing itself), or wrote and committed. The prompt that wrote the code goes first, because that is the one a reviewer needs.

The same split runs the other way. In the session view, a turn that changed files but did not commit is not shown as "uncommitted". It says its work is in a commit, and names the turn that made it. Without that, the most productive prompt of a session looks like it produced nothing.

A session view: a timeline with one bar per prompt, then each prompt as a card with its cost and line counts, and the commits shown as rows between them.
One session: five prompts, two commits. Only two of the five prompts changed code.

From a commit down to a line

Knowing which turns fed a commit is file-level. To answer "which prompt wrote this line", we use two methods and prefer the first.

Compute it where the repo is. The CLI that records the session runs on the developer's machine, with the real repository. It can work out the author of every line right there and upload the result. When that map is complete for a file, the server just uses it.

Replay the session. When there is no map, the server rebuilds the history itself. Take the file as it was before the session. Apply the first turn's edits and compare before and after: the new lines belong to prompt 1. Apply the second turn's edits and compare again. Carry on to the end. A line that prompt 2 added and prompt 4 rewrote ends up belonging to prompt 4, which is what you want: it is the prompt that produced the line as it stands.

The result looks like git blame, with prompts where the commits would be:

A per-line blame view: source code on the right, and beside each block of lines the prompt that wrote it, with the author, agent and model.
Every line with the prompt that wrote it. Older lines keep the prompts of the earlier sessions that wrote them.

Two small rules turned out to matter for keeping the numbers honest. A removed line is shown with the prompt that removed it, but nobody gets credit for it as authored code. And a blank line counts for a prompt only when it sits inside an edit we could attribute. A blank line we cannot place counts for nobody.

Say how you know

Not every change to a file is something we watched happen. An agent can run a shell command that rewrites twenty files: a formatter, a code generator, a git rebase. No edit tool was called. All we know is that the file was different when the turn ended.

So every recorded edit carries its evidence. A tool call, an edit hook or a file watcher that saw the write are direct observation. "The file changed while this turn was open" is not. It is a reasonable guess, and we label it as one: the page says the file was inferred and that the write was not observed.

We think this is the part most attribution tools get wrong. A confident "100% AI" built partly on guesses is worse than a smaller number you can defend.

The link has to survive a squash

One more practical problem. The agent commits on a branch. You squash-merge the pull request. On main the work now has a brand new sha, and the commit the agent made will never be seen again. If the session is tied to the old sha only, the link is gone the moment the work matters.

We handle it in two ways. The commit message gets a trailer naming the session and the turn, and trailers survive most rewrites:

Origin-Session: 8961262a-4b4 | Claude Code | 5 prompts | turn 3 

And the server remembers what a commit became after a squash or a rebase, so the branch commit and the commit on main are treated as the same piece of work.

When there is no trailer at all (a machine without the hooks, an amended commit), there are weaker signals left, such as the author and the time. They are used, and the method is stored with the result, so a weak match is never presented like a strong one.

What it changes

Once the link from a line to a prompt holds, review changes a little. You stop reading a 187-line diff cold. You open the commit, see that the code came from "Yes, add it", click through to the conversation, and read what was actually proposed and agreed. The diff becomes the second thing you read, not the first.

The same record is available in the terminal, which also means the next agent can ask it before changing a file:

origin why src/services/review-pr-fix.ts:14 origin blame src/services/review-pr-fix.ts 

The CLI is open source and works with Claude Code, Codex, Cursor and others. If you want to see it on your own repo: https://getorigin.io