Skip to content

fix(session-flow): retro parser double-counts tokens and over-counts human messages #5818

Closed

Description

@kyle-sexton

Summary

plugins/session-flow/skills/retro/scripts/parse_transcript.py over-counts tokens and human messages.

Tokens. Lines 246-252 sum message.usage for every assistant record. Claude Code writes each streamed assistant message as several records that share one message.id. On this machine's transcripts (Claude Code 2.1.275-2.1.287), 130,996 assistant records held 62,939 unique message ids, so token totals come out about 2x.

Human messages. Lines 260-267 count every string-content user record as a human message. That includes isMeta records, messages from other sessions ("Another Claude session sent..."), <task-notification> records, command output and bash-mode input. In the sample, injected records outnumbered typed human turns about 5:1.

Fix

  • Count usage once per message.id.
  • Count a user record as human only when origin.kind / promptSource marks it typed or queued, plus a prefix denylist for injected text that still carries those markers.

Consumers that inherit the error: /session-flow:retro, the running-retro subagent, and plugin-quality session mode (data.plugin_usage).

Verification

Acceptance: a fixture with duplicated message.id records and injected user records. Token and human-message counts must match the unique, typed values, and the existing contract tests must still pass.

Related

  • plugins/plugin-quality/skills/audit/reference/session-mode.md reads data.plugin_usage from this parser.

No related issue: new defect found while reading transcripts.

🤖 Generated with Claude Code

Activity

  1. added
    needs-triage
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions