Table of Contents

CopilotChat CLI Sample

An interactive chat CLI built on the Copilot connector, demonstrating real-world usage of CopilotSessionProvider, model selection, and the Semantic Kernel chat completion API.

Installation

dotnet tool install -g JD.Tools.CopilotChat

Usage

Interactive chat

jdcplt

Starts an interactive session with gpt-4o (default model). Type messages and receive AI responses. Type exit or quit to end the session.

Single-shot prompt

jdcplt -p "Explain the SOLID principles"

With a specific model

jdcplt -m claude-sonnet-4 -p "Write a haiku about C#"

With a system prompt

jdcplt -s "You are a senior .NET architect" -p "Review this design pattern"

List available models

jdcplt --list-models

Enterprise networks (SSL bypass)

jdcplt --insecure

Architecture

Program.cs
  → System.CommandLine CLI parser
    → CopilotSessionProvider (reads local credentials)
    → CopilotHttpClientFactory (creates auth-injecting HttpClient)
    → Kernel.CreateBuilder().AddOpenAIChatCompletion(...)
      → ChatCompletionService.GetChatMessageContentAsync()

Source

See samples/CopilotChat/Program.cs for the full implementation.