From 56dc8608621c8bbd4dc38888b1d27fd17762e341 Mon Sep 17 00:00:00 2001 From: Paul Holstein <44263169+holstein13@users.noreply.github.com> Date: Mon, 23 Feb 2026 14:15:25 -0500 Subject: [PATCH] feat: show total session cost including subagents in Visible Context panel Compute subagentCostUsd from sessionDetail.processes[].metrics and display total cost (parent + subagents) with breakdown in the header. When subagents exist, shows e.g. "$24.70 ($16.85 parent + $7.84 subagents)" with a link to the Session Report for full details. Replaces the "(parent only)" disclaimer since cost is now accurate. Co-Authored-By: Claude Opus 4.6 --- src/renderer/components/chat/ChatHistory.tsx | 9 ++++ .../components/SessionContextHeader.tsx | 42 +++++++++++-------- .../chat/SessionContextPanel/index.tsx | 2 + .../chat/SessionContextPanel/types.ts | 2 + 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/renderer/components/chat/ChatHistory.tsx b/src/renderer/components/chat/ChatHistory.tsx index 45929946..57ffdf99 100644 --- a/src/renderer/components/chat/ChatHistory.tsx +++ b/src/renderer/components/chat/ChatHistory.tsx @@ -102,6 +102,14 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => { sessionDetail, } = tabData; + // Compute combined subagent cost from process metrics + const subagentCostUsd = useMemo(() => { + const processes = sessionDetail?.processes; + if (!processes || processes.length === 0) return undefined; + const total = processes.reduce((sum, p) => sum + (p.metrics.costUsd ?? 0), 0); + return total > 0 ? total : undefined; + }, [sessionDetail?.processes]); + // State for Context button hover (local state OK - doesn't need per-tab isolation) const [isContextButtonHovered, setIsContextButtonHovered] = useState(false); @@ -874,6 +882,7 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => { onNavigateToUserGroup={handleNavigateToUserGroup} totalSessionTokens={lastAiGroupTotalTokens} sessionMetrics={sessionDetail?.metrics} + subagentCostUsd={subagentCostUsd} onViewReport={effectiveTabId ? () => openSessionReport(effectiveTabId) : undefined} phaseInfo={sessionPhaseInfo ?? undefined} selectedPhase={selectedContextPhase} diff --git a/src/renderer/components/chat/SessionContextPanel/components/SessionContextHeader.tsx b/src/renderer/components/chat/SessionContextPanel/components/SessionContextHeader.tsx index 0c5cd0dd..0879452a 100644 --- a/src/renderer/components/chat/SessionContextPanel/components/SessionContextHeader.tsx +++ b/src/renderer/components/chat/SessionContextPanel/components/SessionContextHeader.tsx @@ -28,6 +28,7 @@ interface SessionContextHeaderProps { totalTokens: number; totalSessionTokens?: number; sessionMetrics?: SessionMetrics; + subagentCostUsd?: number; onClose?: () => void; onViewReport?: () => void; phaseInfo?: ContextPhaseInfo; @@ -42,6 +43,7 @@ export const SessionContextHeader = ({ totalTokens, totalSessionTokens, sessionMetrics, + subagentCostUsd, onClose, onViewReport, phaseInfo, @@ -132,24 +134,30 @@ export const SessionContextHeader = ({
Session Cost: - {formatCostUsd(sessionMetrics.costUsd)} - - - {' (parent only'} - {onViewReport && ( - <> - {' · '} - - - )} - {')'} + {formatCostUsd(sessionMetrics.costUsd + (subagentCostUsd ?? 0))} + {subagentCostUsd !== undefined && subagentCostUsd > 0 && ( + + {' ('} + {formatCostUsd(sessionMetrics.costUsd)} + {' parent + '} + {formatCostUsd(subagentCostUsd)} + {' subagents'} + {onViewReport && ( + <> + {' · '} + + + )} + {')'} + + )}
)} diff --git a/src/renderer/components/chat/SessionContextPanel/index.tsx b/src/renderer/components/chat/SessionContextPanel/index.tsx index 68a200db..83b7ac8f 100644 --- a/src/renderer/components/chat/SessionContextPanel/index.tsx +++ b/src/renderer/components/chat/SessionContextPanel/index.tsx @@ -49,6 +49,7 @@ export const SessionContextPanel = ({ onNavigateToUserGroup, totalSessionTokens, sessionMetrics, + subagentCostUsd, onViewReport, phaseInfo, selectedPhase, @@ -193,6 +194,7 @@ export const SessionContextPanel = ({ totalTokens={totalTokens} totalSessionTokens={totalSessionTokens} sessionMetrics={sessionMetrics} + subagentCostUsd={subagentCostUsd} onClose={onClose} onViewReport={onViewReport} phaseInfo={phaseInfo} diff --git a/src/renderer/components/chat/SessionContextPanel/types.ts b/src/renderer/components/chat/SessionContextPanel/types.ts index df4b7f88..767dae12 100644 --- a/src/renderer/components/chat/SessionContextPanel/types.ts +++ b/src/renderer/components/chat/SessionContextPanel/types.ts @@ -27,6 +27,8 @@ export interface SessionContextPanelProps { totalSessionTokens?: number; /** Full session metrics (input, output, cache tokens, cost) */ sessionMetrics?: SessionMetrics; + /** Combined cost of all subagent processes */ + subagentCostUsd?: number; /** Open the Session Report to see full cost breakdown */ onViewReport?: () => void; /** Phase information for phase selector */