@@ -150,6 +150,12 @@ pub(crate) fn test_config() -> Config {
150150 . expect ( "load default test config" )
151151}
152152
153+ impl Config {
154+ pub ( crate ) fn custom_model_alias ( & self , alias : & str ) -> Option < & CustomModelConfig > {
155+ self . custom_models . get ( alias)
156+ }
157+ }
158+
153159/// Application configuration loaded from disk and merged with overrides.
154160#[ derive( Debug , Clone , PartialEq ) ]
155161pub struct Permissions {
@@ -343,6 +349,9 @@ pub struct Config {
343349 /// Combined provider map (defaults merged with user-defined overrides).
344350 pub model_providers : HashMap < String , ModelProviderInfo > ,
345351
352+ /// User-defined model aliases shown in the picker.
353+ pub custom_models : HashMap < String , CustomModelConfig > ,
354+
346355 /// Maximum number of bytes to include from an AGENTS.md project doc file.
347356 pub project_doc_max_bytes : usize ,
348357
@@ -1117,6 +1126,10 @@ pub struct ConfigToml {
11171126 #[ serde( default ) ]
11181127 pub model_providers : HashMap < String , ModelProviderInfo > ,
11191128
1129+ /// User-defined model aliases that can override model context settings.
1130+ #[ serde( default ) ]
1131+ pub custom_models : Vec < CustomModelToml > ,
1132+
11201133 /// Maximum number of bytes to include from an AGENTS.md project doc file.
11211134 pub project_doc_max_bytes : Option < usize > ,
11221135
@@ -1351,6 +1364,29 @@ pub struct RealtimeAudioToml {
13511364 pub speaker : Option < String > ,
13521365}
13531366
1367+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
1368+ pub struct CustomModelConfig {
1369+ /// Provider-facing model slug used on API requests.
1370+ pub model : String ,
1371+ /// Optional context window override applied when this alias is selected.
1372+ pub model_context_window : Option < i64 > ,
1373+ /// Optional auto-compaction token limit override applied when this alias is selected.
1374+ pub model_auto_compact_token_limit : Option < i64 > ,
1375+ }
1376+
1377+ #[ derive( Serialize , Deserialize , Debug , Clone , Default , PartialEq , Eq , JsonSchema ) ]
1378+ #[ schemars( deny_unknown_fields) ]
1379+ pub struct CustomModelToml {
1380+ /// User-facing alias shown in the model picker.
1381+ pub name : String ,
1382+ /// Provider-facing model slug used on API requests.
1383+ pub model : String ,
1384+ /// Optional context window override applied when this alias is selected.
1385+ pub model_context_window : Option < i64 > ,
1386+ /// Optional auto-compaction token limit override applied when this alias is selected.
1387+ pub model_auto_compact_token_limit : Option < i64 > ,
1388+ }
1389+
13541390#[ derive( Serialize , Deserialize , Debug , Clone , Default , PartialEq , JsonSchema ) ]
13551391#[ schemars( deny_unknown_fields) ]
13561392pub struct ToolsToml {
@@ -1842,6 +1878,24 @@ impl Config {
18421878 for ( key, provider) in cfg. model_providers . into_iter ( ) {
18431879 model_providers. entry ( key) . or_insert ( provider) ;
18441880 }
1881+ let mut custom_models = HashMap :: new ( ) ;
1882+ for custom in cfg. custom_models {
1883+ let alias = custom. name ;
1884+ if custom_models. contains_key ( & alias) {
1885+ return Err ( std:: io:: Error :: new (
1886+ ErrorKind :: InvalidInput ,
1887+ format ! ( "duplicate custom model alias: {alias}" ) ,
1888+ ) ) ;
1889+ }
1890+ custom_models. insert (
1891+ alias,
1892+ CustomModelConfig {
1893+ model : custom. model ,
1894+ model_context_window : custom. model_context_window ,
1895+ model_auto_compact_token_limit : custom. model_auto_compact_token_limit ,
1896+ } ,
1897+ ) ;
1898+ }
18451899
18461900 let model_provider_id = model_provider
18471901 . or ( config_profile. model_provider )
@@ -2157,6 +2211,7 @@ impl Config {
21572211 mcp_oauth_callback_port : cfg. mcp_oauth_callback_port ,
21582212 mcp_oauth_callback_url : cfg. mcp_oauth_callback_url . clone ( ) ,
21592213 model_providers,
2214+ custom_models,
21602215 project_doc_max_bytes : cfg. project_doc_max_bytes . unwrap_or ( PROJECT_DOC_MAX_BYTES ) ,
21612216 project_doc_fallback_filenames : cfg
21622217 . project_doc_fallback_filenames
0 commit comments