Skip to content

fix(claude): normalize anthropic model variants - #578

Merged
junhoyeo merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/claude-model-normalization
May 24, 2026
Merged

junhoyeo merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/claude-model-normalization

Conversation

@IvGolovach

@IvGolovach IvGolovach commented May 21, 2026

Copy link
Copy Markdown
Collaborator

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.

Written for commit 5393e3d. Summary will update on new commits. Review in cubic

Validation

* Validation tier: Tier 2 — narrow runtime change, model canonicalization and pricing alias resolution with focused core tests.

* 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: PASS

* git diff --cached --check: PASS

* Ledger: not applicable — not required for selected validation tier/change family.

* Version: not applicable — not required for selected validation tier/change family.

* Not run: full workspace test suite — not required for selected validation tier; touched behavior is covered by core grouping/pricing/Claude tests.

Rollback

* git revert HEAD
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview May 21, 2026 4:20am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@junhoyeo junhoyeo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@junhoyeo
junhoyeo merged commit 55852d8 into junhoyeo:main May 24, 2026
15 checks passed
@junhoyeo

Copy link
Copy Markdown
Owner

@IvGolovach this has been merged to v3.0.0: https://github.com/junhoyeo/tokscale/releases/tag/v3.0.0 thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants