Migrating & Upgrading
If you’ve been using System.CommandLine or Spectre.Console.Cli, you already think in the right terms — commands, arguments, options, handlers. Repl is built on the same mental model and extends it to surfaces your current tool can’t reach: an interactive REPL, MCP tools for AI agents, hosted sessions over WebSocket or Telnet, and an in-process test harness.
The migration is mostly a find-and-replace of wiring code. Your handler logic moves over untouched.
Already on Repl? Upgrading from 0.12.0 to 0.12.1 lists the behavior changes of the latest release, and Upgrading from 0.11 to 0.12 the breaking changes of 0.12.
From System.CommandLine
Section titled “From System.CommandLine”Concept mapping
Section titled “Concept mapping”| System.CommandLine | Repl equivalent |
|---|---|
RootCommand | ReplApp |
Command("name", ...) | app.Context("name", ...) or app.Map("name", ...) |
Argument<T>("name") | Route segment {name:type} — e.g. {id:int} |
Option<T>("--flag") | Named option on the handler parameter, or [ReplOptionsGroup] |
cmd.SetAction(parseResult => ...) | Lambda passed directly to Map(...) — parameters are injected |
parseResult.GetValue(option) | Handler parameter — binder resolves it automatically |
root.InvokeAsync(args) | app.Run(args) |
Side by side
Section titled “Side by side”using System.CommandLine;
var a = new Argument<int>("a", "First number");var b = new Argument<int>("b", "Second number");var cmd = new Command("add", "Sum two integers") { a, b };
cmd.SetAction(parseResult =>{ var sum = parseResult.GetValue(a) + parseResult.GetValue(b); Console.WriteLine(sum);});
var root = new RootCommand("Calculator") { cmd };return await root.InvokeAsync(args);using Repl;
var app = ReplApp.Create().UseDefaultInteractive();
app.Map("add {a:int} {b:int}", static (int a, int b) => a + b) .WithDescription("Sum two integers");
return app.Run(args);Migration steps
Section titled “Migration steps”- Keep your handler logic as-is. If you have a method that does the real work, it doesn’t change — only the wiring does.
- Replace
RootCommand+Commandtrees withapp.Map(...)andapp.Context(...).
Flat commands becomeMap("name route", handler). Nested subcommands becomeContext("noun", sub => { sub.Map(...) }). - Drop
Argument<T>andOption<T>declarations. Route segments ({name:type}) replace positional arguments. Named options are plain parameters on the handler (string? filter = null) or grouped into a[ReplOptionsGroup]class. - Add
.UseDefaultInteractive(). Repl then handles Ctrl+C andSIGTERMfor one-shot runs;myappwith no arguments opens the REPL with or without it. To keep a pure command-line tool, setInteractivePolicy.Preventafter the profile; see profiles. If scripts depend on a syntax that routes cannot express, keep it with an argument preprocessor. - Add
.UseMcpServer()when you’re ready to expose commands to AI agents.
From Spectre.Console.Cli
Section titled “From Spectre.Console.Cli”Concept mapping
Section titled “Concept mapping”| Spectre.Console.Cli | Repl equivalent |
|---|---|
CommandApp | ReplApp |
CommandSettings with [CommandOption] / [CommandArgument] | [ReplOptionsGroup] class with [ReplOption] |
Command<TSettings> class | Handler method or lambda passed to Map(...) |
Execute(CommandContext, TSettings) | Handler with injected services + options |
config.AddCommand<TCmd>("name") | app.Map("name route", handler) |
AnsiConsole (static) | IAnsiConsole injected via Repl.Spectre |
Side by side
Section titled “Side by side”using Spectre.Console;using Spectre.Console.Cli;
var app = new CommandApp();app.Configure(config => config.AddCommand<AddCommand>("add"));return app.Run(args);
public sealed class AddSettings : CommandSettings{ [CommandArgument(0, "<a>")] public int A { get; set; }
[CommandArgument(1, "<b>")] public int B { get; set; }}
public sealed class AddCommand : Command<AddSettings>{ public override int Execute(CommandContext context, AddSettings settings) { AnsiConsole.WriteLine(settings.A + settings.B); return 0; }}using Repl;
var app = ReplApp.Create().UseDefaultInteractive();
app.Map("add {a:int} {b:int}", static (int a, int b) => a + b);
return app.Run(args);Migrating Settings classes
Section titled “Migrating Settings classes”CommandSettings classes become [ReplOptionsGroup] classes. Named options map one-to-one:
public sealed class ListSettings : CommandSettings{ [CommandOption("--limit <n>")] public int Limit { get; set; } = 20;
[CommandOption("--filter <text>")] public string? Filter { get; set; }}public sealed class ListOptions{ [ReplOption(Aliases = ["--limit"])] public int Limit { get; init; } = 20;
[ReplOption(Aliases = ["--filter"])] public string? Filter { get; init; }}Migration steps
Section titled “Migration steps”- Extract the body of
Execute(...)into a plain method. The handler no longer needs to be a class — it’s a method or lambda that receives injected services and options. - Convert
CommandSettingsto[ReplOptionsGroup]. Swap[CommandOption]for[ReplOption]and[CommandArgument]for route segments. - Wire with
app.Map(...). Replaceconfig.AddCommand<TCmd>("name")withapp.Map("name route", handler). A legacy syntax that routes cannot express can be kept with an argument preprocessor. - Keep your Spectre renderables. If your existing commands already use
IAnsiConsole, addRepl.Spectreand callapp.UseSpectreConsole(). Your widgets work unchanged —IAnsiConsoleis injected and routes to the right client across concurrent sessions.
What you unlock
Section titled “What you unlock”Once your commands are wired into Repl, you get the following without extra code:
- Interactive REPL — users get tab completion, history, and command discovery when they run your app with no arguments.
- MCP server — call
.UseMcpServer()and every mapped command is immediately callable as an MCP tool by AI agents (Claude, Copilot, and others). - Hosted sessions — add
Repl.WebSocketorRepl.Telnetto serve the same command surface over the network to multiple concurrent clients. - In-process test harness —
Repl.Testingruns your full command graph in-memory: real routing, real binding, real output — no subprocess, no mocking. - Structured logging per session — every log statement emitted from a handler automatically carries session metadata (
ReplSessionId,ReplTransport, etc.) with no configuration.
Upgrading from 0.12.0 to 0.12.1
Section titled “Upgrading from 0.12.0 to 0.12.1”Repl 0.12.1 adds .NET 11 support and changes no public API. It changes observable behavior in the places below; the release notes list everything else.
.NET 11
- The packages target
net10.0andnet11.0. Anet11.0application gets thenet11.0build. See Running on .NET 11. - A handler can return a C# 15 union on
net11.0; Repl processes its active case. See Union return values.
Color and terminal control
FORCE_COLORis honored, ahead ofNO_COLOR. With both set, output used to be plain and is now colored. See color.- Color no longer decides terminal control.
CLICOLOR_FORCE=1on redirected output no longer clears the screen or enables arrow-key menus there, and underAnsiMode.Alwaysthe screen clear needs a terminal. A hosted client that advertises ANSI only through capability flags now gets the screen clear and the full-screen pager. See terminal control. ITerminalInfo.IsAnsiSupportedreports terminal control, not color. It is nowfalseon redirected output underCLICOLOR_FORCE=1; testPalette is not nullto decide on color. See adapting output to terminal capabilities.- A Spectre console colored where the terminal may not be driven is not interactive: live displays print static lines, Repl’s text prompts replace Spectre’s, and a prompt on an injected
IAnsiConsolefails there. Upgrade Repl.Spectre together with Repl.Core. See Detecting Spectre capability.
Upgrading from 0.11 to 0.12
Section titled “Upgrading from 0.11 to 0.12”Repl 0.12 changes observable behavior in the places below. Each item links to the page that explains it; the release notes list everything else.
Exit codes and signals
- Usage and binding refusals exit
2, not1. See Exit Codes & Signals. - A handler’s own
OperationCanceledExceptionis a failure (HandlerException), unless the caller asked for cancellation. See Exit Codes & Signals. - The CLI and interactive profiles own Ctrl+C and SIGTERM. An interrupted run exits
130or143, and a one-shot handler’s token is disposed when the run ends. See process signals.
Output streams
- Feedback moves to stderr for machine output. With
--json,--xml,--yamlor a redirected stdout, progress, status and prompt labels go to stderr. See feedback stays out of machine output. - Framework diagnostics go to stderr: hosted-lifecycle failures and a refused
--outputformat. See restoring the pre-policy codes. - A protocol-passthrough command’s feedback leaves the protocol stream. Write to
IReplIoContext.Outputto put text on it. See which stream receives progress.
Dependency injection
Scopedservices are per session: one scope perRun*call and per MCP connection. A singleton that injects a scoped service captures the first session’s instance. See service lifetimes.
Routing and parameters
- Refusals name the best-matching route. An invalid argument is reported against the route that matched the most words; when no route or context wins, the input is an unknown command (
unknown_commandunder--json). See exit codes declared by a module. - Parameters that Repl supplies cannot carry option metadata.
Maprefuses[ReplOption]on them, a.WithOption(...)that names one, and a route segment named like one. See parameter binding. - A required arity with a default value is refused by
Map. See parameter binding.
Prompts and hosted sessions
- Esc in a timed secret prompt, and a hosted disconnect during any prompt, throw
OperationCanceledException. See cancellation. - Cancelling a hosted session’s token ends it as a cancellation, instead of exit
0. See how a session ends. - WebSocket messages are limited to 64 KiB, and Telnet sessions end when the peer closes its input. See how a session ends.
MCP
Repl.Mcprequires the MCP SDK 2.x, andIMcpFeedback.SendMessageAsynctakesMcpMessageLevel. See protocol revisions.- An uncaught exception reaches the client as
Command failed with exit code N.; the detail goes to the operator log. See operator diagnostics. .LongRunning()no longer advertises task support. See upgrading from the 1.x SDK.- Unknown resources and prompts answer
-32002or-32602, not-32603. See protocol revisions. - A required hidden option breaks MCP discovery with one sanitized error, logged as event
2008. See hidden options.
Testing
TryGetResult<T>()reads throughResults.Exit(code, payload)to the payload. See Testing.
Where to go next
Section titled “Where to go next”- Core Basics cookbook — the canonical patterns for mapping, options, and DI.
- Modules reference — composing and reusing command sets across contexts.
- Spectre cookbook — rich output with
IAnsiConsoleand progress widgets. - MCP Concepts reference — how Repl exposes commands as MCP tools.