Skip to content

fix(proxy): detect git branch per-request to fix stale branch header#217

Open
AntonYeromin wants to merge 2 commits intocodemie-ai:mainfrom
AntonYeromin:EPMCDME-11078
Open

fix(proxy): detect git branch per-request to fix stale branch header#217
AntonYeromin wants to merge 2 commits intocodemie-ai:mainfrom
AntonYeromin:EPMCDME-11078

Conversation

@AntonYeromin
Copy link
Contributor

@AntonYeromin AntonYeromin commented Mar 17, 2026

Summary

When a user starts CodeMie CLI on main and then checks out a new branch during the session (e.g., asks the LLM to create/checkout a branch), all subsequent LLM requests were still sending X-CodeMie-Branch: main because the branch was captured once at session start.

This caused token usage to be attributed to main in analytics instead of the newly checked-out branch.

Changes

  • HeaderInjectionPlugin.onRequest(): re-detect current git branch via detectGitBranch(process.cwd()) on every LLM request instead of using the stale config.branch from session start
  • Falls back to config.branch (session-start value) if git detection fails (non-git dir, detached HEAD, timeout)

Impact

Before: all LLM calls after a branch checkout → branch=main in analytics
After: LLM calls reflect the actual current branch at the time of the request

Checklist

  • Self-reviewed
  • Manual testing performed

@AntonYeromin AntonYeromin changed the title fix(proxy): EPMCDME-11078 detect git branch per-request to fix stale branch header fix(proxy): Detect git branch per-request to fix stale branch header Mar 19, 2026
@AntonYeromin AntonYeromin changed the title fix(proxy): Detect git branch per-request to fix stale branch header fix(proxy): detect git branch per-request to fix stale branch header Mar 19, 2026
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