Browse Source

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.
MFPires 11 months ago
parent
commit
f7cf08c607
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/core/Cline.ts

+ 4 - 0
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