@@ -31,6 +31,7 @@ class ClaudeOrchestrator {
3131 this.githubLinks = new Map(); // Track GitHub PR/branch links per session
3232 this.githubLinkLogs = new Map(); // Track last logged GitHub links per session
3333 this.sessionActivity = new Map(); // Track which sessions have been used
34+ this.branchRefreshRequestAt = new Map(); // sessionId -> last refresh timestamp (ms)
3435 this.dismissedStartupUI = new Map(); // Track which sessions have dismissed startup UI
3536 this.startupUIDebounce = new Map(); // Debounce startup UI showing
3637 this.sessionAgentPreferences = new Map(); // Track agent preferences per session
@@ -451,6 +452,9 @@ class ClaudeOrchestrator {
451452 this.detectGitHubLinks(sessionId, data);
452453 }
453454
455+ // Fast-path branch refresh when git reports a branch change in output.
456+ this.maybeRequestBranchRefreshFromOutput(sessionId, data);
457+
454458 // Detect clear commands to reset PR links and activity
455459 if (data.includes('/clear') || data.includes('clear')) {
456460 this.clearGitHubLinks(sessionId);
@@ -3490,6 +3494,38 @@ class ClaudeOrchestrator {
34903494 };
34913495 }
34923496
3497+ maybeRequestBranchRefreshFromOutput(sessionId, data) {
3498+ if (!this.socket) return;
3499+
3500+ const sid = String(sessionId || '').trim();
3501+ if (!sid) return;
3502+
3503+ const t = String(data || '');
3504+ if (!t) return;
3505+
3506+ // Cheap filter first.
3507+ if (!/(switched to|already on|on branch|head is now at|your branch is up to date)/i.test(t)) {
3508+ return;
3509+ }
3510+
3511+ // Only trigger when output is very likely a branch-changing/branch-reporting git message.
3512+ const looksLikeBranchEvent =
3513+ /Switched to (a new )?branch\b/i.test(t) ||
3514+ /\bAlready on\b/i.test(t) ||
3515+ /^\s*On branch\b/im.test(t) ||
3516+ /\bHEAD is now at\b/i.test(t) ||
3517+ /\bYour branch is up to date with\b/i.test(t);
3518+
3519+ if (!looksLikeBranchEvent) return;
3520+
3521+ const now = Date.now();
3522+ const last = this.branchRefreshRequestAt.get(sid) || 0;
3523+ if (now - last < 1500) return;
3524+ this.branchRefreshRequestAt.set(sid, now);
3525+
3526+ this.socket.emit('refresh-branch', { sessionId: sid });
3527+ }
3528+
34933529 updateTerminalBranchLabel(sessionId, branch) {
34943530 const terminalElement = document.querySelector(`#wrapper-${sessionId} .terminal-branch`);
34953531 if (!terminalElement) return;
0 commit comments