Skip to content

Record the git branch a session started on - #54

Merged
gengwg merged 1 commit into
mainfrom
feat/session-branch
Sep 7, 2026
Merged

gengwg merged 1 commit into
mainfrom
feat/session-branch

Conversation

@gengwg

@gengwg gengwg commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Sessions now carry the branch they ran on, read from .git/HEAD in the working directory the harness already reports.

  • A file read, not a git subprocess — no process per session, and it works where git is not installed.
  • Walks up from the working directory, since an agent is usually started below the repository root.
  • Follows a .git that is a file to its real gitdir, which is how worktrees and submodules look.
  • Detached HEAD records the short sha rather than nothing.

Recorded once at session creation and never overwritten: a session that outlives a checkout keeps the branch it began on, because the logs do not say when a checkout happened and anything else would be invention.

Shown beside the agent name (dimmed) with "repo on branch" as the tooltip, and matched by the filter box, so what ran on release/2.4 is a question the table can answer.

One deliberate deviation from the plan: it is not a Prometheus label. Branch is the classic unbounded dimension — this fleet has four today, but a team on ticket branches produces hundreds over a year, multiplied by every agent. Everything else in /metrics has been kept to bounded labels, and this would undo that.

Verified on a fresh ingest of real logs: 146 of 196 sessions got a branch across claude-code, dsh and opencode. TrueForge has none, having no working directory. Tests cover a plain repo, a subdirectory, a worktree, a detached HEAD, a directory that is not a repo, and this repository's own .git. 87 tests pass.

https://claude.ai/code/session_01NZDHk4yVYP4jMZkTUMQ1Lw

Read from .git/HEAD in the working directory the harness already reports:
a file read rather than a git subprocess, walking up from the working
directory since agents start below the repo root, and following a .git
file to its real gitdir so worktrees and submodules resolve.

Recorded at session creation and never overwritten. A session that
outlives a checkout keeps the branch it began on, because the logs do not
say when a checkout happened. Shown beside the agent name and matched by
the filter box, so "what ran on release/2.4" is answerable.

Not a Prometheus label, against the plan: branch is the classic unbounded
dimension, and this fleet's four today would be hundreds on ticket
branches, multiplied by every agent.

On a fresh ingest of real logs, 146 of 196 sessions got one; the rest are
TrueForge, which has no working directory, and stale directories.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZDHk4yVYP4jMZkTUMQ1Lw
@gengwg
gengwg merged commit 1e8af0a into main Sep 7, 2026
1 check passed
@gengwg
gengwg deleted the feat/session-branch branch September 7, 2026 18:48
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.

1 participant