@@ -33,6 +33,7 @@ import {
3333import {
3434 buildProviderReplayFamilyHooks ,
3535 cloneFirstTemplateModel ,
36+ type ModelCompatConfig ,
3637 modelCostsEqual ,
3738 type ProviderPlugin ,
3839 resolveClaudeFable5ModelIdentity ,
@@ -442,6 +443,30 @@ function resolveAnthropicUnreleasedCanonicalModelId(modelId: string): string {
442443 return / (?: ^ | - ) c l a u d e - s o n n e t - / . test ( modelId ) ? "claude-sonnet-5" : "claude-opus-5" ;
443444}
444445
446+ // Lazily indexed manifest compat per provider so hand-built dynamic rows keep
447+ // catalog capability metadata even when the run's model registry is empty
448+ // (for example env-key-only runs without a generated models.json).
449+ let anthropicManifestCompatIndex : Map < string , ModelCompatConfig > | undefined ;
450+
451+ function resolveAnthropicManifestCompat (
452+ provider : string ,
453+ modelId : string ,
454+ ) : ModelCompatConfig | undefined {
455+ if ( ! anthropicManifestCompatIndex ) {
456+ anthropicManifestCompatIndex = new Map ( ) ;
457+ const providers = manifest . modelCatalog ?. providers ?? { } ;
458+ for ( const [ providerId , catalog ] of Object . entries ( providers ) ) {
459+ for ( const model of catalog . models ?? [ ] ) {
460+ const compat = ( model as { compat ?: ModelCompatConfig } ) . compat ;
461+ if ( compat ) {
462+ anthropicManifestCompatIndex . set ( `${ providerId } /${ model . id } ` , compat ) ;
463+ }
464+ }
465+ }
466+ }
467+ return anthropicManifestCompatIndex . get ( `${ provider } /${ modelId } ` ) ;
468+ }
469+
445470function buildAnthropicForwardCompatModel (
446471 ctx : ProviderResolveDynamicModelContext ,
447472) : ProviderRuntimeModel | undefined {
@@ -457,10 +482,21 @@ function buildAnthropicForwardCompatModel(
457482 }
458483 const provider =
459484 normalizedProvider === CLAUDE_CLI_BACKEND_ID ? CLAUDE_CLI_BACKEND_ID : PROVIDER_ID ;
485+ // This hand-built row replaces the catalog row when the runtime prefers
486+ // plugin-resolved modern models, so it must carry the catalog's compat
487+ // capability metadata (for example compat.codeMode) instead of dropping it.
488+ // Registry compat wins when present (it may carry config overrides); the
489+ // manifest index covers empty-registry runs such as env-key-only sessions.
490+ const catalogModel = ctx . modelRegistry . find ( provider , trimmedModelId ) as
491+ | Pick < ProviderRuntimeModel , "compat" >
492+ | null
493+ | undefined ;
494+ const compat = catalogModel ?. compat ?? resolveAnthropicManifestCompat ( provider , trimmedModelId ) ;
460495 return {
461496 id : trimmedModelId ,
462497 name : trimmedModelId ,
463498 provider,
499+ ...( compat ? { compat } : { } ) ,
464500 api : "anthropic-messages" ,
465501 baseUrl : "https://api.anthropic.com" ,
466502 reasoning : true ,
0 commit comments