MCPcopy
hub / github.com/claude-code-best/claude-code / parseUserSpecifiedModel

Function parseUserSpecifiedModel

src/utils/model/model.ts:535–597  ·  view source on GitHub ↗
(
  modelInput: ModelName | ModelAlias,
)

Source from the content-addressed store, hash-verified

533 * @param modelInput The model alias or name provided by the user.
534 */
535export function parseUserSpecifiedModel(
536 modelInput: ModelName | ModelAlias,
537): ModelName {
538 const modelInputTrimmed = modelInput.trim()
539 const normalizedModel = modelInputTrimmed.toLowerCase()
540
541 const has1mTag = has1mContext(normalizedModel)
542 const modelString = has1mTag
543 ? normalizedModel.replace(/\[1m]$/i, '').trim()
544 : normalizedModel
545
546 if (isModelAlias(modelString)) {
547 switch (modelString) {
548 case 'opusplan':
549 return getDefaultSonnetModel() + (has1mTag ? '[1m]' : '') // Sonnet is default, Opus in plan mode
550 case 'sonnet':
551 return getDefaultSonnetModel() + (has1mTag ? '[1m]' : '')
552 case 'haiku':
553 return getDefaultHaikuModel() + (has1mTag ? '[1m]' : '')
554 case 'opus':
555 return getDefaultOpusModel() + (has1mTag ? '[1m]' : '')
556 case 'best':
557 return getBestModel()
558 default:
559 }
560 }
561
562 // Opus 4/4.1 are no longer available on the first-party API (same as
563 // Claude.ai) — silently remap to the current Opus default. The 'opus'
564 // alias resolves to the current default Opus (4.7), so the only users
565 // on these explicit strings pinned them in settings/env/--model/SDK
566 // before 4.5 launched. 3P providers may not yet have 4.6/4.7 capacity,
567 // so pass through unchanged.
568 if (
569 getAPIProvider() === 'firstParty' &&
570 isLegacyOpusFirstParty(modelString) &&
571 isLegacyModelRemapEnabled()
572 ) {
573 return getDefaultOpusModel() + (has1mTag ? '[1m]' : '')
574 }
575
576 if (process.env.USER_TYPE === 'ant') {
577 const has1mAntTag = has1mContext(normalizedModel)
578 const baseAntModel = normalizedModel.replace(/\[1m]$/i, '').trim()
579
580 const antModel = resolveAntModel(baseAntModel)
581 if (antModel) {
582 const suffix = has1mAntTag ? '[1m]' : ''
583 return antModel.model + suffix
584 }
585
586 // Fall through to the alias string if we cannot load the config. The API calls
587 // will fail with this string, but we should hear about it through feedback and
588 // can tell the user to restart/wait for flag cache refresh to get the latest values.
589 }
590
591 // Preserve original case for custom model names (e.g., Azure Foundry deployment IDs)
592 // Only strip [1m] suffix if present, maintaining case of the base model

Callers 15

getDefaultTeammateModelFunction · 0.85
renderToolUseTagFunction · 0.85
callFunction · 0.85
submitMessageMethod · 0.85
logSessionTelemetryFunction · 0.85
runFunction · 0.85
shouldShowEffortCalloutFunction · 0.85
resolveOptionModelFunction · 0.85
restoreAgentFromSessionFunction · 0.85
modelBelongsToFamilyFunction · 0.85

Calls 10

has1mContextFunction · 0.85
isModelAliasFunction · 0.85
getDefaultSonnetModelFunction · 0.85
getDefaultHaikuModelFunction · 0.85
getDefaultOpusModelFunction · 0.85
getBestModelFunction · 0.85
getAPIProviderFunction · 0.85
isLegacyOpusFirstPartyFunction · 0.85
resolveAntModelFunction · 0.85

Tested by

no test coverage detected