Skip to content

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.


System.CommandLineRepl equivalent
RootCommandReplApp
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)
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);
  1. Keep your handler logic as-is. If you have a method that does the real work, it doesn’t change — only the wiring does.
  2. Replace RootCommand + Command trees with app.Map(...) and app.Context(...).
    Flat commands become Map("name route", handler). Nested subcommands become Context("noun", sub => { sub.Map(...) }).
  3. Drop Argument<T> and Option<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.
  4. Add .UseDefaultInteractive(). Repl then handles Ctrl+C and SIGTERM for one-shot runs; myapp with no arguments opens the REPL with or without it. To keep a pure command-line tool, set InteractivePolicy.Prevent after the profile; see profiles. If scripts depend on a syntax that routes cannot express, keep it with an argument preprocessor.
  5. Add .UseMcpServer() when you’re ready to expose commands to AI agents.

Spectre.Console.CliRepl equivalent
CommandAppReplApp
CommandSettings with [CommandOption] / [CommandArgument][ReplOptionsGroup] class with [ReplOption]
Command<TSettings> classHandler 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
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;
}
}

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; }
}
  1. 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.
  2. Convert CommandSettings to [ReplOptionsGroup]. Swap [CommandOption] for [ReplOption] and [CommandArgument] for route segments.
  3. Wire with app.Map(...). Replace config.AddCommand<TCmd>("name") with app.Map("name route", handler). A legacy syntax that routes cannot express can be kept with an argument preprocessor.
  4. Keep your Spectre renderables. If your existing commands already use IAnsiConsole, add Repl.Spectre and call app.UseSpectreConsole(). Your widgets work unchanged — IAnsiConsole is injected and routes to the right client across concurrent sessions.

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.WebSocket or Repl.Telnet to serve the same command surface over the network to multiple concurrent clients.
  • In-process test harness — Repl.Testing runs 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.

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.0 and net11.0. A net11.0 application gets the net11.0 build. 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_COLOR is honored, ahead of NO_COLOR. With both set, output used to be plain and is now colored. See color.
  • Color no longer decides terminal control. CLICOLOR_FORCE=1 on redirected output no longer clears the screen or enables arrow-key menus there, and under AnsiMode.Always the 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.IsAnsiSupported reports terminal control, not color. It is now false on redirected output under CLICOLOR_FORCE=1; test Palette is not null to 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 IAnsiConsole fails there. Upgrade Repl.Spectre together with Repl.Core. See Detecting Spectre capability.

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, not 1. See Exit Codes & Signals.
  • A handler’s own OperationCanceledException is 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 130 or 143, and a one-shot handler’s token is disposed when the run ends. See process signals.

Output streams

Dependency injection

  • Scoped services are per session: one scope per Run* 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_command under --json). See exit codes declared by a module.
  • Parameters that Repl supplies cannot carry option metadata. Map refuses [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.Mcp requires the MCP SDK 2.x, and IMcpFeedback.SendMessageAsync takes McpMessageLevel. 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 -32002 or -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 through Results.Exit(code, payload) to the payload. See Testing.