feat(llma): emit git branch and repo on ai events#145
Merged
Conversation
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.
Radu-Raicea
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The parser already reads
gitBranchfrom 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_branchagainst 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 fromgit remote get-url originin 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 pytestgreen (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).