Skip to content

Commit ca27db7

Browse files
fix(claude): trim resp_ dedupe comments
Co-authored-by: StartupBros <[email protected]>
1 parent 9a57e5f commit ca27db7

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

‎rust/adapters/claude/src/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ Sidechain entries:
3535
[#913](https://github.com/ccusage/ccusage/issues/913).
3636
- When `requestId` is missing, both loaders deduplicate by message ID, effective
3737
session ID, and timestamp. Repeated writes at the same timestamp still
38-
collapse; distinct timestamps stay separate, except that real response
39-
message IDs (`msg_` and `resp_` prefixes) collapse across timestamps because
40-
Claude Code writes one line per content block for a single response. Both keep
41-
gateway responses that reuse a message ID in different sessions separate.
38+
collapse; distinct timestamps stay separate, except that real Anthropic
39+
message IDs (`msg_` prefix) and OpenAI `resp_` IDs collapse across timestamps because Claude Code
40+
writes one line per content block for a single response. Both keep gateway
41+
responses that reuse a message ID in different sessions separate.
4242
- When `requestId` is present, both loaders deduplicate matching message and
4343
request IDs across sessions because Claude Code can copy one response into
4444
multiple session transcripts.

‎rust/adapters/claude/src/lib.rs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ fn push_deduped_entry(
344344
///
345345
/// Matching message and request IDs identify one response across sessions. Without a request
346346
/// ID, gateways can reuse one message ID for every response, so the key is scoped to the
347-
/// session and timestamp instead. Real response IDs (`msg_` and `resp_` prefixes) are unique
348-
/// per response, so requestless entries with one collapse by session across timestamps: Claude
349-
/// Code writes one line per content block with the same `message.id` but distinct timestamps.
347+
/// session and timestamp instead. Real Anthropic IDs (`msg_` prefix) are unique per response,
348+
/// so requestless entries with one collapse by session across timestamps: Claude Code writes
349+
/// one line per content block with the same `message.id` but distinct timestamps.
350350
fn usage_dedupe_hash(
351351
message_id: &str,
352352
request_id: Option<&str>,
@@ -365,14 +365,12 @@ fn usage_dedupe_hash(
365365
hasher.finish()
366366
}
367367

368-
/// Real response IDs are unique per response, unlike the placeholder IDs gateways
368+
/// Real Anthropic message IDs are unique per response, unlike the placeholder IDs gateways
369369
/// reuse for every response.
370370
///
371371
/// The prefix is a heuristic: only a request ID proves two lines belong to one response, so a
372-
/// gateway that reused a response-shaped placeholder would collapse to one entry per session.
373-
/// OpenAI's Responses API mints one `resp_` ID per response, the same way Anthropic mints one
374-
/// `msg_` ID per response, so both collapse across the content-block timestamps Claude Code
375-
/// writes for a single response.
372+
/// gateway that reused a `msg_`-shaped placeholder would collapse to one entry per session.
373+
/// OpenAI Responses API `resp_` IDs are treated the same way.
376374
pub(crate) fn is_anthropic_message_id(message_id: &str) -> bool {
377375
message_id.starts_with("msg_") || message_id.starts_with("resp_")
378376
}

‎rust/crates/ccusage/tests/claude_cli.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,6 @@ fn requestless_anthropic_message_id_content_blocks_are_counted_once_in_every_rep
717717
#[test]
718718
fn requestless_response_message_id_content_blocks_are_counted_once_in_every_report() {
719719
let fixture = Fixture::new();
720-
// A GPT model behind an Anthropic-compatible gateway passes its Responses API id through
721-
// as `message.id`; like the `msg_` case, one response is one line per content block.
722720
let lines = [
723721
requestless_line(
724722
"2026-09-11T12:00:00.000Z",

0 commit comments

Comments
 (0)