mirror of
https://github.com/tiennm99/ccstatusline.git
synced 2026-10-14 02:15:32 +00:00
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: "<synthetic>" - 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.
This commit is contained in:
1 parent
bb73dd63c0
commit
055bf22308
2 files changed
+3
-1
No files matched your search
@@ -9,6 +9,7 @@ export interface TranscriptLine {
|
||||
message?: { usage?: TokenUsage };
|
||||
isSidechain?: boolean;
|
||||
timestamp?: string;
|
||||
isApiErrorMessage?: boolean;
|
||||
}
|
||||
|
||||
export interface TokenMetrics {
|
||||
|
||||
+2
-1
@@ -114,7 +114,8 @@ export async function getTokenMetrics(transcriptPath: string): Promise<TokenMetr
|
||||
cachedTokens += data.message.usage.cache_creation_input_tokens ?? 0;
|
||||
|
||||
// Track the most recent entry with isSidechain: false (or undefined, which defaults to main chain)
|
||||
if (data.isSidechain !== true && data.timestamp) {
|
||||
// Also skip API error messages (synthetic messages with 0 tokens)
|
||||
if (data.isSidechain !== true && data.timestamp && !data.isApiErrorMessage) {
|
||||
const entryTime = new Date(data.timestamp);
|
||||
if (!mostRecentTimestamp || entryTime > mostRecentTimestamp) {
|
||||
mostRecentTimestamp = entryTime;
|
||||
|
||||
Reference in new issue
Block a user