Git AI

How Git AI Works

Learn how Git AI tracks AI-generated code through the full development lifecycle — from the developer's machine, through code review, and into production.

Video Explanation

Git AI is an open source git extension that tracks AI-generated code in your repositories, linking every AI-written line to the agent, model, and prompts that generated it — so you never lose the intent, requirements, and architecture decisions behind your code.

Most attempts to quantify and track AI code authorship focus on counting lines of code at the moment of insertion. That approach tends to overcount AI code because it doesn't track code through the entire development lifecycle. What if a developer undoes the AI change? Copies an AI function to a new part of the repo? Performs a rebase? Cherry-picks the code many commits later on a different branch? Accurate measurement requires following code from the development machine through to merge.

The metrics Copilot, Cursor, Anthropic share massively overcount the AI Code because they don't track code all the through the SDLC.

Git AI approaches the problem differently: by building an accurate git blame for tracking AI code, accurate stats follow naturally. Git AI preserves AI code attribution as it moves from local development environments, through a PR, through code review, and onto the main branch.

Design choices

  • No workflow changes — Just prompt and commit. Git AI tracks AI code accurately without cluttering your git history.
  • "Detecting" AI code is an anti-pattern — No heuristics to identify AI code. Coding agents explicitly mark inserted hunks as AI-generated, giving you the most accurate attribution possible.
  • Local-first — Works 100% offline, no login required. No filewatchers or keyloggers (critical for enterprise use).
  • Git native and open standard — Avoid tying to a single vendor — the ecosystem is multi-agent. Agents are the new IDEs (developers get to choose).
  • Agent sessions stay out of Git — Git Notes link to agent sessions stored locally, in the Git AI Cloud, or in a self-hosted store.

Part 1: What happens on a developer's machine?

Like git, most of the work happens offline on the developer's machine.

Checkpoints and Agent Hooks

Git AI checkpoints track incremental code changes between the start and end of a commit. Each checkpoint contains a diff between the current state and the previous checkpoint, marked as either AI or human authored. These checkpoints are temporary and are stored in .git/ai until the commit is made.

Coding agents like Cursor, Claude Code, and GitHub Copilot mark their changes as AI authored by invoking Git AI when they make changes. Any agent supporting hooks can work with Git AI. Here's an example of hooks Git AI sets up for Claude Code in ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "hooks": [
          {
            "command": "git ai checkpoint 2>/dev/null || true",
            "type": "command"
          }
        ],
        "matcher": "Write|Edit|MultiEdit"
      }
    ],
    "PostToolUse": [
      {
        "hooks": [
          {
            "command": "git ai checkpoint claude --hook-input \"$(cat)\" 2>/dev/null || true",
            "type": "command"
          }
        ],
        "matcher": "Write|Edit|MultiEdit"
      }
    ],
  }
}

Git AI requires two hooks: one before and one after the agent edits code. The pre-edit checkpoint ensures any human changes since the last agent edit are marked as human authored. The post-edit checkpoint picks up newly inserted AI code and marks it as AI authored.

alt

You can see these checkpoints and the current AI authorship of your working index by running git ai status after any AI:

git ai status
you  ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ai
     4%                                   96%
     100% AI code accepted | waited 33s for ai

29 secs ago     +103      0  Cursor claude-4.5-opus-high-thinking
46 secs ago       +2     -1  Cursor claude-4.5-opus-high-thinking
57 secs ago      +12     -2  Cursor claude-4.5-opus-high-thinking
1 mins ago        +1     -2  Aidan Cunniffe
2 mins ago       +53      0  Cursor claude-4.5-opus-high-thinking
2 mins ago         0     -3  Cursor claude-4.5-opus-high-thinking
2 mins ago        +4     -6  Cursor claude-4.5-opus-high-thinking
3 mins ago        +2     -1  Cursor claude-4.5-opus-high-thinking
5 mins ago        +6    -16  Claude claude-opus-4-5-20251101
5 mins ago         0     -2  Aidan Cunniffe

When code is committed, Git AI condenses all checkpoints into an Authorship Log optimized for fast lookups:

/path/to/file.ts
  promptA: 2-24 31-32
  promptB: 25-30
/path/to/other/file.ts
  promptA: 1-212

Known Limitations

Attribution is not properly preserved in these cases, though work is underway to close these gaps. Known limitations:

  • git mv doesn't move attribution
  • If your team checks in generated code, Git AI will attribute it to human unless it's listed in linguist-generated

