MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getStoredSessionCosts

Function getStoredSessionCosts

src/cost-tracker.ts:87–123  ·  view source on GitHub ↗
(
  sessionId: string,
)

Source from the content-addressed store, hash-verified

85 * Use this to read costs BEFORE overwriting the config with saveCurrentSessionCosts().
86 */
87export function getStoredSessionCosts(
88 sessionId: string,
89): StoredCostState | undefined {
90 const projectConfig = getCurrentProjectConfig()
91
92 // Only return costs if this is the same session that was last saved
93 if (projectConfig.lastSessionId !== sessionId) {
94 return undefined
95 }
96
97 // Build model usage with context windows
98 let modelUsage: { [modelName: string]: ModelUsage } | undefined
99 if (projectConfig.lastModelUsage) {
100 modelUsage = Object.fromEntries(
101 Object.entries(projectConfig.lastModelUsage).map(([model, usage]) => [
102 model,
103 {
104 ...usage,
105 contextWindow: getContextWindowForModel(model, getSdkBetas()),
106 maxOutputTokens: getModelMaxOutputTokens(model).default,
107 },
108 ]),
109 )
110 }
111
112 return {
113 totalCostUSD: projectConfig.lastCost ?? 0,
114 totalAPIDuration: projectConfig.lastAPIDuration ?? 0,
115 totalAPIDurationWithoutRetries:
116 projectConfig.lastAPIDurationWithoutRetries ?? 0,
117 totalToolDuration: projectConfig.lastToolDuration ?? 0,
118 totalLinesAdded: projectConfig.lastLinesAdded ?? 0,
119 totalLinesRemoved: projectConfig.lastLinesRemoved ?? 0,
120 lastDuration: projectConfig.lastDuration,
121 modelUsage,
122 }
123}
124
125/**
126 * Restores cost state from project config when resuming a session.

Callers 2

REPLFunction · 0.85

Calls 5

getCurrentProjectConfigFunction · 0.85
getContextWindowForModelFunction · 0.85
getSdkBetasFunction · 0.85
getModelMaxOutputTokensFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected