DEV Community

Cover image for Leveraging GitHub Copilot CLI for Developer Productivity
markring
markring

Posted on • Originally published at ringworks.io

Leveraging GitHub Copilot CLI for Developer Productivity

A practical guide to agentic coding, custom agents, and workflow automation from the terminal

Table of Contents

Introduction

GitHub Copilot CLI brings agentic coding directly to your terminal. It reached general availability in early 2026 and is available to all paid Copilot subscribers.

This isn't the old gh copilot suggest extension. Copilot CLI is a standalone tool that can read your codebase, edit files, run commands, create pull requests, and delegate work to specialized agents - all from an interactive terminal session.

This guide covers:

  • How to install, authenticate, and configure Copilot CLI
  • The slash command system that controls sessions, models, and tools
  • Plan mode vs. autopilot mode and when to use each
  • Creating custom agents for repeatable workflows
  • Connecting MCP servers for external tool integration
  • How your existing .github/copilot-instructions.md and AGENTS.md files carry over

If you've already set up project-level Copilot instructions (see the companion post on configuring Copilot for C# projects), Copilot CLI picks those up automatically.

2. Installation and Setup

2.1 Installation options

Copilot CLI can be installed via multiple package managers:

npm (all platforms):

npm install -g @github/copilot
Enter fullscreen mode Exit fullscreen mode

Homebrew (macOS/Linux):

brew install github/copilot-cli/copilot
Enter fullscreen mode Exit fullscreen mode

WinGet (Windows):

winget install GitHub.CopilotCLI
Enter fullscreen mode Exit fullscreen mode

Via GitHub CLI:

If you already have gh installed, you can run gh copilot to install and launch Copilot CLI directly.

Prerequisites:

  • Node.js 22 or later
  • An active GitHub Copilot subscription (Individual, Business, or Enterprise)

2.2 Authentication

On first launch, Copilot CLI prompts you to authenticate:

copilot
Enter fullscreen mode Exit fullscreen mode

Inside the interactive session, use /login and follow the device flow in your browser. Alternatively, set a fine-grained personal access token with the "Copilot Requests" permission:

export GH_TOKEN=your_token_here
copilot
Enter fullscreen mode Exit fullscreen mode

2.3 First run

Navigate to a project directory and launch:

cd ~/projects/my-api
copilot
Enter fullscreen mode Exit fullscreen mode

Copilot CLI automatically detects your project structure, reads any instruction files, and starts an interactive session. Type a natural language prompt or a slash command to get started.

3. Interactive Mode and Slash Commands

Slash commands are directives prefixed with / that control session state, model selection, permissions, and integrations. They don't invoke the AI model - they configure it.

Type /help to see all available commands, or / and press Tab for autocomplete.

3.1 Session management

Command What it does
/clear Reset conversation history (use when switching tasks)
/compact Compress history to free up context window
/session Show session ID, duration, and code changes
/usage Display API usage metrics
/rename NAME Rename the current session
/resume SESSION-ID Switch to a different session
/share file PATH Export session to a markdown file
/share gist Export session to a GitHub gist
/exit End the session

3.2 Directory and file access

Command What it does
/cwd PATH Change working directory
/add-dir PATH Grant access to an additional directory
/list-dirs Show all directories Copilot can access

By default, Copilot CLI has access to the directory you launched from. Use /add-dir to grant access to related directories (e.g., a shared library repo) without restarting your session.

3.3 Model selection

Command What it does
/model List available models and select one
/model MODEL Switch directly to a specific model

Available models include GPT-5 mini, GPT-4.1, Claude Sonnet, Claude Opus, and Gemini 3 Pro. GPT-5 mini and GPT-4.1 are included with your subscription and don't consume premium requests.

3.4 Permissions and tools

Command What it does
/allow-all Enable all permissions (tools, paths, URLs)
/reset-allowed-tools Reset tool permissions to defaults

Copilot CLI asks for confirmation before making file changes or running commands. For trusted workflows, /allow-all (also aliased as /yolo) skips all confirmation prompts.

3.5 External integrations

Command What it does
/mcp show List configured MCP servers and status
/mcp add Add a new MCP server interactively
/agent Browse and select from available agents
/delegate PROMPT Create a pull request from a natural language prompt
/ide Connect to a VS Code workspace

4. Operational Modes: Plan and Autopilot

Copilot CLI has two distinct modes for how it handles work.

4.1 Plan mode

