1use clap::{ArgAction, ColorChoice, Parser, Subcommand, ValueHint};
2use colorchoice_clap::Color as ColorSelection;
3use std::env;
4use std::path::PathBuf;
5
6use crate::config::models::ModelId;
7
8mod acp;
9mod ask;
10mod background;
11mod bench;
12mod companion;
13mod config;
14mod debug;
15mod exec;
16mod models;
17mod plugins;
18mod pods;
19mod review;
20mod schedule;
21mod schema;
22mod secret;
23mod session_store;
24mod skills;
25mod version;
26mod webmcp;
27pub use version::long_version;
28
29pub use acp::AgentClientProtocolTarget;
30pub use ask::{AskCommandOptions, AskOutputFormat};
31pub use background::BackgroundSubagentArgs;
32pub use bench::BenchAllocatorArgs;
33pub use companion::{CompanionCommand, CompanionSetupArgs};
34pub use config::{
35 ConfigCommand, ConfigFile, ConfigResetArgs, ContextConfig, LoggingConfig, PerformanceConfig, SecurityConfig,
36 ToolConfig,
37};
38pub use debug::DebugCommand;
39pub use exec::{EvalOutputFormat, ExecEvalArgs, ExecResumeArgs, ExecSubcommand};
40pub use models::ModelCommands;
41pub use plugins::PluginsSubcommand;
42pub use pods::PodsCommands;
43pub use review::ReviewArgs;
44pub use schedule::{ScheduleCreateArgs, ScheduleSubcommand};
45pub use schema::{SchemaCommands, SchemaMode, SchemaOutputFormat};
46pub use secret::{MigrateArgs, SecretArgs, SecretProvider, SecretSubcommand};
47pub use session_store::SessionStoreCommand;
48pub use skills::{SkillsRefSubcommand, SkillsSubcommand};
49pub use webmcp::{WebmcpCommand, WebmcpPairArgs, WebmcpServeArgs};
50
51#[derive(Parser, Debug, Clone)]
52pub struct Cli {
53 #[command(flatten)]
55 pub color: ColorSelection,
56
57 #[arg(
59 value_name = "WORKSPACE",
60 value_hint = ValueHint::DirPath,
61 value_parser = version::parse_workspace_directory,
62 global = true,
63 last = true
64 )]
65 pub workspace_path: Option<PathBuf>,
66
67 #[arg(long, global = true)]
69 pub model: Option<String>,
70
71 #[arg(long, global = true)]
73 pub provider: Option<String>,
74
75 #[arg(long, global = true, default_value = crate::config::constants::defaults::DEFAULT_API_KEY_ENV)]
77 pub api_key_env: String,
78
79 #[arg(
81 long,
82 global = true,
83 alias = "workspace-dir",
84 value_name = "PATH",
85 value_hint = ValueHint::DirPath,
86 value_parser = version::parse_workspace_directory
87 )]
88 pub workspace: Option<PathBuf>,
89
90 #[arg(long, global = true)]
92 pub research_preview: bool,
93
94 #[arg(long, global = true, default_value = "moderate")]
96 pub security_level: String,
97
98 #[arg(long, global = true)]
100 pub show_file_diffs: bool,
101
102 #[arg(long, global = true, default_value_t = 5)]
104 pub max_concurrent_ops: usize,
105
106 #[arg(long, global = true, default_value_t = 30)]
108 pub api_rate_limit: usize,
109
110 #[arg(long, global = true, default_value_t = 10)]
112 pub max_tool_calls: usize,
113
114 #[arg(long, global = true)]
116 pub debug: bool,
117
118 #[arg(long, global = true)]
120 pub verbose: bool,
121
122 #[arg(short, long, global = true)]
124 pub quiet: bool,
125
126 #[arg(
128 short = 'c',
129 long = "config",
130 value_name = "KEY=VALUE|PATH",
131 action = ArgAction::Append,
132 global = true
133 )]
134 pub config: Vec<String>,
135
136 #[arg(long, global = true, default_value = "info")]
138 pub log_level: String,
139
140 #[arg(long, global = true)]
142 pub no_color: bool,
143
144 #[arg(long, global = true, value_name = "THEME")]
146 pub theme: Option<String>,
147
148 #[arg(short = 't', long, default_value_t = 250)]
150 pub tick_rate: u64,
151
152 #[arg(short = 'f', long, default_value_t = 60)]
154 pub frame_rate: u64,
155
156 #[arg(long, global = true)]
158 pub enable_skills: bool,
159
160 #[arg(long, global = true)]
162 pub chrome: bool,
163
164 #[arg(long = "no-chrome", global = true, conflicts_with = "chrome")]
166 pub no_chrome: bool,
167
168 #[arg(long, global = true)]
170 pub skip_confirmations: bool,
171
172 #[arg(long = "codex-experimental", global = true, conflicts_with = "no_codex_experimental")]
174 pub codex_experimental: bool,
175
176 #[arg(long = "no-codex-experimental", global = true, conflicts_with = "codex_experimental")]
178 pub no_codex_experimental: bool,
179
180 #[arg(
182 short = 'p',
183 long = "print",
184 value_name = "PROMPT",
185 value_hint = ValueHint::Other,
186 num_args = 0..=1,
187 default_missing_value = "",
188 global = true,
189 conflicts_with_all = ["full_auto"]
190 )]
191 pub print: Option<String>,
192
193 #[arg(
195 long = "full-auto",
196 global = true,
197 help = "Run non-interactively with full-auto permission review",
198 long_help = r#"Run non-interactively on top of the active primary agent.
199
200If no primary agent is explicitly selected or configured, VT Code selects the effective `auto` primary agent. Explicit choices, including `duck`, are honoured. Full-auto is an execution and permission layer, not a primary agent.
201
202Full-auto does not override explicit denies or grant tools outside `[automation.full_auto].allowed_tools`. Tools outside that allow-list are denied. Promptable actions inside the allow-list are routed through automatic permission review after deny and policy checks instead of asking. The run fails fast if it needs the defaulted `auto` primary agent and no effective `auto` exists."#,
203 value_name = "PROMPT",
204 num_args = 0..=1,
205 default_missing_value = "",
206 value_hint = ValueHint::Other
207 )]
208 pub full_auto: Option<String>,
209
210 #[arg(
212 short = 'r',
213 long = "resume",
214 global = true,
215 value_name = "SESSION_ID",
216 num_args = 0..=1,
217 default_missing_value = "__interactive__",
218 conflicts_with_all = ["continue_latest", "full_auto"]
219 )]
220 pub resume_session: Option<String>,
221
222 #[arg(
224 long = "continue",
225 visible_alias = "continue-session",
226 global = true,
227 conflicts_with_all = ["resume_session", "full_auto"]
228 )]
229 pub continue_latest: bool,
230
231 #[arg(
233 long = "fork-session",
234 global = true,
235 value_name = "SESSION_ID",
236 conflicts_with_all = ["resume_session", "continue_latest", "full_auto"]
237 )]
238 pub fork_session: Option<String>,
239
240 #[arg(long, global = true)]
242 pub all: bool,
243
244 #[arg(long = "session-id", global = true, value_name = "CUSTOM_SUFFIX")]
246 pub session_id: Option<String>,
247
248 #[arg(long, global = true)]
250 pub summarize: bool,
251
252 #[arg(long, global = true, value_name = "AGENT")]
254 pub agent: Option<String>,
255
256 #[arg(long = "allowed-tools", global = true, value_name = "TOOLS", action = ArgAction::Append)]
258 pub allowed_tools: Vec<String>,
259
260 #[arg(long = "disallowed-tools", global = true, value_name = "TOOLS", action = ArgAction::Append)]
262 pub disallowed_tools: Vec<String>,
263
264 #[arg(
266 long = "dangerously-skip-permissions",
267 global = true,
268 help = "Auto-approve promptable actions while respecting denies and policy blocks",
269 long_help = "Auto-approve promptable actions while still respecting explicit denies and policy blocks."
270 )]
271 pub dangerously_skip_permissions: bool,
272
273 #[arg(long, global = true, conflicts_with_all = ["full_auto", "skip_confirmations", "dangerously_skip_permissions"])]
275 pub full_access: bool,
276
277 #[arg(long, global = true)]
279 pub ide: bool,
280
281 #[command(subcommand)]
282 pub command: Option<Commands>,
283}
284
285#[derive(Subcommand, Debug, Clone)]
286pub enum Commands {
287 #[command(name = "companion")]
289 Companion {
290 #[command(subcommand)]
291 command: CompanionCommand,
292 },
293
294 #[command(name = "acp")]
296 AgentClientProtocol {
297 #[arg(value_enum, default_value_t = AgentClientProtocolTarget::Zed)]
299 target: AgentClientProtocolTarget,
300 },
301
302 #[command(name = "session-store")]
306 SessionStore {
307 #[command(subcommand)]
308 command: SessionStoreCommand,
309 },
310
311 Chat,
313
314 Continue,
325
326 Ask {
336 #[arg(
338 value_name = "PROMPT",
339 long_help = "The prompt to send to the model.\n\nOmit to read from stdin (piped input).\nUse '-' to explicitly force reading from stdin."
340 )]
341 prompt: Option<String>,
342 #[arg(
344 long = "output-format",
345 value_enum,
346 value_name = "FORMAT",
347 long_help = "Output format for the response.\n\nCurrently supports:\n json - Emit the response as a structured JSON document."
348 )]
349 output_format: Option<AskOutputFormat>,
350 },
351 Exec {
364 #[arg(
366 long,
367 long_help = "Stream newline-delimited JSON events to stdout.\nEach line is a JSON object representing an agent event (tool call, message, etc.).\nUseful for programmatic consumption and CI integration."
368 )]
369 json: bool,
370 #[arg(
372 long,
373 long_help = "Simulate execution without making changes.\nThe agent plans tool calls but does not execute mutating operations (file writes, shell commands).\nUseful for previewing what the agent would do."
374 )]
375 dry_run: bool,
376 #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath, long_help = "Write the full JSONL event transcript to this file.\nIncludes all agent events: tool calls, messages, errors, and metadata.")]
378 events: Option<PathBuf>,
379 #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath, long_help = "Write only the final agent message to this file.\nUseful for piping the agent's response into other tools.")]
381 last_message_file: Option<PathBuf>,
382 #[command(subcommand)]
384 command: Option<ExecSubcommand>,
385 #[arg(
387 value_name = "PROMPT",
388 long_help = "The prompt to execute.\n\nOmit to read from stdin (piped input).\nUse '-' to explicitly force reading from stdin.\nQuote multi-word prompts: vtcode exec \"fix the bug in auth.rs\""
389 )]
390 prompt: Option<String>,
391 },
392 Eval(ExecEvalArgs),
402 Schedule {
414 #[command(subcommand)]
415 command: ScheduleSubcommand,
416 },
417
418 #[command(name = "background-subagent", hide = true)]
420 BackgroundSubagent(BackgroundSubagentArgs),
421
422 #[command(
424 long_about = "Run a non-interactive code review.\n\nExamples:\n vtcode review\n vtcode review \"Review the full diff for correctness and regressions\"\n vtcode review --last-diff\n vtcode review --target HEAD~1..HEAD\n vtcode review --file src/main.rs --file crates/codegen/vtcode-core/src/lib.rs\n vtcode review --style security \"Focus on auth bypass and injection\""
425 )]
426 Review(ReviewArgs),
427
428 Schema {
430 #[command(subcommand)]
431 command: SchemaCommands,
432 },
433
434 ChatVerbose,
436
437 Analyze {
439 #[arg(value_name = "TYPE", default_value = "full")]
441 analysis_type: String,
442 },
443
444 #[command(name = "trajectory")]
446 Trajectory {
447 #[arg(long)]
449 file: Option<PathBuf>,
450 #[arg(long, default_value_t = 10)]
452 top: usize,
453 },
454
455 #[command(name = "debug")]
457 Debug {
458 #[command(subcommand)]
459 command: DebugCommand,
460 },
461
462 Notify {
464 #[arg(long, value_name = "TITLE")]
466 title: Option<String>,
467 #[arg(value_name = "MESSAGE")]
469 message: String,
470 },
471
472 Benchmark {
474 #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath)]
476 task_file: Option<PathBuf>,
477 #[arg(long, value_name = "JSON")]
479 task: Option<String>,
480 #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath)]
482 output: Option<PathBuf>,
483 #[arg(long, value_name = "COUNT")]
485 max_tasks: Option<usize>,
486 },
487
488 #[command(name = "bench-allocator")]
496 BenchAllocator(BenchAllocatorArgs),
497
498 CreateProject {
500 name: String,
501 #[arg(long = "feature", value_name = "FEATURE", action = ArgAction::Append)]
502 features: Vec<String>,
503 },
504
505 Revert {
507 #[arg(short, long)]
509 turn: usize,
510 #[arg(long)]
512 partial: Option<String>,
513 #[arg(long)]
515 session: Option<String>,
516 },
517
518 Snapshots,
520
521 #[command(name = "cleanup-snapshots")]
532 CleanupSnapshots {
533 #[arg(short, long, default_value_t = 50)]
538 max: usize,
539 },
540
541 Init {
550 #[arg(
552 long,
553 short = 'f',
554 long_help = "Overwrite AGENTS.md without confirmation.\nUse this in CI/CD or scripts where interactive prompts are not possible."
555 )]
556 force: bool,
557 },
558
559 #[command(name = "init-project")]
569 InitProject {
570 #[arg(
572 long,
573 long_help = "Name for the project.\nDefaults to the current directory name if not specified."
574 )]
575 name: Option<String>,
576 #[arg(long, long_help = "Overwrite existing project structure without confirmation.")]
578 force: bool,
579 #[arg(
581 long,
582 long_help = "Move existing config and cache files into the new project structure."
583 )]
584 migrate: bool,
585 },
586
587 Config {
601 #[command(subcommand)]
602 command: Option<ConfigCommand>,
603 #[arg(
605 long,
606 long_help = "Write the configuration to this path.\nDefaults to ./vtcode.toml in the current directory."
607 )]
608 output: Option<PathBuf>,
609 #[arg(
611 long,
612 long_help = "Write the configuration to the canonical user config directory.\nThis sets global defaults for all workspaces."
613 )]
614 global: bool,
615 },
616
617 Login {
629 #[arg(long_help = "The provider to authenticate with.\nSupported: openai, openrouter, copilot, codex")]
631 provider: String,
632 #[arg(
634 long,
635 default_value_t = false,
636 long_help = "Use the device-code OAuth flow.\nCurrently supported only for the `codex` provider.\nOpens a browser URL and asks you to enter a code."
637 )]
638 device_code: bool,
639 #[arg(
642 long,
643 default_value_t = false,
644 long_help = "Import ChatGPT OAuth tokens from Codex's auth.json.\n\
645 Requires that you have already run `codex login`.\n\
646 Currently supported only for the `openai` provider."
647 )]
648 from_codex: bool,
649 },
650
651 Logout {
659 #[arg(long_help = "The provider to deauthenticate.\nSupported: openai, openrouter, copilot, codex")]
661 provider: String,
662 },
663
664 Auth {
674 #[arg(long_help = "Show status for a single provider.\nOmit to show status for all supported providers.")]
676 provider: Option<String>,
677 },
678
679 #[command(name = "tool-policy")]
681 ToolPolicy {
682 #[command(subcommand)]
683 command: crate::cli::tool_policy_commands::ToolPolicyCommands,
684 },
685
686 #[command(name = "mcp")]
688 Mcp {
689 #[command(subcommand)]
690 command: crate::mcp::cli::McpCommands,
691 },
692
693 #[command(name = "a2a")]
695 A2a {
696 #[command(subcommand)]
697 command: super::super::a2a::cli::A2aCommands,
698 },
699
700 #[command(name = "webmcp")]
702 Webmcp {
703 #[command(subcommand)]
704 command: WebmcpCommand,
705 },
706
707 #[command(name = "app-server")]
709 AppServer {
710 #[arg(long, default_value = "stdio://")]
712 listen: String,
713 },
714
715 #[command(name = "desktop-server")]
717 DesktopServer,
718
719 #[command(name = "desktop")]
727 Desktop {
728 #[arg(value_name = "APP_PATH")]
730 app_path: Option<PathBuf>,
731 #[arg(
733 long,
734 conflicts_with = "app_path",
735 long_help = "Download and install the desktop app from the prebuilt release asset instead of opening it.\nUpdates install in place; fresh installs go to ~/Applications."
736 )]
737 install: bool,
738 },
739
740 Models {
742 #[command(subcommand)]
743 command: ModelCommands,
744 },
745
746 #[command(name = "pods")]
748 Pods {
749 #[command(subcommand)]
750 command: PodsCommands,
751 },
752
753 Man {
755 command: Option<String>,
757 #[arg(long, conflicts_with = "command", requires = "output")]
759 all_pages: bool,
760 #[arg(short, long)]
762 output: Option<PathBuf>,
763 },
764
765 #[command(subcommand)]
777 Skills(SkillsSubcommand),
778
779 #[command(subcommand)]
791 Plugins(PluginsSubcommand),
792
793 #[command(name = "list-skills", hide = true)]
795 ListSkills {},
796
797 Secret(SecretArgs),
809
810 #[command(name = "update")]
824 Update {
825 #[arg(
827 long,
828 long_help = "Check whether a newer version is available without installing it."
829 )]
830 check: bool,
831 #[arg(
833 long,
834 long_help = "Reinstall or downgrade even if the current version is already the latest."
835 )]
836 force: bool,
837 #[arg(long, long_help = "Print available release versions from GitHub and exit.")]
839 list: bool,
840 #[arg(
842 long,
843 default_value = "10",
844 long_help = "Maximum number of versions to display with --list."
845 )]
846 limit: usize,
847 #[arg(
849 long,
850 value_name = "VERSION",
851 long_help = "Pin the binary to a specific version.\nAuto-updates are disabled until --unpin is used."
852 )]
853 pin: Option<String>,
854 #[arg(long, long_help = "Remove a previously set version pin and resume auto-updates.")]
856 unpin: bool,
857 #[arg(
859 long,
860 value_name = "CHANNEL",
861 long_help = "Switch the release channel.\nAccepted values: stable, beta, nightly."
862 )]
863 channel: Option<String>,
864 #[arg(
866 long,
867 long_help = "Display the current update configuration (channel, pin, intervals) and exit."
868 )]
869 show_config: bool,
870 #[arg(
872 long,
873 conflicts_with = "without_desktop",
874 long_help = "Install or update the macOS desktop app from the prebuilt release asset without prompting.\nFails on non-macOS platforms."
875 )]
876 with_desktop: bool,
877 #[arg(
879 long,
880 conflicts_with = "with_desktop",
881 long_help = "Skip the macOS desktop app install/update step without prompting."
882 )]
883 without_desktop: bool,
884 },
885
886 #[command(name = "anthropic-api")]
888 AnthropicApi {
889 #[arg(long, default_value = "11434")]
891 port: u16,
892 #[arg(long, default_value = "127.0.0.1")]
894 host: String,
895 },
896}
897
898impl Default for Cli {
899 fn default() -> Self {
900 Self {
901 color: ColorSelection { color: ColorChoice::Auto },
902 workspace_path: None,
903 model: Some(ModelId::default().to_string()),
904 provider: Some("gemini".to_owned()),
905 api_key_env: "GEMINI_API_KEY".to_owned(),
906 workspace: None,
907 research_preview: false,
908 security_level: "moderate".to_owned(),
909 show_file_diffs: false,
910 max_concurrent_ops: 5,
911 api_rate_limit: 30,
912 max_tool_calls: 10,
913 verbose: false,
914 quiet: false,
915 config: Vec::new(),
916 log_level: "info".to_owned(),
917 no_color: false,
918 theme: None,
919 skip_confirmations: false,
920 codex_experimental: false,
921 no_codex_experimental: false,
922 print: None,
923 full_auto: None,
924 resume_session: None,
925 continue_latest: false,
926 fork_session: None,
927 all: false,
928 session_id: None,
929 summarize: false,
930 debug: false,
931 enable_skills: false,
932 tick_rate: 250,
933 frame_rate: 60,
934 agent: None,
935 allowed_tools: Vec::new(),
936 disallowed_tools: Vec::new(),
937 dangerously_skip_permissions: false,
938 full_access: false,
939 ide: false,
940 chrome: false,
941 no_chrome: false,
942 command: Some(Commands::Chat),
943 }
944 }
945}
946
947impl Cli {
948 pub fn get_api_key_env(&self) -> String {
953 crate::config::api_keys::resolve_api_key_env(
954 self.provider
955 .as_deref()
956 .unwrap_or(crate::config::constants::defaults::DEFAULT_PROVIDER),
957 &self.api_key_env,
958 )
959 }
960
961 pub fn codex_experimental_override(&self) -> Option<bool> {
962 if self.codex_experimental {
963 Some(true)
964 } else if self.no_codex_experimental {
965 Some(false)
966 } else {
967 None
968 }
969 }
970}
971
972#[cfg(test)]
973mod tests;