From 788b71f131e754cdca9e51e3f7a9e4bfc5bb760d Mon Sep 17 00:00:00 2001
From: Yax Patel <74978532+ypatel2022@users.noreply.github.com>
Date: Sat, 11 Apr 2026 15:30:41 -0400
Subject: [PATCH] feat: add active agent count in top bar (#484)
* feat: add active agent count in top bar
* fix: pass missing runtime pane title setters to pty connection
---------
Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
---
src/renderer/src/App.tsx | 24 ++++++
src/renderer/src/assets/main.css | 35 ++++++++
.../components/terminal-pane/TerminalPane.tsx | 6 ++
.../terminal-pane/pty-connection.ts | 4 +
.../use-terminal-pane-lifecycle.ts | 7 ++
.../src/lib/agent-status-count.test.ts | 83 +++++++++++++++++++
src/renderer/src/lib/agent-status.ts | 43 ++++++++++
src/renderer/src/store/slices/repos.ts | 3 +
src/renderer/src/store/slices/terminals.ts | 47 +++++++++++
src/renderer/src/store/slices/worktrees.ts | 3 +
10 files changed, 255 insertions(+)
create mode 100644 src/renderer/src/lib/agent-status-count.test.ts
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 8282b1b4a..a84885d9c 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -28,6 +28,7 @@ import {
import { useGlobalFileDrop } from './hooks/useGlobalFileDrop'
import { registerUpdaterBeforeUnloadBypass } from './lib/updater-beforeunload'
import { buildWorkspaceSessionPayload } from './lib/workspace-session'
+import { countWorkingAgents } from './lib/agent-status'
const isMac = navigator.userAgent.includes('Mac')
@@ -60,6 +61,12 @@ function App(): React.JSX.Element {
const activeRepoId = useAppStore((s) => s.activeRepoId)
const tabsByWorktree = useAppStore((s) => s.tabsByWorktree)
const activeTabId = useAppStore((s) => s.activeTabId)
+ const activeAgentCount = useAppStore((s) =>
+ countWorkingAgents({
+ tabsByWorktree: s.tabsByWorktree,
+ runtimePaneTitlesByTabId: s.runtimePaneTitlesByTabId
+ })
+ )
const expandedPaneByTabId = useAppStore((s) => s.expandedPaneByTabId)
const canExpandPaneByTabId = useAppStore((s) => s.canExpandPaneByTabId)
const terminalLayoutsByTabId = useAppStore((s) => s.terminalLayoutsByTabId)
@@ -491,6 +498,23 @@ function App(): React.JSX.Element {
Orca
+ {activeAgentCount > 0 ? (
+
+
+
+
+ {activeAgentCount}
+ active
+
+
+
+ {`${activeAgentCount} ${activeAgentCount === 1 ? 'agent' : 'agents'} active across all worktrees`}
+
+
+ ) : null}
{/* Why: keep the center titlebar slot mounted even when tabs are hidden.
Using `hidden` here collapsed the spacer entirely, which let the
diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css
index eb5660a59..3fa8b49d0 100644
--- a/src/renderer/src/assets/main.css
+++ b/src/renderer/src/assets/main.css
@@ -337,6 +337,41 @@
flex-shrink: 0;
}
+.titlebar-agent-badge {
+ -webkit-app-region: no-drag;
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ margin-left: 10px;
+ padding: 3px 8px;
+ border-radius: 999px;
+ border: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
+ background: color-mix(in srgb, var(--accent) 80%, transparent);
+ color: var(--foreground);
+ font-size: 11px;
+ font-weight: 600;
+ line-height: 1;
+ white-space: nowrap;
+}
+
+.titlebar-agent-badge-dot {
+ width: 7px;
+ height: 7px;
+ border-radius: 999px;
+ flex-shrink: 0;
+ background: #16a34a;
+ box-shadow: 0 0 0 3px color-mix(in srgb, #16a34a 18%, transparent);
+}
+
+.titlebar-agent-badge-count {
+ min-width: 1ch;
+}
+
+.titlebar-agent-badge-label {
+ color: var(--muted-foreground);
+ font-weight: 500;
+}
+
.titlebar-icon-button {
-webkit-app-region: no-drag;
background: none;
diff --git a/src/renderer/src/components/terminal-pane/TerminalPane.tsx b/src/renderer/src/components/terminal-pane/TerminalPane.tsx
index 44fda5f97..68e637e13 100644
--- a/src/renderer/src/components/terminal-pane/TerminalPane.tsx
+++ b/src/renderer/src/components/terminal-pane/TerminalPane.tsx
@@ -98,6 +98,8 @@ export default function TerminalPane({
const setTabLayout = useAppStore((store) => store.setTabLayout)
const initialLayoutRef = useRef(savedLayout)
const updateTabTitle = useAppStore((store) => store.updateTabTitle)
+ const setRuntimePaneTitle = useAppStore((store) => store.setRuntimePaneTitle)
+ const clearRuntimePaneTitle = useAppStore((store) => store.clearRuntimePaneTitle)
const updateTabPtyId = useAppStore((store) => store.updateTabPtyId)
const clearTabPtyId = useAppStore((store) => store.clearTabPtyId)
const markWorktreeUnread = useAppStore((store) => store.markWorktreeUnread)
@@ -268,6 +270,8 @@ export default function TerminalPane({
clearTabPtyId,
consumeSuppressedPtyExit: useAppStore((store) => store.consumeSuppressedPtyExit),
updateTabTitle,
+ setRuntimePaneTitle,
+ clearRuntimePaneTitle,
updateTabPtyId,
markWorktreeUnread,
dispatchNotification,
@@ -323,6 +327,8 @@ export default function TerminalPane({
clearTabPtyId,
consumeSuppressedPtyExit: useAppStore.getState().consumeSuppressedPtyExit,
updateTabTitle,
+ setRuntimePaneTitle,
+ clearRuntimePaneTitle,
updateTabPtyId,
markWorktreeUnread,
dispatchNotification,
diff --git a/src/renderer/src/components/terminal-pane/pty-connection.ts b/src/renderer/src/components/terminal-pane/pty-connection.ts
index 311c85508..985fdd7a7 100644
--- a/src/renderer/src/components/terminal-pane/pty-connection.ts
+++ b/src/renderer/src/components/terminal-pane/pty-connection.ts
@@ -20,6 +20,8 @@ type PtyConnectionDeps = {
clearTabPtyId: (tabId: string, ptyId: string) => void
consumeSuppressedPtyExit: (ptyId: string) => boolean
updateTabTitle: (tabId: string, title: string) => void
+ setRuntimePaneTitle: (tabId: string, paneId: number, title: string) => void
+ clearRuntimePaneTitle: (tabId: string, paneId: number) => void
updateTabPtyId: (tabId: string, ptyId: string) => void
markWorktreeUnread: (worktreeId: string) => void
dispatchNotification: (event: {
@@ -49,6 +51,7 @@ export function connectPanePty(
const cacheKey = `${deps.tabId}:${pane.id}`
const onExit = (ptyId: string): void => {
+ deps.clearRuntimePaneTitle(deps.tabId, pane.id)
deps.clearTabPtyId(deps.tabId, ptyId)
// Why: if the PTY exits abruptly (Ctrl-D, crash, shell termination) without
// first emitting a non-agent title, the cache timer would persist as stale
@@ -85,6 +88,7 @@ export function connectPanePty(
const onTitleChange = (title: string, rawTitle: string): void => {
manager.setPaneGpuRendering(pane.id, !isGeminiTerminalTitle(rawTitle))
+ deps.setRuntimePaneTitle(deps.tabId, pane.id, title)
deps.updateTabTitle(deps.tabId, title)
if (!hasConsideredInitialCacheTimerSeed) {
diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
index 9a29e6464..69a15697f 100644
--- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
+++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
@@ -50,6 +50,8 @@ type UseTerminalPaneLifecycleDeps = {
clearTabPtyId: (tabId: string, ptyId: string) => void
consumeSuppressedPtyExit: (ptyId: string) => boolean
updateTabTitle: (tabId: string, title: string) => void
+ setRuntimePaneTitle: (tabId: string, paneId: number, title: string) => void
+ clearRuntimePaneTitle: (tabId: string, paneId: number) => void
updateTabPtyId: (tabId: string, ptyId: string) => void
markWorktreeUnread: (worktreeId: string) => void
dispatchNotification: (event: {
@@ -92,6 +94,8 @@ export function useTerminalPaneLifecycle({
clearTabPtyId,
consumeSuppressedPtyExit,
updateTabTitle,
+ setRuntimePaneTitle,
+ clearRuntimePaneTitle,
updateTabPtyId,
markWorktreeUnread,
dispatchNotification,
@@ -189,6 +193,8 @@ export function useTerminalPaneLifecycle({
clearTabPtyId,
consumeSuppressedPtyExit,
updateTabTitle,
+ setRuntimePaneTitle,
+ clearRuntimePaneTitle,
updateTabPtyId,
markWorktreeUnread,
dispatchNotification,
@@ -252,6 +258,7 @@ export function useTerminalPaneLifecycle({
transport.destroy?.()
paneTransportsRef.current.delete(paneId)
}
+ clearRuntimePaneTitle(tabId, paneId)
paneFontSizesRef.current.delete(paneId)
pendingWritesRef.current.delete(paneId)
// Clean up pane title state so closed panes don't leave stale entries.
diff --git a/src/renderer/src/lib/agent-status-count.test.ts b/src/renderer/src/lib/agent-status-count.test.ts
new file mode 100644
index 000000000..7821de88c
--- /dev/null
+++ b/src/renderer/src/lib/agent-status-count.test.ts
@@ -0,0 +1,83 @@
+import { describe, expect, it } from 'vitest'
+import type { TerminalTab } from '../../../shared/types'
+import { countWorkingAgents } from './agent-status'
+
+function makeTab(overrides: Partial = {}): TerminalTab {
+ return {
+ id: 'tab-1',
+ ptyId: 'pty-1',
+ worktreeId: 'wt-1',
+ title: 'Terminal 1',
+ customTitle: null,
+ color: null,
+ sortOrder: 0,
+ createdAt: 0,
+ ...overrides
+ }
+}
+
+describe('countWorkingAgents', () => {
+ it('counts each live working tab when pane-level titles are unavailable', () => {
+ expect(
+ countWorkingAgents({
+ tabsByWorktree: {
+ 'wt-1': [
+ makeTab({ id: 'tab-1', title: '⠂ Claude Code' }),
+ makeTab({ id: 'tab-2', title: '✦ Gemini CLI' })
+ ],
+ 'wt-2': [makeTab({ id: 'tab-3', worktreeId: 'wt-2', title: '⠋ Codex is thinking' })]
+ },
+ runtimePaneTitlesByTabId: {}
+ })
+ ).toBe(3)
+ })
+
+ it('counts working panes separately within the same tab', () => {
+ expect(
+ countWorkingAgents({
+ tabsByWorktree: {
+ 'wt-1': [makeTab({ id: 'tab-1', title: '⠂ Claude Code' })]
+ },
+ runtimePaneTitlesByTabId: {
+ 'tab-1': {
+ 1: '⠂ Claude Code',
+ 2: '✦ Gemini CLI',
+ 3: '✳ Claude Code'
+ }
+ }
+ })
+ ).toBe(2)
+ })
+
+ it('ignores non-working or non-live tabs', () => {
+ expect(
+ countWorkingAgents({
+ tabsByWorktree: {
+ 'wt-1': [
+ makeTab({ id: 'tab-1', title: '✳ Claude Code' }),
+ makeTab({ id: 'tab-2', title: '✋ Gemini CLI' }),
+ makeTab({ id: 'tab-3', title: 'bash' }),
+ makeTab({ id: 'tab-4', title: '⠂ Claude Code', ptyId: null })
+ ]
+ },
+ runtimePaneTitlesByTabId: {}
+ })
+ ).toBe(0)
+ })
+
+ it('prefers pane-level titles over the coarse tab title when available', () => {
+ expect(
+ countWorkingAgents({
+ tabsByWorktree: {
+ 'wt-1': [makeTab({ id: 'tab-1', title: '⠂ Claude Code' })]
+ },
+ runtimePaneTitlesByTabId: {
+ 'tab-1': {
+ 1: '✳ Claude Code',
+ 2: 'bash'
+ }
+ }
+ })
+ ).toBe(0)
+ })
+})
diff --git a/src/renderer/src/lib/agent-status.ts b/src/renderer/src/lib/agent-status.ts
index bba75aca7..2ff9d2c7a 100644
--- a/src/renderer/src/lib/agent-status.ts
+++ b/src/renderer/src/lib/agent-status.ts
@@ -1,3 +1,5 @@
+import type { TerminalTab } from '../../../shared/types'
+
// Re-export from shared module so existing renderer imports continue to work.
// Why: the main process now needs the same agent detection logic for stat
// tracking. Moving to shared avoids duplicating the detection code.
@@ -10,3 +12,44 @@ export {
isGeminiTerminalTitle,
isClaudeAgent
} from '../../../shared/agent-detection'
+import { detectAgentStatusFromTitle } from '../../../shared/agent-detection'
+
+type CountWorkingAgentsArgs = {
+ tabsByWorktree: Record
+ runtimePaneTitlesByTabId: Record>
+}
+
+export function countWorkingAgents({
+ tabsByWorktree,
+ runtimePaneTitlesByTabId
+}: CountWorkingAgentsArgs): number {
+ let count = 0
+
+ for (const tabs of Object.values(tabsByWorktree)) {
+ for (const tab of tabs) {
+ const paneTitles = runtimePaneTitlesByTabId[tab.id]
+ // Why: split-pane tabs can host multiple concurrent agents, but the
+ // legacy tab title only reflects the last pane title update that won the
+ // tab label. Prefer pane-level titles whenever TerminalPane is mounted,
+ // and fall back to the tab title only for tabs we have not mounted yet
+ // (for example restored-but-unvisited worktrees).
+ if (paneTitles && Object.keys(paneTitles).length > 0) {
+ for (const title of Object.values(paneTitles)) {
+ if (detectAgentStatusFromTitle(title) === 'working') {
+ count += 1
+ }
+ }
+ continue
+ }
+ // Why: restored session tabs can keep the last agent title even before a
+ // PTY reconnects (or after the PTY is gone). Count only live PTY-backed
+ // tab fallbacks so the titlebar matches the sidebar's notion of
+ // "actively running" instead of surfacing stale pre-shutdown state.
+ if (tab.ptyId && detectAgentStatusFromTitle(tab.title) === 'working') {
+ count += 1
+ }
+ }
+ }
+
+ return count
+}
diff --git a/src/renderer/src/store/slices/repos.ts b/src/renderer/src/store/slices/repos.ts
index d8cdca272..d18e902e3 100644
--- a/src/renderer/src/store/slices/repos.ts
+++ b/src/renderer/src/store/slices/repos.ts
@@ -140,6 +140,7 @@ export const createRepoSlice: StateCreator = (set,
const nextTabs = { ...s.tabsByWorktree }
const nextLayouts = { ...s.terminalLayoutsByTabId }
const nextPtyIdsByTabId = { ...s.ptyIdsByTabId }
+ const nextRuntimePaneTitlesByTabId = { ...s.runtimePaneTitlesByTabId }
const nextSuppressedPtyExitIds = { ...s.suppressedPtyExitIds }
for (const wId of worktreeIds) {
delete nextTabs[wId]
@@ -147,6 +148,7 @@ export const createRepoSlice: StateCreator = (set,
for (const tabId of killedTabIds) {
delete nextLayouts[tabId]
delete nextPtyIdsByTabId[tabId]
+ delete nextRuntimePaneTitlesByTabId[tabId]
}
for (const ptyId of killedPtyIds) {
nextSuppressedPtyExitIds[ptyId] = true
@@ -174,6 +176,7 @@ export const createRepoSlice: StateCreator = (set,
worktreesByRepo: nextWorktrees,
tabsByWorktree: nextTabs,
ptyIdsByTabId: nextPtyIdsByTabId,
+ runtimePaneTitlesByTabId: nextRuntimePaneTitlesByTabId,
suppressedPtyExitIds: nextSuppressedPtyExitIds,
terminalLayoutsByTabId: nextLayouts,
activeTabId: s.activeTabId && killedTabIds.has(s.activeTabId) ? null : s.activeTabId,
diff --git a/src/renderer/src/store/slices/terminals.ts b/src/renderer/src/store/slices/terminals.ts
index f01e4a204..3531223f1 100644
--- a/src/renderer/src/store/slices/terminals.ts
+++ b/src/renderer/src/store/slices/terminals.ts
@@ -21,6 +21,9 @@ export type TerminalSlice = {
* the user returns to the same tab they left, not always tabs[0]. */
activeTabIdByWorktree: Record
ptyIdsByTabId: Record
+ /** Live pane titles keyed by tabId then paneId. Unlike the legacy tab title,
+ * this preserves split-pane agent status per pane while TerminalPane is mounted. */
+ runtimePaneTitlesByTabId: Record>
suppressedPtyExitIds: Record
pendingCodexPaneRestartIds: Record
codexRestartNoticeByPtyId: Record<
@@ -49,6 +52,8 @@ export type TerminalSlice = {
setTabBarOrder: (worktreeId: string, order: string[]) => void
setActiveTab: (tabId: string) => void
updateTabTitle: (tabId: string, title: string) => void
+ setRuntimePaneTitle: (tabId: string, paneId: number, title: string) => void
+ clearRuntimePaneTitle: (tabId: string, paneId: number) => void
setTabCustomTitle: (tabId: string, title: string | null) => void
setTabColor: (tabId: string, color: string | null) => void
updateTabPtyId: (tabId: string, ptyId: string) => void
@@ -101,6 +106,7 @@ export const createTerminalSlice: StateCreator
activeTabId: null,
activeTabIdByWorktree: {},
ptyIdsByTabId: {},
+ runtimePaneTitlesByTabId: {},
suppressedPtyExitIds: {},
pendingCodexPaneRestartIds: {},
codexRestartNoticeByPtyId: {},
@@ -216,6 +222,8 @@ export const createTerminalSlice: StateCreator
delete nextLayouts[tabId]
const nextPtyIdsByTabId = { ...s.ptyIdsByTabId }
delete nextPtyIdsByTabId[tabId]
+ const nextRuntimePaneTitlesByTabId = { ...s.runtimePaneTitlesByTabId }
+ delete nextRuntimePaneTitlesByTabId[tabId]
const nextPendingStartupByTabId = { ...s.pendingStartupByTabId }
delete nextPendingStartupByTabId[tabId]
const nextPendingSetupSplitByTabId = { ...s.pendingSetupSplitByTabId }
@@ -245,6 +253,7 @@ export const createTerminalSlice: StateCreator
activeTabId: s.activeTabId === tabId ? null : s.activeTabId,
activeTabIdByWorktree: nextActiveTabIdByWorktree,
ptyIdsByTabId: nextPtyIdsByTabId,
+ runtimePaneTitlesByTabId: nextRuntimePaneTitlesByTabId,
expandedPaneByTabId: nextExpanded,
canExpandPaneByTabId: nextCanExpand,
terminalLayoutsByTabId: nextLayouts,
@@ -346,6 +355,41 @@ export const createTerminalSlice: StateCreator
})
},
+ setRuntimePaneTitle: (tabId, paneId, title) => {
+ set((s) => {
+ const currentByPane = s.runtimePaneTitlesByTabId[tabId] ?? {}
+ if (currentByPane[paneId] === title) {
+ return s
+ }
+ return {
+ runtimePaneTitlesByTabId: {
+ ...s.runtimePaneTitlesByTabId,
+ [tabId]: { ...currentByPane, [paneId]: title }
+ }
+ }
+ })
+ },
+
+ clearRuntimePaneTitle: (tabId, paneId) => {
+ set((s) => {
+ const currentByPane = s.runtimePaneTitlesByTabId[tabId]
+ if (!currentByPane || !(paneId in currentByPane)) {
+ return s
+ }
+ const nextByPane = { ...currentByPane }
+ delete nextByPane[paneId]
+
+ const next = { ...s.runtimePaneTitlesByTabId }
+ if (Object.keys(nextByPane).length > 0) {
+ next[tabId] = nextByPane
+ } else {
+ delete next[tabId]
+ }
+
+ return { runtimePaneTitlesByTabId: next }
+ })
+ },
+
setTabCustomTitle: (tabId, title) => {
set((s) => {
const next = { ...s.tabsByWorktree }
@@ -467,6 +511,7 @@ export const createTerminalSlice: StateCreator
...s.ptyIdsByTabId,
...Object.fromEntries(tabs.map((tab) => [tab.id, [] as string[]] as const))
}
+ const nextRuntimePaneTitlesByTabId = { ...s.runtimePaneTitlesByTabId }
const nextSuppressedPtyExitIds = {
...s.suppressedPtyExitIds,
...Object.fromEntries(ptyIds.map((ptyId) => [ptyId, true] as const))
@@ -483,6 +528,7 @@ export const createTerminalSlice: StateCreator
const nextPendingSetupSplitByTabId = { ...s.pendingSetupSplitByTabId }
const nextPendingIssueCommandSplitByTabId = { ...s.pendingIssueCommandSplitByTabId }
for (const tab of tabs) {
+ delete nextRuntimePaneTitlesByTabId[tab.id]
delete nextPendingSetupSplitByTabId[tab.id]
delete nextPendingIssueCommandSplitByTabId[tab.id]
}
@@ -508,6 +554,7 @@ export const createTerminalSlice: StateCreator
return {
tabsByWorktree: nextTabsByWorktree,
ptyIdsByTabId: nextPtyIdsByTabId,
+ runtimePaneTitlesByTabId: nextRuntimePaneTitlesByTabId,
suppressedPtyExitIds: nextSuppressedPtyExitIds,
pendingCodexPaneRestartIds: nextPendingCodexPaneRestartIds,
codexRestartNoticeByPtyId: nextCodexRestartNoticeByPtyId,
diff --git a/src/renderer/src/store/slices/worktrees.ts b/src/renderer/src/store/slices/worktrees.ts
index 2407252f4..a53dfb9f2 100644
--- a/src/renderer/src/store/slices/worktrees.ts
+++ b/src/renderer/src/store/slices/worktrees.ts
@@ -116,9 +116,11 @@ export const createWorktreeSlice: StateCreator
delete nextTabs[worktreeId]
const nextLayouts = { ...s.terminalLayoutsByTabId }
const nextPtyIdsByTabId = { ...s.ptyIdsByTabId }
+ const nextRuntimePaneTitlesByTabId = { ...s.runtimePaneTitlesByTabId }
for (const tabId of tabIds) {
delete nextLayouts[tabId]
delete nextPtyIdsByTabId[tabId]
+ delete nextRuntimePaneTitlesByTabId[tabId]
}
const nextDeleteState = { ...s.deleteStateByWorktreeId }
delete nextDeleteState[worktreeId]
@@ -141,6 +143,7 @@ export const createWorktreeSlice: StateCreator
worktreesByRepo: next,
tabsByWorktree: nextTabs,
ptyIdsByTabId: nextPtyIdsByTabId,
+ runtimePaneTitlesByTabId: nextRuntimePaneTitlesByTabId,
terminalLayoutsByTabId: nextLayouts,
deleteStateByWorktreeId: nextDeleteState,
fileSearchStateByWorktree: (() => {