1- use clap:: Args ;
21use clap:: CommandFactory ;
32use clap:: Parser ;
43use clap_complete:: Shell ;
54use clap_complete:: generate;
65use codex_acp:: init_file_tracing;
76use codex_arg0:: arg0_dispatch_or_else;
7+ #[ cfg( feature = "chatgpt" ) ]
88use codex_chatgpt:: apply_command:: ApplyCommand ;
9+ #[ cfg( feature = "chatgpt" ) ]
910use codex_chatgpt:: apply_command:: run_apply_command;
1011use codex_cli:: LandlockCommand ;
1112use codex_cli:: SeatbeltCommand ;
1213use codex_cli:: WindowsCommand ;
14+ #[ cfg( feature = "login" ) ]
1315use codex_cli:: login:: read_api_key_from_stdin;
16+ #[ cfg( feature = "login" ) ]
1417use codex_cli:: login:: run_login_status;
18+ #[ cfg( feature = "login" ) ]
1519use codex_cli:: login:: run_login_with_api_key;
20+ #[ cfg( feature = "login" ) ]
1621use codex_cli:: login:: run_login_with_chatgpt;
22+ #[ cfg( feature = "login" ) ]
1723use codex_cli:: login:: run_login_with_device_code;
24+ #[ cfg( feature = "login" ) ]
1825use codex_cli:: login:: run_logout;
26+ #[ cfg( feature = "cloud-tasks" ) ]
1927use codex_cloud_tasks:: Cli as CloudTasksCli ;
2028use codex_common:: CliConfigOverrides ;
2129use codex_exec:: Cli as ExecCli ;
2230use codex_execpolicy:: ExecPolicyCheckCommand ;
31+ #[ cfg( feature = "responses-api-proxy" ) ]
2332use codex_responses_api_proxy:: Args as ResponsesApiProxyArgs ;
2433use codex_tui:: AppExitInfo ;
2534use codex_tui:: Cli as TuiCli ;
@@ -28,10 +37,12 @@ use owo_colors::OwoColorize;
2837use std:: path:: PathBuf ;
2938use supports_color:: Stream ;
3039
40+ #[ cfg( feature = "mcp-server" ) ]
3141mod mcp_cmd;
3242#[ cfg( not( windows) ) ]
3343mod wsl_paths;
3444
45+ #[ cfg( feature = "mcp-server" ) ]
3546use crate :: mcp_cmd:: McpCli ;
3647
3748use codex_core:: config:: Config ;
@@ -74,18 +85,23 @@ enum Subcommand {
7485 Exec ( ExecCli ) ,
7586
7687 /// Manage login.
88+ #[ cfg( feature = "login" ) ]
7789 Login ( LoginCommand ) ,
7890
7991 /// Remove stored authentication credentials.
92+ #[ cfg( feature = "login" ) ]
8093 Logout ( LogoutCommand ) ,
8194
8295 /// [experimental] Run Codex as an MCP server and manage MCP servers.
96+ #[ cfg( feature = "mcp-server" ) ]
8397 Mcp ( McpCli ) ,
8498
8599 /// [experimental] Run the Codex MCP server (stdio transport).
100+ #[ cfg( feature = "mcp-server" ) ]
86101 McpServer ,
87102
88103 /// [experimental] Run the app server or related tooling.
104+ #[ cfg( feature = "app-server" ) ]
89105 AppServer ( AppServerCommand ) ,
90106
91107 /// Generate shell completion scripts.
@@ -100,17 +116,20 @@ enum Subcommand {
100116 Execpolicy ( ExecpolicyCommand ) ,
101117
102118 /// Apply the latest diff produced by Codex agent as a `git apply` to your local working tree.
119+ #[ cfg( feature = "chatgpt" ) ]
103120 #[ clap( visible_alias = "a" ) ]
104121 Apply ( ApplyCommand ) ,
105122
106123 /// Resume a previous interactive session (picker by default; use --last to continue the most recent).
107124 Resume ( ResumeCommand ) ,
108125
109126 /// [EXPERIMENTAL] Browse tasks from Codex Cloud and apply changes locally.
127+ #[ cfg( feature = "cloud-tasks" ) ]
110128 #[ clap( name = "cloud" , alias = "cloud-tasks" ) ]
111129 Cloud ( CloudTasksCli ) ,
112130
113131 /// Internal: run the responses API proxy.
132+ #[ cfg( feature = "responses-api-proxy" ) ]
114133 #[ clap( hide = true ) ]
115134 ResponsesApiProxy ( ResponsesApiProxyArgs ) ,
116135
@@ -181,6 +200,7 @@ enum ExecpolicySubcommand {
181200 Check ( ExecPolicyCheckCommand ) ,
182201}
183202
203+ #[ cfg( feature = "login" ) ]
184204#[ derive( Debug , Parser ) ]
185205struct LoginCommand {
186206 #[ clap( skip) ]
@@ -216,25 +236,29 @@ struct LoginCommand {
216236 action : Option < LoginSubcommand > ,
217237}
218238
239+ #[ cfg( feature = "login" ) ]
219240#[ derive( Debug , clap:: Subcommand ) ]
220241enum LoginSubcommand {
221242 /// Show login status.
222243 Status ,
223244}
224245
246+ #[ cfg( feature = "login" ) ]
225247#[ derive( Debug , Parser ) ]
226248struct LogoutCommand {
227249 #[ clap( skip) ]
228250 config_overrides : CliConfigOverrides ,
229251}
230252
253+ #[ cfg( feature = "app-server" ) ]
231254#[ derive( Debug , Parser ) ]
232255struct AppServerCommand {
233256 /// Omit to run the app server; specify a subcommand for tooling.
234257 #[ command( subcommand) ]
235258 subcommand : Option < AppServerSubcommand > ,
236259}
237260
261+ #[ cfg( feature = "app-server" ) ]
238262#[ derive( Debug , clap:: Subcommand ) ]
239263enum AppServerSubcommand {
240264 /// [experimental] Generate TypeScript bindings for the app server protocol.
@@ -244,7 +268,8 @@ enum AppServerSubcommand {
244268 GenerateJsonSchema ( GenerateJsonSchemaCommand ) ,
245269}
246270
247- #[ derive( Debug , Args ) ]
271+ #[ cfg( feature = "app-server" ) ]
272+ #[ derive( Debug , clap:: Args ) ]
248273struct GenerateTsCommand {
249274 /// Output directory where .ts files will be written
250275 #[ arg( short = 'o' , long = "out" , value_name = "DIR" ) ]
@@ -255,7 +280,8 @@ struct GenerateTsCommand {
255280 prettier : Option < PathBuf > ,
256281}
257282
258- #[ derive( Debug , Args ) ]
283+ #[ cfg( feature = "app-server" ) ]
284+ #[ derive( Debug , clap:: Args ) ]
259285struct GenerateJsonSchemaCommand {
260286 /// Output directory where the schema bundle will be written
261287 #[ arg( short = 'o' , long = "out" , value_name = "DIR" ) ]
@@ -458,14 +484,17 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
458484 ) ;
459485 codex_exec:: run_main ( exec_cli, codex_linux_sandbox_exe) . await ?;
460486 }
487+ #[ cfg( feature = "mcp-server" ) ]
461488 Some ( Subcommand :: McpServer ) => {
462489 codex_mcp_server:: run_main ( codex_linux_sandbox_exe, root_config_overrides) . await ?;
463490 }
491+ #[ cfg( feature = "mcp-server" ) ]
464492 Some ( Subcommand :: Mcp ( mut mcp_cli) ) => {
465493 // Propagate any root-level config overrides (e.g. `-c key=value`).
466494 prepend_config_flags ( & mut mcp_cli. config_overrides , root_config_overrides. clone ( ) ) ;
467495 mcp_cli. run ( ) . await ?;
468496 }
497+ #[ cfg( feature = "app-server" ) ]
469498 Some ( Subcommand :: AppServer ( app_server_cli) ) => match app_server_cli. subcommand {
470499 None => {
471500 codex_app_server:: run_main ( codex_linux_sandbox_exe, root_config_overrides) . await ?;
@@ -497,6 +526,7 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
497526 let exit_info = codex_tui:: run_main ( interactive, codex_linux_sandbox_exe) . await ?;
498527 handle_app_exit ( exit_info) ?;
499528 }
529+ #[ cfg( feature = "login" ) ]
500530 Some ( Subcommand :: Login ( mut login_cli) ) => {
501531 prepend_config_flags (
502532 & mut login_cli. config_overrides ,
@@ -528,6 +558,7 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
528558 }
529559 }
530560 }
561+ #[ cfg( feature = "login" ) ]
531562 Some ( Subcommand :: Logout ( mut logout_cli) ) => {
532563 prepend_config_flags (
533564 & mut logout_cli. config_overrides ,
@@ -538,6 +569,7 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
538569 Some ( Subcommand :: Completion ( completion_cli) ) => {
539570 print_completion ( completion_cli) ;
540571 }
572+ #[ cfg( feature = "cloud-tasks" ) ]
541573 Some ( Subcommand :: Cloud ( mut cloud_cli) ) => {
542574 prepend_config_flags (
543575 & mut cloud_cli. config_overrides ,
@@ -583,13 +615,15 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
583615 Some ( Subcommand :: Execpolicy ( ExecpolicyCommand { sub } ) ) => match sub {
584616 ExecpolicySubcommand :: Check ( cmd) => run_execpolicycheck ( cmd) ?,
585617 } ,
618+ #[ cfg( feature = "chatgpt" ) ]
586619 Some ( Subcommand :: Apply ( mut apply_cli) ) => {
587620 prepend_config_flags (
588621 & mut apply_cli. config_overrides ,
589622 root_config_overrides. clone ( ) ,
590623 ) ;
591624 run_apply_command ( apply_cli, None ) . await ?;
592625 }
626+ #[ cfg( feature = "responses-api-proxy" ) ]
593627 Some ( Subcommand :: ResponsesApiProxy ( args) ) => {
594628 tokio:: task:: spawn_blocking ( move || codex_responses_api_proxy:: run_main ( args) )
595629 . await ??;
0 commit comments