From 055bf22308caa371d11ed0171a65566734f662a7 Mon Sep 17 00:00:00 2001 From: Alexander Buyanov Date: Sun, 5 Oct 2025 00:16:15 +0200 Subject: [PATCH] Fix #97: context widgets showing 0% due to synthetic API error messages (#98) Investigation revealed that Claude Code now appends synthetic error messages to transcript files when API errors occur (rate limits, authentication failures, etc.). These synthetic messages have: - model: "" - isApiErrorMessage: true - All token usage fields set to 0 The getTokenMetrics() function in src/utils/jsonl.ts calculates the current context length by finding the most recent main chain entry(isSidechain !== true) sorted by timestamp. When an API error occurs, the synthetic error message becomes the "most recent entry", causing contextLength to be calculated as 0. --- src/types/TokenMetrics.ts | 1 + src/utils/jsonl.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types/TokenMetrics.ts b/src/types/TokenMetrics.ts index b1cb8f8..ec3c866 100644 --- a/src/types/TokenMetrics.ts +++ b/src/types/TokenMetrics.ts @@ -9,6 +9,7 @@ export interface TranscriptLine { message?: { usage?: TokenUsage }; isSidechain?: boolean; timestamp?: string; + isApiErrorMessage?: boolean; } export interface TokenMetrics { diff --git a/src/utils/jsonl.ts b/src/utils/jsonl.ts index 617f313..6a1ec4e 100644 --- a/src/utils/jsonl.ts +++ b/src/utils/jsonl.ts @@ -114,7 +114,8 @@ export async function getTokenMetrics(transcriptPath: string): Promise mostRecentTimestamp) { mostRecentTimestamp = entryTime;