fix(claude): normalize anthropic model variants

Merged
IV
6mo ago
+129-0

Summary

  • Normalize Anthropic-prefixed Claude model identifiers into the same grouping keys as canonical Claude model names.
  • Add pricing aliases for Anthropic-prefixed Claude 4.5 and 4.6 variants so cost lookup resolves through existing canonical pricing.
  • Add focused tests for grouping and pricing behavior across prefixed and canonical Claude model names.

Why

Some Claude usage sources report models as anthropic/claude-... while existing grouping and pricing paths expect canonical Claude names. Without normalization, equivalent Claude usage can split into separate model rows or miss known pricing aliases. This change keeps attribution consistent without changing parser behavior or token accounting.

Diff scope

  • crates/tokscale-core/src/lib.rs
  • crates/tokscale-core/src/pricing/aliases.rs
  • crates/tokscale-core/src/pricing/lookup.rs
  • Normalizes Anthropic-prefixed Claude variants for grouping.
  • Adds pricing aliases for the supported prefixed Claude variant forms.
  • No CLI flags, TUI behavior, database schema, package metadata, or release files changed.

Branch integrity

  • Base branch: main
  • Validated base SHA: 270d64c4d268d5bcc380690441d6a891687d6794
  • Ahead/behind against origin/main: 0 behind / 1 ahead
  • Introduced commit: 5393e3d5037f41102936fa102cde0acade368be2 fix(claude): normalize anthropic model variants

Validation mode and proof

Mode 2 - narrow runtime change. The diff is isolated to model normalization and pricing alias lookup, with focused unit tests for the affected Claude paths.

Local validation on the final branch SHA:

  • cargo test -p tokscale-core test_normalize_model_for_grouping: PASS
  • cargo test -p tokscale-core anthropic_prefixed: PASS
  • cargo test -p tokscale-core claude: PASS
  • cargo test -p tokscale-core pricing::aliases: PASS
  • cargo fmt --all --check: PASS
  • rustup run stable cargo clippy -p tokscale-core --all-targets -- -D warnings: PASS
  • git diff --check origin/main...HEAD: PASS, no output
  • git diff --cached --check: PASS, no output

Ledger: not applicable - not required for this change family.
Version: not applicable - no package or release version changed.
Remote CI: Pending - not available until the pull request is opened.

Runtime safety

The change only maps recognized Anthropic-prefixed Claude model identifiers to existing canonical Claude names and aliases. It does not change token extraction, session parsing, aggregation math, persistence, or network behavior. Unknown model names still flow through existing fallback behavior. No invariant regression introduced.

Rollback plan

Rollback: revert this PR.
DB downgrade: not applicable.
Data repair: not applicable.
Operational caveats: reverting would restore split grouping or missing pricing for these Anthropic-prefixed Claude variant names.

Known residual risks

No known residual risks. Remote CI should validate the final PR SHA after the pull request is opened.


Summary by cubic

Normalize Anthropic-prefixed Claude model IDs to canonical names so usage groups correctly and pricing lookups use the right rates. Adds aliases for anthropic/claude 4.5/4.6 variants to reuse existing canonical pricing.

  • Bug Fixes
    • Map anthropic/claude-<major>-<minor>-{opus|sonnet|haiku} to claude-{family}-<major>-<minor> in tokscale-core grouping.
    • Add pricing aliases for anthropic/claude-4-5-* and anthropic/claude-4-6-* so cost lookup matches canonical entries.
    • Add focused tests covering grouping and pricing for prefixed and canonical names.