Blog ·

How to track AI-generated code in git

git blame tells you who committed a line. When an AI agent wrote it, that is half the answer: you also want to know which agent, and what it was asked to do.

Where git blame stops

Run git blame on a line an agent wrote and you get a commit hash, the developer who made the commit and a time. That is correct: a person ran the agent and committed the result. It leaves out what you need when the line looks wrong:

  • Was it written by hand or by an agent, and which agent?
  • What was the agent asked to do? A line that rounds money reads differently once you know the request was “store money as integer cents”.
  • Which other files did the same request change?

A good commit message sometimes answers these, but only if someone wrote it down. To answer them every time, the record has to be made when the change happens.

Three ways to keep the record

1. Commit trailers

Many agents end their commit messages with a trailer such as Co-Authored-By: Claude <noreply@anthropic.com>, and some projects ask for Assisted-by: instead. Trailers are part of git history, so every clone has them and git log can search them. They name the agent, but not the prompt, and they exist only if the agent or the developer writes them. The formats are covered in commit trailers for AI coding agents.

2. Agent hooks

Claude Code, Cursor, Codex CLI and Gemini CLI can run a command when you submit a prompt and after the agent edits a file. A hook can record the prompt and the files it touched, and link them to the commit that later includes those files. This is the only way to keep the prompt, because the prompt never reaches git.

3. Where the record lives

The record can be stored in the repository, in git notes or on a separate branch, or in a service outside it. In the repository it travels with the code, but git notes are not pushed or fetched unless you configure it, and the prompts can be read by anyone who can read the code. Outside the repository it can be searched across repositories and has its own access control, but it is one more system to run.

Setting it up with Whyline

Whyline uses all three: it records prompts and edits through agent hooks, reads trailers for every other commit, and keeps the record in a workspace outside the repository that your team shares. How it works walks through each step.

  1. Create a workspace in the dashboard and install the CLI, as in Getting started.
  2. Connect your agent: the Claude Code plugin, or a hook entry for Cursor, Codex CLI or Gemini CLI.
  3. Run whyline init in each repository, so every commit is recorded.
  4. Ask why a line exists:
Example output
$ whyline blame src/orders.ts:2
src/orders.ts:2  const amount_cents = Math.round(order.total * 100);
  a7394e0b · claude-code · dev@example.com · 10/7/2026, 11:10:20 AM
  add orders

  Prompt:
    store money as integer cents

For a commit with no connected agent, Whyline reads the agent from its trailers. A commit with neither is recorded as agent none, so the timeline also shows which commits have no AI involvement on record.

What this does not tell you

  • Attribution is per commit, not per line. A commit that mixes your edits with the agent's is attributed to the agent as a whole. Smaller commits give sharper answers.
  • Some edits are not seen. Inline completions such as Cursor Tab, and files changed by a Codex shell command, are not recorded as edits.
  • Commits made elsewhere have no record. Amends and rebases keep the prompts, but a squash merge made on GitHub creates a commit that no hook on your machine sees.