Activate with /plan followed by your prompt:

/plan Add pagination to the GET /api/orders endpoint
Enter fullscreen mode Exit fullscreen mode

In plan mode, Copilot:

  1. Analyzes your request and asks clarifying questions
  2. Reads relevant files in your codebase
  3. Produces a step-by-step implementation plan
  4. Waits for your approval before making any changes

This is the right mode when you want oversight. Use it for architectural changes, unfamiliar codebases, or anything touching authentication/authorization.

4.2 Autopilot mode

For hands-off execution, use the --yolo flag at launch or /allow-all in an active session. In autopilot, Copilot:

  1. Reads your prompt
  2. Executes tools, edits files, and runs commands autonomously
  3. Iterates on failures without stopping for approval

Use autopilot for well-understood tasks: scaffolding boilerplate, running and fixing tests, formatting/refactoring, or generating migration files.

4.3 Choosing the right mode

Scenario Mode
New feature in unfamiliar code Plan
Refactoring a well-tested module Autopilot
Security-sensitive changes Plan
Scaffolding a new controller/service Autopilot
Debugging a failing test Either - start with plan, switch to autopilot once you understand the issue

5. Custom Agents

Custom agents let you define specialized roles with specific expertise, tool access, and instructions.

5.1 Agent profile structure

Agents are defined as .agent.md files with YAML frontmatter:

---
name: api-scaffolder
description: Scaffolds new API endpoints following Clean Architecture conventions
tools:
  - read
  - edit
  - search
  - bash
---

## Instructions

You are an API scaffolding assistant for a .NET 8 Clean Architecture project.

When asked to create a new endpoint:

1. Create the command/query record in Application/Features/{Entity}/
2. Create the handler in the same directory
3. Create the FluentValidation validator
4. Add the controller action in API/Controllers/{Entity}Controller.cs
5. Create the DTO in Application/DTOs/

Follow these conventions:
- Use MediatR for all commands and queries
- Async all the way - every method returns Task
- Use CancellationToken in all async signatures
- Return ActionResult<T> from controller actions
Enter fullscreen mode Exit fullscreen mode

5.2 Where to place agent profiles

Agent profiles can live in several locations:

Location Scope
.github/agents/ Repository-level, shared with team
~/.copilot/agents/ Personal, applies across all projects
Any directory in COPILOT_CUSTOM_INSTRUCTIONS_DIRS Custom paths

5.3 Tool access control

By default, custom agents have access to all tools. You can restrict this:

---
name: code-reviewer
description: Reviews code changes for quality and security issues
tools:
  - read
  - search
---
Enter fullscreen mode Exit fullscreen mode

This agent can read and search but can't edit files or run commands - appropriate for a review-only role.

5.4 Using agents

In an interactive session:

/agent
Enter fullscreen mode Exit fullscreen mode

Select from the list of available agents, or reference one directly in your prompt. You can also create new agents interactively with /agent and selecting "Create new agent."

5.5 Built-in agents

Copilot CLI ships with specialized agents that activate automatically when appropriate:

  • Explore - Fast codebase analysis and navigation
  • Task - Runs commands like tests and builds
  • Code-review - Reviews changes with high signal-to-noise ratio, surfacing only genuine issues

6. MCP Server Integration

Model Context Protocol (MCP) servers extend Copilot CLI with external tools and data sources.

6.1 Adding an MCP server

Interactively:

/mcp add
Enter fullscreen mode Exit fullscreen mode

Follow the prompts to configure the server type (STDIO or HTTP/SSE), command, and arguments.

Or edit the configuration file directly at ~/.copilot/mcp-config.json:

{
  "servers": {
    "github": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

6.2 Managing MCP servers

Command What it does
/mcp show List servers and their status
/mcp edit SERVER Edit a server's configuration
/mcp disable SERVER Temporarily disable a server
/mcp enable SERVER Re-enable a disabled server
/mcp delete SERVER Remove a server

6.3 Useful MCP servers

  • GitHub MCP Server - Access to issues, pull requests, repositories, and Copilot Spaces
  • Azure MCP Server - Query Azure resources and configurations
  • Database servers - Query databases directly from Copilot CLI
  • Custom internal servers - Connect to your organization's internal tools and APIs

6.4 Agent profiles with MCP servers

You can embed MCP server configuration directly in an agent profile:

---
name: db-analyst
description: Analyzes database schema and query performance
tools:
  - read
  - search
mcp-server:
  type: stdio
  command: npx
  args: ["-y", "@modelcontextprotocol/server-postgres"]
---

## Instructions

You are a database analyst. When asked about schema or query performance,
use the PostgreSQL MCP server to inspect tables, indexes, and query plans.
Enter fullscreen mode Exit fullscreen mode

7. Connecting to Your Project Configuration

Copilot CLI automatically reads project-level configuration files. If you've already set these up for VS Code Copilot, they work in the CLI with zero additional setup.

7.1 Supported instruction files

File How Copilot CLI uses it
.github/copilot-instructions.md Global project rules, always loaded
.github/instructions/*.instructions.md Scoped rules, activated by file path glob
AGENTS.md (root) Project-wide agent instructions
AGENTS.md (nested) Directory-specific agent instructions
~/.copilot/copilot-instructions.md Personal global instructions

7.2 The instruction loading order

When you launch Copilot CLI in a project directory, it loads:

  1. Personal instructions from ~/.copilot/copilot-instructions.md
  2. Project global instructions from .github/copilot-instructions.md
  3. AGENTS.md from the root and any nested directories
  4. Scoped .instructions.md files matching the current context

These layer together - scoped instructions add specificity on top of global rules.

7.3 Custom instruction directories

For monorepos or projects that span multiple directories, set the COPILOT_CUSTOM_INSTRUCTIONS_DIRS environment variable:

export COPILOT_CUSTOM_INSTRUCTIONS_DIRS="/path/to/shared-config,/path/to/team-standards"
Enter fullscreen mode Exit fullscreen mode

Copilot CLI looks for AGENTS.md and .github/instructions/**/*.instructions.md in each of these directories.

7.4 Initializing configuration

If your project doesn't have instruction files yet, Copilot CLI can generate them:

/init
Enter fullscreen mode Exit fullscreen mode

This creates starter AGENTS.md and instruction files based on your project structure. Review and refine them - the generated defaults are a starting point, not a final answer.

8. Practical Workflows

8.1 Scaffold a new feature

/plan Create a new CustomerNotifications feature with:
- A SendNotificationCommand with email and SMS channels
- A FluentValidation validator
- An EF Core configuration for the Notification entity
- Unit tests for the handler
Enter fullscreen mode Exit fullscreen mode

Review the plan, approve it, and Copilot creates all the files following your project's conventions (pulled from your instruction files).

8.2 Fix a failing CI build

The CI build is failing on the AddOrder_InvalidInput_ReturnsValidationError test.
Read the test, the handler, and the validator. Find the mismatch and fix it.
Enter fullscreen mode Exit fullscreen mode

8.3 Review changes before a PR

/review Review the changes in this branch for security issues,
missing null checks, and async anti-patterns
Enter fullscreen mode Exit fullscreen mode

Or use the built-in diff viewer:

/diff
Enter fullscreen mode Exit fullscreen mode

8.4 Delegate a PR

/delegate Add XML documentation comments to all public methods
in the OrdersController and OrderService classes
Enter fullscreen mode Exit fullscreen mode

This creates a pull request with the changes without modifying your local working tree.

8.5 Parallel subagent work with /fleet

For tasks that can be split across independent workstreams:

/fleet Across the Application layer, ensure every command handler
has a corresponding FluentValidation validator. Create any that are missing.
Enter fullscreen mode Exit fullscreen mode

Copilot spawns multiple subagents working in parallel and converges on a single result.

8.6 Explore an unfamiliar codebase

Explain the authentication flow in this project. Start from the middleware
and trace through to the token validation and claims mapping.
Enter fullscreen mode Exit fullscreen mode

The built-in Explore agent handles codebase navigation efficiently, reading only the files it needs.

Conclusion

Copilot CLI changes how you interact with AI-assisted development. Instead of switching between your terminal and an editor for AI help, the terminal becomes the AI environment.

The key capabilities:

  • Plan mode for oversight on complex or sensitive changes
  • Autopilot mode for trusted, repetitive tasks
  • Custom agents for codifying your team's workflows into reusable roles
  • MCP servers for connecting external tools and data
  • Project configuration that carries over from VS Code with zero duplication

The most effective setup is layered: global instructions define your standards, scoped instructions handle layer-specific rules, custom agents encode repeatable workflows, and MCP servers connect external systems. Each layer makes Copilot CLI more precise and more useful.

If you haven't already, start with your project's instruction files. Everything else builds on that foundation.

Top comments (0)