Authorship Notes

Authorship Logs are addressed by commit SHA and should be treated as immutable. On post-commit, each Authorship Log is attached to the new commit using a git note.

git log --show-notes=ai
commit 02e97d75fde395576205d18dacf0e51627f356d5 (origin/feat/narrow-git-status-on-checkpoint)
Author: Sasha Varlamov <sasha@sashavarlamov.com>
Date:   Tue Oct 14 18:37:34 2025 -0400

    Filter edited paths/will edit paths to ensure that they are part of the repo

Notes (ai):
    src/commands/checkpoint.rs
      6e4d6f2 51-52,54,58-110,901-931,934-947
    src/git/test_utils/mod.rs
      6e4d6f2 4,410-425

Git Note Format

Here's what a full Git AI note looks like for a commit that touched hooks/post_clone_hook.rs:

hooks/post_clone_hook.rs
  a1b2c3d4e5f6a7b8 6-8
  c9d0e1f2a3b4c5d6 16,21,25
---
{
  "schema_version": "authorship/3.0.0",
  "git_ai_version": "0.1.4",
  "base_commit_sha": "f4a8b2c...",
  "prompts": {
    "a1b2c3d4e5f6a7b8": {
      "agent_id": {
        "tool": "copilot",
        "model": "codex-5.2"
      },
      "human_author": "Alice Person <alice@example.com>",
      "messages": [],
      "total_additions": 8,
      "total_deletions": 0,
      "accepted_lines": 3,
      "overriden_lines": 0,
      "messages_url": "https://your-prompt-store.dev/cas/a1b2c3d4..."
    },
    "c9d0e1f2a3b4c5d6": {
      "agent_id": {
        "tool": "cursor",
        "model": "sonnet-4.5"
      },
      "human_author": "Jeff Coder <jeff@example.com>",
      "messages": [],
      "total_additions": 5,
      "total_deletions": 2,
      "accepted_lines": 3,
      "overriden_lines": 0,
      "messages_url": "https://your-prompt-store.dev/cas/c9d0e1f2..."
    }
  }
}

The top section maps files to agent session IDs and line ranges. Below the --- separator is the JSON metadata for each agent session, including the agent, model, human author, and a messages_url pointing to the full session in your configured store.

Blame and Stats

git ai blame is Git blame for Agents. It is a drop-in replacement for blame that overlays AI authorship information from Git AI notes on top of regular git output.

For line 2 of file.ts inserted by commit 6e4d6f2, Git AI looks up the Authorship Log for that commit to determine if the line was written by an AI. Even if lines have shifted in intervening commits, git blame --line-porcelain <file> provides the original line position for correct lookups and overlay.

alt

Part 2: Distribution

Git AI is a Git extension you can install on every developer endpoint, including via MDM. The CLI staples AI attribution onto every commit using Git notes — no per-repo hooks or configuration required. It's enterprise-ready, compatible with your existing setups and proven to scale.

Part 3: History Rewriting & Merge Operations

Since AI authorship is indexed by commit SHA, rewrite operations that create new commits leave those commits without authorship logs. Git AI automatically rewrites authorship logs after any local rewrite operation.

Git OperationStatus
Merging branches correctly merges attribution
Merging branches with --squash correctly merges attribution
reset --hard resets attribution to the base commit
git replace maintains correct attribution
git worktrees maintains correct attribution
Amending commits correctly preserves attribution
After resolving git conflicts, attribution is correct
Rebase correctly merges attribution
reset --soft and --mixed maintains correct attribution
Cherrypick correctly merges attribution
mv (move or rename files) moves AI attribution to the new file
Stash / Pop maintain correct attribution

Web UI Squash & Merge / Rebase & Merge

Web UI merge operations happen server-side where Git AI isn't running, so authorship logs aren't updated automatically. Git AI for Teams listens for SCM webhooks and reconstructs them, or you can use our free and open source CI workflows on PR merge events.

PlatformOperationStatus
GitHubRebase / MergeBuilt into Git AI for Teams
GitHubSquash and MergeBuilt into Git AI for Teams
GitLabSquash and MergeBuilt into Git AI for Teams
BitBucket CloudSquash and MergeBuilt into Git AI for Teams
Azure Repos PipelinesSquash and MergeBuilt into Git AI for Teams