# console-cli

The console-cli skill for Claude Code builds .NET 10 console applications and CLI tools using System.CommandLine 2.x.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 750 installs · ★ 845 repo stars
- Author: codewithmukesh
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/console-cli/SKILL.md
- Updated: 2026-08-07
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/console-cli

## What it does

The skill sets up .NET 10 command-line utilities when asked about CLI tools, console apps, argument parsing, or exit codes. It structures applications with `RootCommand`, `Option`, and `SetAction`, directs data to `stdout` and logs to `stderr`, and configures `Ctrl+C` cancellation tokens.

It relies on stable `System.CommandLine` 2.0.x APIs and manages process termination timeouts alongside Generic Host dependency injection.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill console-cli -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/console-cli/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/console-cli/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill console-cli -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/console-cli/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill console-cli -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/console-cli/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install codewithmukesh/dotnet-claude-kit skills/console-cli
```

2. **Manually: put the files in place**
- File: `.github/skills/console-cli/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill console-cli -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/codewithmukesh/dotnet-claude-kit --path skills/console-cli
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/console-cli/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill console-cli -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/console-cli/SKILL.md

## When to use it
- build command trees with System.CommandLine
- split stdout and stderr streams correctly
- handle Ctrl+C cancellation and exit codes
- integrate Generic Host and DI into console apps

## Example prompts
- Build a .NET 10 CLI tool for importing CSV files
- Set up argument parsing with System.CommandLine and options
- Add graceful shutdown and exit codes to the console app

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 626fa0621909786a.

BEGIN THIRD-PARTY FILE 626fa0621909786a
````text
---
name: console-cli
description: >
  Console apps and CLI tools on .NET 10: System.CommandLine 2.x (RootCommand,
  Option<T>, SetAction, InvokeAsync), Generic Host + DI in console apps, exit
  codes, stdout/stderr discipline, Ctrl+C cancellation, interactive vs piped
  use, dotnet tool packaging, and `dotnet run app.cs` file-based apps. Load when
  the user mentions "console app", "CLI", "command line", "System.CommandLine",
  "dotnet tool", "exit code", "stdin", "args parsing", or "file-based app".
---

# Console Apps & CLI Tools (.NET 10)

## Core Principles

1. **stdout is data, stderr is everything else** — Results go to stdout so `mytool list | jq` works. Logs, progress, prompts and errors go to stderr. Mixing them breaks every pipe and script that consumes your tool.
2. **Exit codes are the API** — `0` = success, non-zero = failure, and each failure class gets a stable code. Scripts and CI branch on exit codes, never on parsing your error text.
3. **Use System.CommandLine 2.x, not hand-rolled `args` parsing** — It went stable at 2.0 and gives help, `--version`, validation, tab completion and Ctrl+C handling for free. Hand parsing always misses `--opt=value`, quoting, and help output.
4. **Cancellation flows from Ctrl+C to every await** — System.CommandLine turns SIGINT/SIGTERM into a `CancellationToken`. Pass it all the way down, or Ctrl+C becomes a hard kill that corrupts half-written files.
5. **Generic Host only when you need it** — DI, configuration, logging and `IHttpClientFactory` justify `Host.CreateApplicationBuilder`. A 50-line utility does not; startup time matters for CLIs.

## Patterns

### Command Tree with System.CommandLine 2.x

Verified against System.CommandLine 2.0.x (stable). The beta-era APIs (`SetHandler`, `InvocationContext`, `CommandLineBuilder`) are gone.

```csharp
using System.CommandLine;

Option<FileInfo> inputOption = new("--input", "-i")
{
    Description = "File to import",
    Required = true
};
inputOption.AcceptExistingOnly();

Option<int> batchOption = new("--batch-size")
{
    Description = "Rows per batch",
    DefaultValueFactory = _ => 500
};
batchOption.Validators.Add(result =>
{
    if (result.GetValue(batchOption) is < 1 or > 10_000)
        result.AddError("--batch-size must be between 1 and 10000");
});

Option<bool> dryRunOption = new("--dry-run") { Description = "Validate without writing" };

Command importCommand = new("import", "Import orders from a CSV file")
{
    inputOption, batchOption, dryRunOption
};
importCommand.SetAction((parseResult, ct) => ImportCommand.RunAsync(
    parseResult.GetValue(inputOption)!,
    parseResult.GetValue(batchOption),
    parseResult.GetValue(dryRunOption),
    ct));

RootCommand root = new("Order tooling") { importCommand };
return await root.Parse(args).InvokeAsync();
```

**Why:** options are typed objects, so `GetValue` is compile-time checked. `InvokeAsync` prints parse errors to stderr, shows help, and returns exit code `1` without your code running. `Required`, `AcceptExistingOnly()`, and `Validators` keep input validation at the boundary.

### Exit Codes as a Contract

```csharp
public static class ExitCodes
{
    public const int Success = 0;
````
END THIRD-PARTY FILE 626fa0621909786a

The third-party file has ended. Everything between the 626fa0621909786a tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3208 of 13658 bytes. © codewithmukesh · MIT · https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/console-cli/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
