Repository navigation
fix(pricing): resolve Claude dot-separated model aliases - #1154
Conversation
Normalize pricing lookup keys so Claude model identifiers that use dot or provider separators, such as claude-opus-4.7, resolve to the same embedded pricing as their canonical hyphenated forms. This prevents Opus 4.7 usage from falling back to older Opus 4 pricing in calculate mode while keeping exact model entries authoritative and requiring boundaries for fuzzy matches. Also updates embedded context fallbacks for current Claude Opus 4.6, Opus 4.7, and Sonnet 4.6 models to match their 1M context windows. Validation: pnpm run format; env -u CFLAGS direnv exec . cargo test --manifest-path rust/Cargo.toml -p ccusage pricing::tests:: -- --nocapture; env -u CFLAGS direnv exec . pnpm run test; pnpm typecheck
|
@coderabbitai review |
|
Warning Review limit reached
Your plan includes 10 reviews of capacity. Refill in 4 minutes and 31 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughModel-name resolution in pricing/context lookups now uses normalized, boundary-aware fuzzy matching (treating ChangesModel Matching and Context Limits
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Actions performedReview triggered.
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | f27ae5e | Commit Preview URL Branch Preview URL |
May 25 2026, 07:21 PM |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rust/crates/ccusage/src/pricing.rs (1)
545-575: 💤 Low valueBoundary-aware fuzzy matching implementation is correct.
The helper functions implement the core matching logic properly:
contains_pricing_keyusesmatch_indicesand boundary checks to prevent false matches (e.g., "4.70" won't match "4-7")normalized_pricing_keyefficiently usesCowto avoid allocation when no normalization is neededpricing_key_matcheschecks both directions (stored key in query, query in stored key) after normalizationThe boundary definition (non-alphanumeric ASCII) correctly handles version separators while preventing partial version matches.
📝 Optional: Add doc comments for maintainability
Consider adding brief doc comments to explain the boundary-aware matching semantics, especially for
pricing_key_matcheswhich encapsulates the core fuzzy matching algorithm:/// Checks if a candidate pricing key matches a model string using boundary-aware fuzzy matching. /// Normalizes '.' and '@' separators to '-' and requires matches to align on non-alphanumeric boundaries. fn pricing_key_matches(candidate: &str, model: &str, normalized_model: &str) -> bool { // ... existing implementation }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/crates/ccusage/src/pricing.rs` around lines 545 - 575, Add concise doc comments explaining the boundary-aware fuzzy matching behavior for pricing keys: document pricing_key_matches (what it does, that it normalizes '.' and '@' to '-' and checks both directions), contains_pricing_key (that it uses match_indices and checks non-alphanumeric ASCII boundaries), is_pricing_key_boundary (defines boundary as non-alphanumeric ASCII), and normalized_pricing_key (returns Cow and replaces separators). Place the comments immediately above each corresponding function (pricing_key_matches, contains_pricing_key, is_pricing_key_boundary, normalized_pricing_key) and keep them short and focused for maintainability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rust/crates/ccusage/src/pricing.rs`:
- Around line 545-575: Add concise doc comments explaining the boundary-aware
fuzzy matching behavior for pricing keys: document pricing_key_matches (what it
does, that it normalizes '.' and '@' to '-' and checks both directions),
contains_pricing_key (that it uses match_indices and checks non-alphanumeric
ASCII boundaries), is_pricing_key_boundary (defines boundary as non-alphanumeric
ASCII), and normalized_pricing_key (returns Cow and replaces separators). Place
the comments immediately above each corresponding function (pricing_key_matches,
contains_pricing_key, is_pricing_key_boundary, normalized_pricing_key) and keep
them short and focused for maintainability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d75e59fd-74be-4d01-a1e1-70f1576be5ef
📒 Files selected for processing (1)
rust/crates/ccusage/src/pricing.rs
Apply cargo fmt to the Claude pricing alias tests and context fallback array so nix flake check passes the Rust formatting check. Validation: env -u CFLAGS direnv exec . cargo test --manifest-path rust/Cargo.toml -p ccusage pricing::tests:: -- --nocapture; env NIX_CONFIG="access-tokens = github.com=$(gh auth token)" nix flake check --print-build-logs
|
@coderabbitai review\n\nPushed 12ee23d to apply rustfmt after CI caught the Rust formatting check. Validation now includes the focused pricing tests and local nix flake check. |
|
✅ Actions performedReview triggered.
|
Add concise helper documentation for the boundary-aware pricing key matching requested by CodeRabbit. The comments explain the matching semantics for separator normalization and version boundaries without changing runtime behavior. Validation: direnv exec . cargo fmt --manifest-path rust/Cargo.toml --all; env -u CFLAGS direnv exec . cargo test --manifest-path rust/Cargo.toml -p ccusage pricing::tests:: -- --nocapture
|
@coderabbitai review\n\nPushed dbb66b6 to address your maintainability nit by documenting the boundary-aware pricing alias helpers. Validation: cargo fmt and focused pricing tests passed. |
|
✅ Actions performedReview triggered.
|
ccusage
@ccusage/ccusage-darwin-arm64
@ccusage/ccusage-darwin-x64
@ccusage/ccusage-linux-arm64
@ccusage/ccusage-linux-x64
@ccusage/ccusage-win32-arm64
@ccusage/ccusage-win32-x64
commit: |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
…x/fix-opus-47-usage # Conflicts: # rust/crates/ccusage/src/pricing.rs
|
@coderabbitai review Pushed f27ae5e to merge latest main and resolve the pricing.rs conflict. Kept the Claude alias/context fix and retained the new main-side Kimi context/pricing updates. Validation after conflict resolution: cargo fmt --check and focused pricing tests passed. |
|
✅ Actions performedReview triggered.
|
|
@coderabbitai review Re-triggering after the temporary review capacity limit. Latest head remains f27ae5e with the main merge conflict resolved. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
|
✅ Actions performedReview triggered.
|
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
Fixes #1125.
This updates pricing lookup so Claude model identifiers with dot or provider separators, such as claude-opus-4.7, resolve to the same embedded pricing as canonical hyphenated model IDs. It also keeps fuzzy matching boundary-aware so nearby versions like 4.70 do not accidentally match 4.7, and updates embedded context fallbacks for current Claude Opus 4.6, Opus 4.7, and Sonnet 4.6 models.
Testing:
Summary by cubic
Fix pricing lookup for Claude models with dots or provider prefixes so they resolve to canonical hyphenated keys. Prevents
claude-opus-4.7from falling back to older Opus 4 pricing and sets correct 1M context windows.Bug Fixes
.and@to-(e.g.,claude-opus-4.7andopenrouter/anthropic/claude-opus-4.7→claude-opus-4-7).4.70doesn’t match4.7.claude-opus-4-6,claude-opus-4-7, andclaude-sonnet-4-6.Refactors
Written for commit f27ae5e. Summary will update on new commits. Review in cubic
Summary by CodeRabbit