From f7cf08c6075d47fadf385195a44c0a797fb85306 Mon Sep 17 00:00:00 2001 From: MFPires Date: Tue, 28 Jan 2025 15:49:36 -0300 Subject: [PATCH] feat: Add context tokens to environment details Adds the current conversation's context token count to the environment details section by: - Using existing getApiMetrics() to retrieve contextTokens from the last API request - Adding a new "Context Tokens" section between "Current Time" and "Current Mode" - Formatting the token count with toLocaleString() for better readability - Showing "(Not available)" when no context tokens are present This provides visibility into the current conversation's token usage directly in the environment details, helping track context window utilization. --- src/core/Cline.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 86a4ec5..f85bf18 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -3041,6 +3041,10 @@ export class Cline { const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : ""}${timeZoneOffset}:00` details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})` + // Add context tokens information + const { contextTokens } = getApiMetrics(this.clineMessages) + details += `\n\n# Current Context Size (Tokens)\n${contextTokens ? contextTokens.toLocaleString() : "(Not available)"}` + // Add current mode and any mode-specific warnings const { mode, customModes } = (await this.providerRef.deref()?.getState()) ?? {} const currentMode = mode ?? defaultModeSlug