DEV Community

Cover image for GitHub Copilot CLI Slash Commands Every .NET Developer Should Know
Vikrant Bagal
Vikrant Bagal

Posted on

GitHub Copilot CLI Slash Commands Every .NET Developer Should Know

What if you could generate C# unit tests, refactor your .NET code, and manage your GitHub repo — all without leaving your terminal?

GitHub Copilot CLI brings AI-powered development directly to your command line. You probably already know Copilot from your IDE, but the CLI version offers something different: full natural‑language control over your terminal context. You get an interactive, session-aware assistant that live in your shell, understands file contents, and runs commands.

As a .NET developer, this means you can ask Copilot CLI to scaffold an ASP.NET Core React project, explain a Program.cs file, or debug an Entity Framework migration — and it sees the same values you see. No copy‑pasting. No context‑switching.

This guide walks you through the most useful Copilot CLI slash commands that will genuinely change how you work, especially if you are in the .NET ecosystem. Let me start with the basics.

Getting Started: Installing and Authenticating Copilot CLI

First, install the official GitHub Copilot CLI extension for GitHub CLI. If you already have gh installed, this is a single command:

gh extension install github/copilot-cli
Enter fullscreen mode Exit fullscreen mode

Then authenticate. Ensure you have an active GitHub Copilot subscription (Individual, Business, or Enterprise). Run:

gh copilot auth-status
Enter fullscreen mode Exit fullscreen mode

If not authenticated, sign in:

gh auth login
Enter fullscreen mode Exit fullscreen mode

Now launch the interactive Copilot CLI session:

gh copilot
Enter fullscreen mode Exit fullscreen mode

You will enter a REPL-style interface where you type natural language prompts and Copilot CLI responds with code, commands, or analysis — and can execute commands in the middle of a session. This is where the real power begins, specifically through slash commands — the hidden gem that transforms this from a chatbot into a programmable AI terminal.

/model: Switch AI Models On the Fly

One of the first commands you should learn is /model. It lets you change the underlying AI model during a session. This matters because different models handle different tasks better — GPT-4o might excel at complex C# refactoring, while Claude Sonnet might be faster for boilerplate generation.

Inside the copilot prompt:
/model
Enter fullscreen mode Exit fullscreen mode

This displays the current model and lets you switch. To set it directly:

/model gpt-4o
/model claude-sonnet
/model gemini-2.5-flash-preview
Enter fullscreen mode Exit fullscreen mode

This flexibility is huge for .NET developers. You can test your EF Core model generation or ASP.NET Minimal API setup against different models without changing any IDE settings. Just type /model, pick one, and continue your session.

/delegate: Let AI Agent Handle Your Repetitive .NET Tasks

The /delegate command is Copilot CLI's most powerful time-saver. It offloads tasks to a cloud‑hosted AI agent that works asynchronously — meaning you continue coding while Copilot CLI works in the background.

/delegate Write xUnit tests for OrderService.cs covering edge cases
Enter fullscreen mode Exit fullscreen mode
/delegate Refactor the CustomerController to use minimal APIs
Enter fullscreen mode Exit fullscreen mode
/delegate Run dotnet build, analyze warnings, and suggest fixes
Enter fullscreen mode Exit fullscreen mode

The agent runs in a sandboxed environment with your repo context, completes the task, and returns results. This is particularly useful for .NET workloads:

  • Generating test projects with realistic test data and mocking frameworks (Moq, NSubstitute)
  • Scaffolding new ASP.NET Core projects from scratch or from existing models
  • Investigating NuGet package compatibility during version upgrades
  • Running dotnet CLI commands: dotnet build, dotnet Ef migrations add, dotnet publish etc. — without leaving Copilot CLI

Return on investment: Instead of manually switching context, writing the test yourself, and then debugging, you describe intent in natural language and review the output when ready.

/context and /compact: Control Token Usage in Large .NET Solutions

Large .NET solutions with dozens of projects generate massive context. Every token costs money and slows responses. The /context and /compact commands let you manage this explicitly:

/context
Enter fullscreen mode Exit fullscreen mode

This shows current context usage, file count, and approximate tokens consumed. Essential before asking Copilot CLI to analyze a 50‑project solution.

When context gets too large, use /compact:

/compact
Enter fullscreen mode Exit fullscreen mode

Copilot CLI summarizes the conversation history, reducing token pressure — like minimizing a window but keeping the important state. For .NET developers working with monolithic repositories or large dotnet new‑generated microservice templates, this keeps responsiveness high and costs predictable. You can also explicitly exclude folders:

/compact --exclude "**/bin", "**/obj", "**/node_modules"
Enter fullscreen mode Exit fullscreen mode

This prevents build artifacts and dependencies from polluting the context window during Copilot CLI sessions.

/allow-all and /deny-Tool: Manage Permissions Safely

By default, Copilot CLI asks for confirmation before executing any shell command. For .NET developers running dotnet build, migrations, or publish operations, this can cause permission fatigue. Slash commands let you configure trusted tools:

/allow-all
Enter fullscreen mode Exit fullscreen mode

Gives blanket permission. Risky in production repos but fine locally — Copilot CLI moves faster, executing dotnet build and dotnet run without prompting you each time. To be more surgical:

/deny-tool dotnet-ef
/deny-tool docker
Enter fullscreen mode Exit fullscreen mode

Useful when you trust dotnet build but want manual control over database migrations or container commands. Narrow permissions keep you safe while automating the tasks you trust.


The Bottom Line

As a .NET developer, you spend a lot of time in the terminal. GitHub Copilot CLI slash commands — /model, /delegate, /compact, /allow‑all — let you keep that flow.

Start small: open gh copilot today and try /model to switch models on a single task. Then experiment with /delegate for your next refactoring repetition. Once you feel the compound effect on daily .NET tasks, you will rarely go back to manually typing every command yourself.

Top comments (0)