@@ -781,36 +781,44 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
781781
782782 await this . updateGlobalState ( "mode" , newMode )
783783
784- // Load the saved API config for the new mode if it exists
785- const savedConfigId = await this . providerSettingsManager . getModeConfigId ( newMode )
786- const listApiConfig = await this . providerSettingsManager . listConfig ( )
784+ const stickyModesEnabled = this . getGlobalState ( "stickyModesEnabled" ) ?? true
787785
788- // Update listApiConfigMeta first to ensure UI has latest data
789- await this . updateGlobalState ( "listApiConfigMeta" , listApiConfig )
786+ if ( stickyModesEnabled ) {
787+ // Load the saved API config for the new mode if it exists
788+ const savedConfigId = await this . providerSettingsManager . getModeConfigId ( newMode )
789+ const listApiConfig = await this . providerSettingsManager . listConfig ( )
790790
791- // If this mode has a saved config, use it
792- if ( savedConfigId ) {
793- const config = listApiConfig ?. find ( ( c ) => c . id === savedConfigId )
791+ // Update listApiConfigMeta first to ensure UI has latest data
792+ await this . updateGlobalState ( "listApiConfigMeta" , listApiConfig )
794793
795- if ( config ?. name ) {
796- const apiConfig = await this . providerSettingsManager . loadConfig ( config . name )
794+ // If this mode has a saved config, use it
795+ if ( savedConfigId ) {
796+ const config = listApiConfig ?. find ( ( c ) => c . id === savedConfigId )
797797
798- await Promise . all ( [
799- this . updateGlobalState ( "currentApiConfigName" , config . name ) ,
800- this . updateApiConfiguration ( apiConfig ) ,
801- ] )
802- }
803- } else {
804- // If no saved config for this mode, save current config as default
805- const currentApiConfigName = this . getGlobalState ( "currentApiConfigName" )
798+ if ( config ?. name ) {
799+ const apiConfig = await this . providerSettingsManager . loadConfig ( config . name )
800+
801+ await Promise . all ( [
802+ this . updateGlobalState ( "currentApiConfigName" , config . name ) ,
803+ this . updateApiConfiguration ( apiConfig ) ,
804+ ] )
805+ }
806+ } else {
807+ // If no saved config for this mode, save current config as default
808+ const currentApiConfigName = this . getGlobalState ( "currentApiConfigName" )
806809
807- if ( currentApiConfigName ) {
808- const config = listApiConfig ?. find ( ( c ) => c . name === currentApiConfigName )
810+ if ( currentApiConfigName ) {
811+ const config = listApiConfig ?. find ( ( c ) => c . name === currentApiConfigName )
809812
810- if ( config ?. id ) {
811- await this . providerSettingsManager . setModeConfig ( newMode , config . id )
813+ if ( config ?. id ) {
814+ await this . providerSettingsManager . setModeConfig ( newMode , config . id )
815+ }
812816 }
813817 }
818+ } else {
819+ // If sticky modes are disabled, ensure we don't accidentally load a stale config
820+ const listApiConfig = await this . providerSettingsManager . listConfig ( )
821+ await this . updateGlobalState ( "listApiConfigMeta" , listApiConfig )
814822 }
815823
816824 await this . postStateToWebview ( )
@@ -1226,6 +1234,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12261234 showRooIgnoredFiles,
12271235 language,
12281236 maxReadFileLine,
1237+ stickyModesEnabled,
12291238 } = await this . getState ( )
12301239
12311240 const telemetryKey = process . env . POSTHOG_API_KEY
@@ -1310,6 +1319,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13101319 maxReadFileLine : maxReadFileLine ?? 500 ,
13111320 settingsImportedAt : this . settingsImportedAt ,
13121321 hasSystemPromptOverride,
1322+ stickyModesEnabled : stickyModesEnabled ?? true ,
13131323 }
13141324 }
13151325
@@ -1397,6 +1407,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13971407 telemetrySetting : stateValues . telemetrySetting || "unset" ,
13981408 showRooIgnoredFiles : stateValues . showRooIgnoredFiles ?? true ,
13991409 maxReadFileLine : stateValues . maxReadFileLine ?? 500 ,
1410+ stickyModesEnabled : stateValues . stickyModesEnabled ?? true ,
14001411 }
14011412 }
14021413
0 commit comments