Skip to content

feat(llma): emit git branch and repo on ai events#145

Merged
webjunkie merged 1 commit into
mainfrom
feat/emit-git-metadata-on-ai-events
Jul 13, 2026
Merged

feat(llma): emit git branch and repo on ai events#145
webjunkie merged 1 commit into
mainfrom
feat/emit-git-metadata-on-ai-events

Conversation

@webjunkie

Copy link
Copy Markdown
Contributor

Problem

The parser already reads gitBranch from Claude Code transcript entries but drops it before building events, so sessions ingested via llma-cc carry no git context. PostHog engineering analytics attributes LLM token spend to pull requests by joining $ai_git_branch against the PR head ref, which makes interactive Claude Code sessions attributable once these properties exist.

Changes

All emitted events ($ai_generation, $ai_span, $ai_trace) now carry $ai_git_branch (from the transcript) and $ai_git_repo (owner/name, best-effort from git remote get-url origin in the session's cwd, one subprocess per session). Every failure path just omits the property: missing cwd, non-git dir, no origin, timeout, unparseable remote.

Testing

uv run pytest green (84 passed), including parameterized remote-URL parsing cases and build-events cases asserting the properties land on all three event types and are absent when unresolvable.

Agent-assisted (Claude Code session, reviewed via a multi-agent simplify pass before push).

Every $ai_generation, $ai_span, and $ai_trace built from a Claude Code
transcript now carries $ai_git_branch and $ai_git_repo.

The branch comes straight from the transcript's gitBranch. The repo is a
best-effort owner/name derived at ingest time via `git remote get-url
origin` and parsed from ssh or https remotes; the lookup is cached per
cwd so it runs at most once per session, and every failure is swallowed
since the cwd may no longer exist by the time we ingest. Both properties
are omitted when they can't be resolved.

Why: LLM analytics attributes token spend to pull requests by joining
$ai_git_branch against the PR head ref in engineering analytics. Without
these properties interactive Claude Code sessions can't be attributed to
the work they produced.
@webjunkie webjunkie self-assigned this Jul 10, 2026
@webjunkie webjunkie marked this pull request as ready for review July 10, 2026 15:19
@webjunkie webjunkie requested a review from a team July 10, 2026 15:19
@webjunkie webjunkie merged commit e921736 into main Jul 13, 2026
11 checks passed
@webjunkie webjunkie deleted the feat/emit-git-metadata-on-ai-events branch July 13, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants