feat(git): attribute AI spend to commits
Summary
This adds a new codeburn git-cost command for attributing local AI coding spend to commits in the current git repository.
The goal is to answer a question that the existing aggregate reports cannot answer directly: after spending on AI sessions inside a repo, which nearby commits are those sessions most likely associated with, and how much spend remains unattributed?
What changed
- add
codeburn git-costas a new CLI command - support
--sincewindows fortoday,week/7days/7d,30days/30d,month, and custom day windows such as14d/14days - support
--providerfiltering so attribution can be scoped to one provider - support
--window-minutesto control how long after a session ends commits can still be linked to that session - support
--jsonfor scripts and downstream tooling - document the command in the README and add an Unreleased changelog entry
Attribution model
git-cost only considers usage sessions whose recorded project path belongs to the current git repository. For each matched session, it looks for commits in the current checkout's git log whose committer timestamp falls between:
- the session's first usage timestamp
- the session's last usage timestamp plus the configured post-session window
If a session maps to exactly one commit, that commit receives the session's full cost. If a session maps to multiple commits, the session cost and call count are split evenly across those commits so the report does not double-count spend. Sessions without a matching commit are kept visible as unattributed spend.
The command uses git committer timestamps (%cI) because that is the same timestamp family used by git log --since/--until. That avoids dropping rebased, amended, or cherry-picked commits because of older author dates.
Output behavior
The text output shows:
- repository name and path
- selected period and attribution window
- total repo spend
- attributed and unattributed spend
- top attributed commit costs
- largest unattributed sessions
The JSON output exposes the same summary plus commit rows and unattributed session rows for automation.
Caveats
This is intentionally heuristic. It identifies commits that are close to AI usage sessions in time; it does not prove that a commit was AI-authored.
Attribution also depends on providers recording usable project paths. If a provider only exposes a project name, multiple repos share the same final directory name, or an upstream parser normalizes a path differently, some sessions may appear as unattributed.
Validation
npx vitest run tests/git-cost.test.tsnpm run buildnode dist/cli.js git-cost --helpnode dist/cli.js git-cost --window-minutes 1.5exits with code 1 and the expected validation errornpx vitest rungit diff --cached --check
npx tsc --noEmit is still blocked by existing src/providers/copilot.ts type errors on main; this branch does not touch that provider path.
Validation run on macOS arm64 inside a local git checkout with private details omitted. This is behavior proof for attribution output, not just build proof.
What was checked:
git-cost --jsondetected the surrounding git repository context.- The JSON summary included total, attributed, and unattributed usage buckets.
- The output included attributed commit rows and unattributed session rows without double-counting totals.
- The test suite covers period parsing, attribution windows, split attribution across multiple commits, provider filtering, invalid window input, and JSON shape.
Commands:
npx vitest run tests/git-cost.test.ts- 15/15 tests passed.npx tsx src/cli.ts git-cost --since 30days --provider claude --jsonfrom a local git repository - JSON parsed and structural checks passed.
No project names, prompts, paths, session IDs, commit hashes, raw costs, usage totals, or private product details are included here.
Closing this — it's an unsolicited feature PR that's gone stale, and per CONTRIBUTING these should start from an issue with maintainer buy-in. Cleaning up my open-PR queue; happy to revisit via an issue if there's interest.