{"record":{"id":"c6371357b0ccc88d","repo":"thedotmack/claude-mem","slug":"high-token-usage-detected-consider-reducing-cont","errorCode":null,"errorMessage":"High token usage detected - consider reducing context","messagePattern":"High token usage detected - consider reducing context","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/services/worker/OpenRouterProvider.ts","lineNumber":644,"sourceCode":"      ? data.usage.cost_details.upstream_inference_cost\n      : undefined;\n    const costUsd = orCost !== undefined || upstreamCost !== undefined\n      ? (orCost ?? 0) + (upstreamCost ?? 0)\n      : undefined;\n    const servedModel = typeof data.model === 'string' && data.model ? data.model : undefined;\n\n    if (tokensUsed) {\n      logger.info('SDK', 'OpenRouter API usage', {\n        model: servedModel ?? model,\n        inputTokens: realInputTokens || 0,\n        outputTokens: realOutputTokens || 0,\n        totalTokens: tokensUsed,\n        ...(costUsd !== undefined ? { costUSD: costUsd.toFixed(6) } : {}),\n        messagesInContext: history.length\n      });\n\n      if (tokensUsed > 50000) {\n        logger.warn('SDK', 'High token usage detected - consider reducing context', {\n          totalTokens: tokensUsed,\n          ...(costUsd !== undefined ? { costUSD: costUsd.toFixed(6) } : {}),\n        });\n      }\n    }\n\n    return { content, tokensUsed, inputTokens: realInputTokens, outputTokens: realOutputTokens, costUsd, servedModel };\n  }\n\n}\n\nexport function isOpenRouterAvailable(settingsPath: string = USER_SETTINGS_PATH): boolean {\n  return Boolean(resolveOpenRouterConfig(settingsPath).apiKey);\n}\n\nexport function isOpenRouterSelected(): boolean {\n  const settingsPath = USER_SETTINGS_PATH;\n  const settings = SettingsDefaultsManager.loadFromFile(settingsPath);","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker/OpenRouterProvider.ts#L626-L662","documentation":"A heuristic warning logged by queryOpenRouterMultiTurn when total tokens used in a multi-turn OpenRouter query exceed 50,000. It is not an error; it flags that the conversation history is large and costs/latency grow, suggesting context reduction.","triggerScenarios":"After a multi-turn query completes, tokensUsed > 50000 when the usage is logged; history.length (messagesInContext) is large.","commonSituations":"Long-running agent sessions that never trim history; pasting large files into the prompt; models with small context windows causing truncation or cost spikes on OpenRouter.","solutions":["Trim or summarize conversation history before it exceeds the threshold.","Lower the max history length / enable context windowing in the session manager.","Move large content out of the prompt (reference files instead of inlining).","Monitor costUSD in the same log to decide if the usage is intentional."],"exampleFix":"// before\nmessages: [...fullHistory, prompt]\n// after\nmessages: [...fullHistory.slice(-MAX_TURNS), prompt]","handlingStrategy":"validation","validationCode":"const estimate = history.reduce((n, m) => n + (m.content?.length ?? 0), 0) / 4;\nif (estimate > 45000) history = summarize(history);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap retained history length per session","Summarize or compact context before hitting ~50k tokens","Track costUSD per turn to catch runaway sessions"],"tags":["token-usage","context-size","cost"],"backgroundTag":"value-out-of-range","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}