t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Preserve Opus fallback on older Claude Code

Open mihneaptu opened this issue 4 months ago • 4 comments

What Changed

The bare opus alias now resolves to the newest Opus model the installed Claude Code actually supports, instead of falling through to the provider default when Opus 5 is absent from the catalog.

Two files in packages/shared. No SDK bump, no change to the version gate.

Why

#4472 repointed opus to claude-opus-5. That slug is gated behind MINIMUM_CLAUDE_OPUS_5_VERSION = "2.1.219" in getBuiltInClaudeModelsForVersion(), so on older clients it never reaches the served catalog. resolveSelectableModel() returns null, and selection falls through to getDefaultServerModel() — which takes the first non-custom model surviving version filtering, claude-fable-5 from 2.1.169 up.

In practice: on Claude Code 2.1.169–2.1.218, picking opus gives you Claude Fable 5 while Opus 4.8 is sitting available in the same catalog.

Claude Code before after
>= 2.1.219 Opus 5 Opus 5 — direct match, fallback never runs
2.1.169 – 2.1.218 Fable 5 Opus 4.8
2.1.154 – 2.1.168 Opus 4.8 unchanged
< 2.1.154 / unknown Opus 4.7 / 4.6 unchanged

Only the second row moves. Below 2.1.169 the default already lands on the newest available Opus, so the fallback is a no-op there.

Falling through to the newest supported model is the right behaviour when nothing was asked for. opus is a family request though, so it now resolves inside the Opus family first. The default policy itself is untouched.

The fallback walks a fixed list of built-in slugs, so modelOrder cannot shift which Opus is picked and claude-opus-custom is never selected. It reads the visible option list, so a model hidden via hiddenModels stays unselected. Explicit opus-5 still resolves to nothing when Opus 5 is absent, rather than quietly downgrading to a different model.

Resolves the open finding on #4472: https://github.com/pingdotgg/t3code/pull/4472#discussion_r3647506358

apps/web/src/modelSelection.test.ts pins this end to end: with claude-fable-5 present and claude-opus-5 filtered out, resolveAppModelSelection returns claude-opus-4-8. Reverting packages/shared/src/model.ts to 41a430a8 fails that case with claude-fable-5.

Tests: vp test run packages/shared/src/model.test.ts apps/web/src/modelSelection.test.ts — 17 passed. Typecheck on @t3tools/shared and @t3tools/web, targeted lint and format, and git diff --check — all clean. Claude adapter suite — 62 passed.

Verified live on Claude Code 2.1.219 (Windows): claude -p --model claude-opus-5 responds across all five efforts, claude-opus-5[1m] is accepted, and the bare opus alias resolves.

Checklist

  • [x] This PR is small and focused
  • [x] I explained what changed and why
  • [ ] I included before/after screenshots for any UI changes — n/a, no UI changes
  • [ ] I included a video for animation/interaction changes — n/a

[!NOTE]

Preserve Opus model fallback in resolveSelectableModel for older Claude Code

When the provider is claudeAgent and the requested value is 'opus', resolveSelectableModel now iterates a fixed priority list (CLAUDE_OPUS_FALLBACK_MODELS) and returns the newest available Claude Opus model slug instead of returning null. This ensures older Claude Code clients that send the bare 'opus' alias still resolve to a valid model when the normalized target slug is not present in the available options.

Macroscope summarized 29a898e.


[!NOTE] Low Risk Scoped to Claude opus alias resolution when the normalized slug is missing; no auth, persistence, or version-gate changes.

Overview Fixes a regression where the bare opus alias could resolve to an unrelated default (e.g. Fable 5) when Opus 5 is missing from the live catalog on Claude Code 2.1.169–2.1.218.

resolveSelectableModel in @t3tools/shared now, for claudeAgent and input opus, walks a fixed CLAUDE_OPUS_FALLBACK_MODELS priority list and picks the first slug present in the caller’s option list. Direct normalization still wins when Opus 5 is available; explicit opus-5 still returns nothing if that slug isn’t offered. Custom Opus slugs are not used as fallbacks.

Tests cover shared resolution behavior and resolveAppModelSelection end-to-end when the served catalog omits Opus 5.

Reviewed by Cursor Bugbot for commit de4da06b92b3165cbcc6a748fb8de07fd9715541. Bugbot is set up for automated code reviews on this repo. Configure here.

mihneaptu avatar Jul 24 '26 21:07 mihneaptu

[!IMPORTANT]

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f2d186e-69db-4a50-b559-c72d6c9059e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • [ ] 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

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.

coderabbitai[bot] avatar Jul 24 '26 21:07 coderabbitai[bot]

This is a focused follow-up to #4472, not another Opus 5 integration.

It resolves the unresolved review finding at https://github.com/pingdotgg/t3code/pull/4472#discussion_r3647506358: after opus was repointed to claude-opus-5, Claude Code versions below 2.1.219 omit Opus 5 from the live catalog, so resolveSelectableModel() returned null and selection fell through to the provider default — claude-fable-5 on 2.1.169 and above — instead of the newest available Opus.

The fix keeps the bare opus alias inside the Opus family by walking a fixed built-in priority list, so it is independent of the user's modelOrder preferences and never selects an arbitrary custom name such as claude-opus-custom. Explicit opus-5 still resolves to nothing when Opus 5 is absent, and a custom model named exactly opus is still preserved by the existing direct-match path.

Scope is packages/shared, plus a regression test in apps/web. No SDK bump and no changes to the version gate.

mihneaptu avatar Jul 24 '26 22:07 mihneaptu

Approvability

Verdict: Needs human review

This PR changes runtime model selection behavior for the 'opus' alias fallback logic, and has an unresolved review comment identifying a potential bug where custom model slugs could incorrectly be selected as fallbacks.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Jul 24 '26 22:07 macroscopeapp[bot]

One finding unrelated to this PR, flagged here rather than in the description. Live verification details now live in the description itself.

The five tests in apps/server/src/textGeneration/ClaudeTextGeneration.test.ts fail on Windows on unmodified main at 41a430a8, independently of this change. They are not hermetic on Windows: the fixture prepends a fake claude script to PATH using a POSIX : separator and writes it extension-less, so the Windows resolver skips it (no PATHEXT match) and the real installed CLI is invoked instead. Failures therefore appear as live model prose replacing expected fixtures, or as live 429 / Not logged in errors.

Happy to open a separate issue or PR for that if useful; it is out of scope here.

mihneaptu avatar Jul 24 '26 22:07 mihneaptu