Skip to content

fix(opencode): add Claude model aliases for dot-notation version names#868

Open
sunmingyang666 wants to merge 1 commit intoryoppippi:mainfrom
sunmingyang666:fix/opencode-model-aliases
Open

fix(opencode): add Claude model aliases for dot-notation version names#868
sunmingyang666 wants to merge 1 commit intoryoppippi:mainfrom
sunmingyang666:fix/opencode-model-aliases

Conversation

@sunmingyang666
Copy link

@sunmingyang666 sunmingyang666 commented Feb 25, 2026

Summary

OpenCode uses dot notation for Claude model version numbers (e.g. claude-opus-4.6, claude-sonnet-4.5), but LiteLLM uses hyphens (e.g. claude-opus-4-6, claude-sonnet-4-5). This mismatch causes cost calculation to silently fall back to zero for all Claude models used through OpenCode.

Problem

When OpenCode records usage for Claude models, the modelID stored in the database uses dot notation:

  • claude-opus-4.6
  • claude-sonnet-4.5
  • claude-sonnet-4.6
  • claude-opus-4.5
  • claude-haiku-4.5

However, LiteLLM's pricing dataset uses hyphen notation (claude-opus-4-6, claude-sonnet-4-5, etc.). The LiteLLMPricingFetcher.getModelPricing() method cannot find a match, so costs are reported as $0.

Note: github_copilot/claude-opus-4.6 does exist in LiteLLM but with NaN pricing — this is a separate upstream issue. The providerID field in OpenCode is stored separately and is not used in the model name lookup, so createMatchingCandidates() never constructs the github_copilot/ prefixed name. Our aliases correctly map the bare model names.

Changes

Added 5 Claude model aliases to MODEL_ALIASES in apps/opencode/src/cost-utils.ts:

OpenCode name LiteLLM name Input ($/M) Output ($/M)
claude-haiku-4.5 claude-haiku-4-5 $0.80 $4.00
claude-opus-4.5 claude-opus-4-5 $5.00 $25.00
claude-opus-4.6 claude-opus-4-6 $5.00 $25.00
claude-sonnet-4.5 claude-sonnet-4-5 $3.00 $15.00
claude-sonnet-4.6 claude-sonnet-4-6 $3.00 $15.00

Verification

  • Build passes (pnpm --filter @ccusage/opencode run build)
  • All tests pass (pnpm --filter @ccusage/opencode run test — 6/6)
  • Lint passes (pnpm --filter @ccusage/opencode run lint)
  • Verified modelID in OpenCode's SQLite DB is stored as bare name without provider prefix
  • Confirmed all 5 aliased names exist in LiteLLM with valid (non-NaN) pricing

Summary by CodeRabbit

  • Bug Fixes
    • Added support for additional Claude model naming conventions in pricing lookups, enabling proper translation between variant naming formats for accurate cost calculations.

OpenCode uses dot notation for Claude version numbers (e.g. claude-opus-4.6), but LiteLLM uses hyphens (e.g. claude-opus-4-6). Without these aliases, cost calculation silently falls back to zero for all Claude models.
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Added seven alias mappings for Claude model variants using hyphenated naming conventions to enable pricing lookups. The mappings translate dot-notation names (4.5, 4.6) to hyphenated forms (4-5, 4-6) while maintaining existing alias entries.

Changes

Cohort / File(s) Summary
Model Alias Mappings
apps/opencode/src/cost-utils.ts
Added seven new alias entries for Claude model variants mapping dot-notation names to hyphenated equivalents (e.g., 4.5 → 4-5, 4.6 → 4-6) for pricing resolution lookups.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #854 — Extends alias mappings and adds fallback logic to use aliases when direct pricing lookups return zero values.
  • PR #689 — Broadens model-name matching and scoring logic to select provider/model variants for pricing lookups.

Suggested labels

bug

Suggested reviewers

  • ryoppippi

Poem

A rabbit hops through alias trees,
Adding names with dotted ease,
Four-point-five becomes hyphenated,
Claude's pricing—now translated! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly and specifically describes the main change: adding Claude model aliases for dot-notation version names to resolve pricing lookup failures.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant