@devries-cameron20 / t3code-1 / commits / f34ba437a5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(usage): Claude usage no longer lists a `<synthetic>` model (#14672)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Tristan Knight committed Oct 19, 2026 at 18:54 UTC f34ba437a5dec23a205ef5f670f7b10439ae98eb
4 files changed +75 -11
apps/server/src/provider/Drivers/claudeUsage.test.ts
+30 -1
@@ -1,6 +1,6 @@
1 import { describe, expect, it } from "@effect/vitest";
2
3 -import { parseClaudeLine } from "./claudeUsage.ts";
3 +import { claudeUsageFormat, parseClaudeLine } from "./claudeUsage.ts";
4
5 function claudeLine(overrides: {
6 messageId: string;
@@ -66,6 +66,35 @@ describe("parseClaudeLine", () => {
66 expect(text?.totals).toEqual(toolUse?.totals);
67 });
68
69 + it("skips local placeholders in both reader paths but keeps real zero-token responses", () => {
70 + const projected = {
71 + type: "assistant",
72 + timestamp: "2026-08-07T04:05:13.944Z",
73 + message: {
74 + model: "claude-fable-5",
75 + usage: { input_tokens: 0, output_tokens: 0 },
76 + },
77 + };
78 + const expected = [
79 + expect.objectContaining({
80 + model: "claude-fable-5",
81 + totals: {
82 + uncachedInputTokens: 0,
83 + cachedInputTokens: 0,
84 + cacheCreationTokens: 0,
85 + outputTokens: 0,
86 + reasoningTokens: 0,
87 + },
88 + }),
89 + ];
90 + expect(claudeUsageFormat.parseLine(JSON.stringify(projected), undefined)).toEqual(expected);
91 + expect(claudeUsageFormat.parseProjected(projected, undefined)).toEqual(expected);
92 +
93 + const synthetic = { ...projected, message: { ...projected.message, model: "<synthetic>" } };
94 + expect(claudeUsageFormat.parseLine(JSON.stringify(synthetic), undefined)).toEqual([]);
95 + expect(claudeUsageFormat.parseProjected(synthetic, undefined)).toEqual([]);
96 + });
97 +
98 it("ignores records that are not assistant messages", () => {
99 expect(parseClaudeLine(JSON.stringify({ type: "user", message: {} }))).toBeNull();
100 expect(parseClaudeLine("not json")).toBeNull();
apps/server/src/provider/Drivers/claudeUsage.ts
+4 -1
@@ -12,6 +12,9 @@ import {
12 } from "@t3tools/provider-core/server/usage";
13 import * as HostProcess from "@t3tools/shared/HostProcess";
14
15 +// Claude Code uses this model for local placeholders that never reached the API.
16 +export const CLAUDE_SYNTHETIC_MODEL = "<synthetic>";
17 +
18 /**
19 * T3 Code writes one record per assistant *content block*, and every one of those records repeats
20 * the same complete `usage` object for the parent message. Summing them overcounts by roughly
@@ -45,7 +48,7 @@ function parseClaudeRecord(parsed: unknown): UsageRecord | null {
48 if (timestampMs === null) return null;
49
50 const model = typeof messageRecord["model"] === "string" ? messageRecord["model"] : "";
48 - if (model.length === 0) return null;
51 + if (model.length === 0 || model === CLAUDE_SYNTHETIC_MODEL) return null;
52
53 const messageId = typeof messageRecord["id"] === "string" ? messageRecord["id"] : null;
54 const requestId = typeof record["requestId"] === "string" ? record["requestId"] : null;
apps/server/src/usage/usageScanCache.test.ts
+36 -9
@@ -59,14 +59,30 @@ function cacheWith(entries: readonly [string, number, readonly UsageRecord[]][])
59 }
60
61 describe("scan cache round trip", () => {
62 - it("restores records unchanged", () => {
62 + it("restores cached history unchanged except for Claude local placeholders", () => {
63 const original = cacheWith([
64 [
65 "/a.jsonl",
66 100,
67 [record(), record({ dedupeKey: "msg_2:", model: "claude-opus-5-5", speed: "fast" })],
68 ],
69 - ["/b.jsonl", 200, [record({ sessionId: "session-b", reportedCostUsd: 1.5 })]],
69 + [
70 + "/b.jsonl",
71 + 200,
72 + [
73 + record({
74 + sessionId: "session-b",
75 + reportedCostUsd: 1.5,
76 + totals: {
77 + uncachedInputTokens: 0,
78 + cachedInputTokens: 0,
79 + cacheCreationTokens: 0,
80 + outputTokens: 0,
81 + reasoningTokens: 0,
82 + },
83 + }),
84 + ],
85 + ],
86 ]);
87 original.set("/grok.jsonl", {
88 size: 40,
@@ -74,8 +90,9 @@ describe("scan cache round trip", () => {
90 provider: "grok",
91 records: [
92 record({ provider: "grok", model: "grok-4.5-build", dedupeKey: "s:p:grok-4.5-build" }),
93 + record({ provider: "grok", model: "<synthetic>", dedupeKey: "s:p:<synthetic>" }),
94 ],
78 - tailRecords: [record({ provider: "grok", model: "grok-4.5-build", dedupeKey: null })],
95 + tailRecords: [record({ provider: "grok", model: "<synthetic>", dedupeKey: null })],
96 position: position({ resumeOffset: 30, guardLength: 30, guardHash: 123 }),
97 });
98 original.set("/codex.jsonl", {
@@ -99,16 +116,26 @@ describe("scan cache round trip", () => {
116 }),
117 });
118
119 + original.set("/a.jsonl", {
120 + ...original.get("/a.jsonl")!,
121 + tailRecords: [record({ dedupeKey: "msg_tail:" })],
122 + });
123 + const claude = original.get("/a.jsonl")!;
124 + const cached = new Map(original);
125 + cached.set("/a.jsonl", {
126 + ...claude,
127 + records: [...claude.records, record({ model: "<synthetic>" })],
128 + tailRecords: [
129 + ...claude.tailRecords,
130 + record({ model: "<synthetic>", dedupeKey: "msg_tail:" }),
131 + ],
132 + });
133 const restored = decodeScanCache(
103 - JSON.parse(JSON.stringify(encodeScanCache(original))),
134 + JSON.parse(JSON.stringify(encodeScanCache(cached))),
135 TEST_FORMAT_MAP,
136 );
137
107 - expect(restored.size).toBe(4);
108 - expect(restored.get("/a.jsonl")).toEqual(original.get("/a.jsonl"));
109 - expect(restored.get("/b.jsonl")).toEqual(original.get("/b.jsonl"));
110 - expect(restored.get("/grok.jsonl")).toEqual(original.get("/grok.jsonl"));
111 - expect(restored.get("/codex.jsonl")).toEqual(original.get("/codex.jsonl"));
138 + expect(restored).toEqual(original);
139 });
140
141 it("drops an entry whose persisted parse state is corrupt", () => {
apps/server/src/usage/usageScanCache.ts
+5
@@ -6,6 +6,7 @@ import type {
6 } from "@t3tools/provider-core/server/usage";
7 import * as Schema from "effect/Schema";
8
9 +import { CLAUDE_SYNTHETIC_MODEL } from "../provider/Drivers/claudeUsage.ts";
10 import { GUARD_LENGTH, type TranscriptParsePosition } from "./usageTranscriptReader.ts";
11
12 const USAGE_SCAN_CACHE_VERSION = 5 as const;
@@ -237,6 +238,10 @@ export function decodeScanCache(
238 return null;
239 }
240
241 + // Unchanged and deleted transcripts may only exist in the cache, so the
242 + // parser cannot remove their previously saved local placeholders.
243 + if (provider === "claude" && model === CLAUDE_SYNTHETIC_MODEL) continue;
244 +
245 records.push({
246 provider,
247 timestampMs,