Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill when adding, modifying, or reviewing CLI commands in a .NET project built with System.CommandLine. Triggers include: creating a new CLI command, adding options or arguments, wiring command handlers, registering subcommands, building command groups, or any architecture decision about CLI command structure. Also use when the user mentions 'System.CommandLine', 'CommandBase', 'SetAction', 'ParseResult', 'RootCommand', 'subcommand', or asks to add a verb to the CLI. Do NOT use for gen
.claude/skills/github-system-commandline-cli/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 73% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 128% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 80% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 36% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 95% | 0% |
You are working on a .NET CLI application built with System.CommandLine v2.x.x, targeting .NET 8 or later or any .NET Standard 2.0 implementation, including .NET Framework 4.6.1 or later and .NET Core 2.0 or later. Follow these rules and patterns strictly when creating or modifying CLI commands.
<CLI Project>/
├── Program.cs # Entry point and command invocation
└── Commands/
├── CommandBase.cs # Base class for all commands
├── GlobalOptions.cs # Defines global options for the CLI
├── RootCommand.cs # Registers top-level commands
└── <Group>/ # One folder per command group
├── <Group>Command.cs # Parent command that registers its children
└── <Group><Verb>Command.cs # Leaf command with its handlerPrefer defining a project-specific abstract CommandBase that inherits from System.CommandLine.Command. Concrete commands should inherit from this base class so shared behavior and conventions remain centralized.
csharpinternal abstract class CommandBase : Command { protected CommandBase(string name, string? description = null) : base(name, description) { } } internal sealed class MyCommand : CommandBase { public MyCommand() : base("command-name", "Help text shown in --help") { this.SetAction(CommandHandler); } private async Task<int> CommandHandler( ParseResult parseResult, CancellationToken cancellationToken) { // implementation return 0; } }
When the project already has a command base class, preserve its established conventions. Otherwise, introduce one when commands need shared behavior; simple applications may inherit from Command directly when a base class adds no meaningful value.
csharpprivate readonly Option<string> _myOption; // In constructor: _myOption = new Option<string>("--my-option") { Description = "Clear description of what this option does", Required = true, // or false }; _myOption.Aliases.Add("-m"); // Add a short alias this.Options.Add(_myOption);
csharpprivate readonly Argument<string> _fileArgument; // In constructor: _fileArgument = new Argument<string>("file") { Description = "Path to the input file" }; this.Arguments.Add(_fileArgument);
csharp// Required option/argument — use GetValue: var value = parseResult.GetValue(_myOption);
Handlers are async methods wired via SetAction:
csharpthis.SetAction(CommandHandler); private async Task<int> CommandHandler(ParseResult parseResult, CancellationToken cancellationToken) { // 1. Read option/argument values // 2. Load session settings (if needed) // 3. Validate configuration early — fail fast with clear error // 4. Execute business logic // 5. Output results with Console return 0; // or non-zero exit code }
A group command registers children but does not call SetAction:
csharpinternal class MyGroupCommand : CommandBase { public MyGroupCommand() : base("mygroup", "Manages my-group resources") { this.Subcommands.Add(new MyGroupListCommand()); this.Subcommands.Add(new MyGroupCreateCommand()); this.Subcommands.Add(new MyGroupDeleteCommand()); } }
A command may define both an action and subcommands when the direct invocation has meaningful behavior.
RootCommand.cs:csharp this.Subcommands.Add(new MyGroupCommand());
csharp this.Subcommands.Add(new MyGroupCreateCommand());
csharpConsole.WriteLine("Are you sure you want to delete X? This action cannot be undone. (yes/no)"); var confirmation = Console.ReadLine(); if (confirmation?.ToLower() != "yes" && confirmation?.ToLower() != "y") { Console.WriteLine("Operation cancelled."); return 0; }
The logic of each command should be in one or more service classes that implement interfaces. The command receives interfaces through dependency injection (DI), not concrete implementations. The command handler should not contain business logic. The command handler should be thin, responsible only for:
Service class should be injected in the command constructor via DI, not instantiated directly.
Services are registered in Program.cs:
csharpserviceCollection.TryAddSingleton<IMyService, MyServiceImpl>();
Add a convenience extension in ServiceProviderExtensions.cs:
csharppublic static IMyService GetMyService(this ServiceProvider provider) => provider.GetRequiredService<IMyService>();
| Element | Convention | Example | |---------|-----------|---------| | CLI command name | lowercase kebab-case | agent create, set show | | Command class | PascalCase + Command suffix | AgentCreateCommand | | Option field | _camelCaseOption (private readonly) | _projectNameOption | | Option long name | --kebab-case | --project-name | | Option short alias | -x (1-2 chars) | -p, -id, -md | | Argument field | _camelCaseArgument | _fileArgument | | Namespace | MyProject.Commands.<Group> | MyProject.Commands.Agent | | Folder | Commands/<Group>/ | Commands/Agent/ |
internal.Define options shared by the entire command tree once in GlobalOptions.cs. Reuse the same Option<T> instance when registering, validating, and reading the option.
csharpinternal static class GlobalOptions { public static readonly Option<string> EndpointOption = CreateEndpointOption(); private static Option<string> CreateEndpointOption() { var option = new Option<string>(...); // add option description, aliases, and Required flag // Add validation to the option's Validators collection return option; } }
Expose repeated parsing or conversion through protected CommandBase helpers:
csharp/// <summary>Resolves the validated endpoint from the global option.</summary> protected Uri GetEndpoint(ParseResult parseResult) { var baseUrl = parseResult.GetValue(GlobalOptions.EndpointOption)!; return new Uri(baseUrl); } /// <summary>Resolves the optional key from the global option.</summary> protected string? GetKey(ParseResult parseResult) => parseResult.GetValue(GlobalOptions.KeyOption);
Consume those helpers from the leaf command's handler. The command must not add the global options to its own Options collection; recursive registration on the root already makes them available in its ParseResult.
csharpprivate async Task<int> CommandHandler( ParseResult parseResult, CancellationToken cancellationToken) { var endpoint = GetEndpoint(parseResult); var key = GetKey(parseResult); ... return 0; }
Read a global option directly in a leaf handler only when no shared conversion or fallback logic is needed. Always use the static GlobalOptions symbol; never create a second Option<T> with the same aliases.
Follow these requirements:
Recursive = true so the option is accepted for every descendant command.RootCommand.Options; do not duplicate it on leaf commands.parseResult.GetValue(GlobalOptions.Endpoint), preferably behind a CommandBase helper.
Validators collection so invalid input becomes a parse error andthe command handler is not invoked. Do not rely on exceptions from new Uri(...) or downstream services.
http or https URIs. Reject unsupported schemes,relative URIs, query strings, and fragments because appending a fixed endpoint path would change their meaning.
--key, allow omission but reject an explicitly supplied blank orwhitespace-only value. Validate the value without logging, displaying, trimming, or otherwise mutating it.
and placement before and after a representative subcommand. Verify invalid input prevents handler execution.
When creating a new command, verify:
name, description to baseDescription, Requiredthis.SetAction(CommandHandler)async Task<int> CommandHandler(ParseResult, CancellationToken)internalCommands/<Group>/ folderMyProject.CLI.Commands.<Group>| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-17 | pass→pass | 11,064 | 8,030 | -27% | 1 | 1 | 0% | 2,039 | 3,971 | +95% | 0 | 0 | — |
case-23 | pass→pass | 12,000 | 10,461 | -13% | 1 | 1 | 0% | 2,063 | 4,142 | +101% | 0 | 0 | — |
case-01 | fail→pass | 14,811 | 18,749 | +27% | 1 | 1 | 0% | 3,124 | 5,411 | +73% | 0 | 0 | — |
case-02 | fail→pass | 16,837 | 18,441 | +10% | 1 | 1 | 0% | 2,444 | 5,575 | +128% | 0 | 0 | — |
case-03 | fail→pass | 19,911 | 22,553 | +13% | 1 | 1 | 0% | 2,924 | 5,255 | +80% | 0 | 0 | — |
case-04 | pass→pass | 20,723 | 17,141 | -17% | 1 | 1 | 0% | 2,602 | 4,599 | +77% | 0 | 0 | — |
case-05 | pass→pass | 14,012 | 12,862 | -8% | 1 | 1 | 0% | 2,652 | 5,049 | +90% | 0 | 0 | — |
case-06 | pass→pass | 12,530 | 12,170 | -3% | 1 | 1 | 0% | 2,537 | 4,810 | +90% | 0 | 0 | — |
case-07 | fail→pass | 22,712 | 14,687 | -35% | 1 | 1 | 0% | 3,298 | 4,486 | +36% | 0 | 0 | — |
case-08 | fail→pass | 12,409 | 14,566 | +17% | 1 | 1 | 0% | 2,301 | 4,494 | +95% | 0 | 0 | — |
case-09 | fail→pass | 14,380 | 12,252 | -15% | 1 | 1 | 0% | 2,905 | 4,691 | +61% | 0 | 0 | — |
case-10 | fail→pass | 21,184 | 5,279 | -75% | 1 | 1 | 0% | 3,015 | 3,376 | +12% | 0 | 0 | — |
case-11 | fail→pass | 10,963 | 6,475 | -41% | 1 | 1 | 0% | 2,159 | 3,582 | +66% | 0 | 0 | — |
case-12 | pass→pass | 12,749 | 10,570 | -17% | 1 | 1 | 0% | 2,235 | 4,492 | +101% | 0 | 0 | — |
case-13 | pass→pass | 12,501 | 9,599 | -23% | 1 | 1 | 0% | 2,319 | 4,472 | +93% | 0 | 0 | — |
case-14 | fail→pass | 12,687 | 6,456 | -49% | 1 | 1 | 0% | 2,519 | 3,602 | +43% | 0 | 0 | — |
case-15 | fail→pass | 8,769 | 7,446 | -15% | 1 | 1 | 0% | 1,250 | 3,788 | +203% | 0 | 0 | — |
case-16 | fail→pass | 7,796 | 8,119 | +4% | 1 | 1 | 0% | 1,441 | 3,889 | +170% | 0 | 0 | — |
case-18 | fail→pass | 12,577 | 7,275 | -42% | 1 | 1 | 0% | 2,160 | 3,755 | +74% | 0 | 0 | — |
case-19 | pass→pass | 15,641 | 13,661 | -13% | 1 | 1 | 0% | 2,598 | 5,272 | +103% | 0 | 0 | — |
case-20 | fail→pass | 17,661 | 12,136 | -31% | 1 | 1 | 0% | 3,302 | 4,545 | +38% | 0 | 0 | — |
case-21 | fail→pass | 12,992 | 8,323 | -36% | 1 | 1 | 0% | 2,188 | 4,117 | +88% | 0 | 0 | — |
case-22 | fail→fail | 13,339 | 12,884 | -3% | 1 | 1 | 0% | 2,797 | 4,924 | +76% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +61 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.