Skip to main content

Chapter 10: GitHub Copilot CLI

Part IV: Developer Tooling & Workflows Prerequisites: Chapter 5: Copilot Policies & Content Controls, Chapter 9: GitHub CLI (gh) for Enterprise GH-100 Exam Mapping: Beyond GH-100 — Enterprise Copilot mastery Verified: 2026-02-01 against official documentation

1. Introduction​

Learning Objectives​

After completing this chapter, you will be able to:

  • Install and configure the GitHub Copilot CLI across Windows, macOS, and Linux enterprise environments
  • Use the legacy gh copilot suggest and gh copilot explain commands and understand their deprecation status
  • Leverage the new agentic Copilot CLI for multi-step planning, file modification, and command execution
  • Configure model selection, trusted directories, and MCP (Model Context Protocol) server integrations
  • Apply enterprise authentication and policy controls to govern Copilot CLI usage across an organization
  • Integrate Copilot CLI into CI/CD (Continuous Integration/Continuous Delivery) pipelines and automation scripts

Exam Domain Coverage​

DomainTopics in This Chapter
Beyond GH-100Copilot CLI installation, legacy vs. agentic CLI, model selection, enterprise authentication, policy controls, MCP server integration, CI/CD usage

Chapter Overview​

The GitHub Copilot CLI brings the power of AI-assisted development directly into the terminal. Unlike IDE-based Copilot features that assist with code completion and chat inside an editor, the Copilot CLI operates where many enterprise developers spend a significant portion of their day: the command line. From generating complex shell commands to executing multi-step workflows that modify files, run tests, and interact with APIs, the Copilot CLI transforms the terminal from a passive command executor into an intelligent development partner.

The evolution of Copilot in the terminal has been significant. The original gh copilot extension, introduced as a GitHub CLI extension (see Chapter 9: GitHub CLI (gh) for Enterprise), offered two focused capabilities: suggesting shell commands from natural language descriptions and explaining unfamiliar commands. In October 2025, GitHub deprecated this extension and replaced it with the new standalone Copilot CLI -- a fully agentic assistant that can read and modify files, execute shell commands, create multi-step plans, and connect to external tools through the Model Context Protocol. This represents a fundamental shift from a suggestion tool to an autonomous agent that operates within your terminal.

For enterprise organizations, the Copilot CLI introduces both opportunities and governance challenges. It inherits your organization's existing Copilot policies (see Chapter 5: Copilot Policies & Content Controls), respects content exclusions, and operates under the same subscription model as other Copilot features. Enterprise administrators must understand how to enable the CLI policy, manage model access, configure trusted directories for security, and integrate the tool into standardized developer workflows. This chapter covers the complete lifecycle of the Copilot CLI from installation through advanced enterprise usage, equipping you to deploy it as a governed, productivity-enhancing tool across your development teams.


2. Theory & Deep Dive​

2.1 The Legacy gh copilot Extension​

Before the current Copilot CLI, GitHub offered an extension to the GitHub CLI called gh-copilot. This extension added two subcommands to the gh tool that brought AI assistance to the terminal. Understanding these legacy commands is important because existing documentation, internal scripts, and developer habits in many organizations still reference them.

gh copilot suggest​

The gh copilot suggest command accepted a natural language description and returned a suggested shell command. It supported three command types:

  • generic shell command -- general-purpose commands for any shell environment
  • gh command -- commands using the GitHub CLI
  • git command -- Git version control operations
# Legacy command: suggest a shell command from natural language (bash)
gh copilot suggest "find all Python files modified in the last 7 days"

The command presented an interactive prompt where the user selected the command type, reviewed the suggestion, and chose to copy, execute, or revise it. Critically, it never executed commands automatically -- the user always had final approval.

gh copilot explain​

The gh copilot explain command took a shell command as input and returned a plain-language explanation of what the command does:

# Legacy command: explain a complex shell command (bash)
gh copilot explain "find . -name '*.log' -mtime +30 -exec rm {} \;"

This was particularly valuable for onboarding developers who encountered unfamiliar commands in scripts, CI/CD pipelines, or runbooks.

Deprecation Notice​

GitHub officially deprecated the gh copilot extension on October 25, 2025. The extension remains installable but receives no further updates. Enterprise teams should plan migration to the new Copilot CLI, which subsumes and extends all legacy functionality.

Enterprise Scenario: A financial services company with 250 developers has internal documentation referencing gh copilot suggest in their onboarding guides and runbook templates. Their platform engineering team creates a migration plan: they update all documentation to reference the new copilot command, add shell aliases (alias ghcs='copilot') for developers who have muscle memory with the old syntax, and schedule the gh copilot extension removal from their managed workstation images over a 90-day transition period.

2.2 The New Agentic Copilot CLI​

The new GitHub Copilot CLI is a standalone tool invoked with the copilot command. It represents a fundamental architectural shift from the legacy extension. Rather than suggesting a single command for the user to evaluate and execute, the new CLI operates as a fully autonomous agent that can plan multi-step workflows, modify files, execute commands, and iterate on errors -- all within the terminal.

Key Capabilities​

CapabilityLegacy gh copilotNew copilot CLI
Command suggestionYes (interactive prompt)Yes (inline, with execution)
Command explanationYes (explain subcommand)Yes (natural language)
File readingNoYes
File modificationNoYes (with trust approval)
Multi-step planningNoYes
Shell command executionNo (user must copy/run)Yes (with confirmation)
MCP server integrationNoYes
Model selectionNo (fixed model)Yes (multiple models)
Session persistenceNoYes (conversation context)
Auto-compactionNoYes (at 95% token limit)

Interactive Session​

The Copilot CLI runs as an interactive session. When you launch it, you enter a conversational interface where you can type natural language prompts, receive responses, and iterate:

# Start the Copilot CLI (bash)
copilot
# Start the Copilot CLI (PowerShell)
copilot

On first launch in a directory, the CLI asks whether you trust the files in the current folder. This trust model is a security mechanism that prevents the agent from modifying files without explicit consent.

Trust Model Options​

When Copilot CLI starts in a new directory, it presents three options:

  1. Yes, proceed -- trust files in this directory for the current session only
  2. Yes, and remember this folder for future sessions -- permanently trust this directory
  3. No, exit (Esc) -- end the session without granting access

If the agent needs to modify files in a directory outside the current trusted location during a session, it requests approval before proceeding.

Slash Commands​

Slash commands are special directives prefixed with / that control session behavior. They are processed locally and do not consume premium request quota or tokens:

CommandPurpose
/modelSwitch between available AI models
/loginAuthenticate with GitHub
/usageView premium request usage, session duration, and token breakdown
/cwdChange the current working directory
/add-dirAdd a directory to the trusted directories list
/mcp addAdd an MCP server for extended capabilities
/mcp showDisplay all configured MCP servers
/compactManually compress conversation history
/helpDisplay available slash commands
/clearClear the current conversation

All slash commands support TAB autocomplete and display argument hints in the input box.

Enterprise Scenario: A healthcare technology company with 300 developers creates an onboarding script that pre-configures trusted directories for each developer. The script adds the company's standard project directories (e.g., ~/repos/corp-*) to the trusted list and pre-configures the MCP server connection to their internal documentation API. New developers start their first copilot session with full access to organizational context without manual setup.

2.3 Installing the Copilot CLI​

The Copilot CLI is distributed through multiple package managers and as a direct download. Enterprise teams should standardize on a single installation method per platform.

Prerequisites​

Before installing, ensure the following requirements are met:

  • An active GitHub Copilot subscription (Copilot Pro, Copilot Pro+, Copilot Business, or Copilot Enterprise)
  • Node.js version 22 or later
  • npm version 10 or later
  • PowerShell version 6 or higher (Windows only)
  • The Copilot CLI policy must be enabled in your organization's settings (see Section 2.6)

Installation via npm (All Platforms)​

The npm installation method works across all platforms and is the most commonly documented approach:

# Install Copilot CLI globally via npm (bash)
npm install -g @github/copilot
# Install Copilot CLI globally via npm (PowerShell)
npm install -g @github/copilot

After installation, verify the installation:

# Verify the copilot command is available (bash)
copilot --version

Installation via Homebrew (macOS and Linux)​

# Install Copilot CLI using Homebrew (bash)
brew install github/copilot-cli/copilot

Installation via winget (Windows)​

# Install Copilot CLI using winget (PowerShell)
winget install GitHub.CopilotCLI

Installation via Install Script (macOS and Linux)​

GitHub provides an install script for environments where npm or Homebrew are not available:

# Install using the official install script (bash)
curl -fsSL https://cli.github.com/copilot/install.sh | sh

Enterprise Version Management​

For organizations that require version pinning, the npm installation method supports pinning to a specific version:

# Install a specific version (bash)
npm install -g @github/copilot@0.0.395

Enterprise IT teams can host the npm package on an internal registry (such as Artifactory or Nexus) and distribute it through configuration management tools. This ensures all developers run an approved and security-scanned version.

Enterprise Scenario: A defense contractor with 200 developers operates in an air-gapped environment. Their platform team downloads the @github/copilot npm package, runs it through their security scanning pipeline, publishes it to an internal Verdaccio registry, and configures developer workstations to use the internal registry. Developers install with npm install -g @github/copilot --registry https://npm.internal.corp.com and receive updates only after security review.

2.4 Authentication and Enterprise Configuration​

Authentication for the Copilot CLI integrates with your existing GitHub credentials and Copilot subscription.

Interactive Authentication​

On first launch, if you are not authenticated, the CLI prompts you to log in:

# Start copilot -- it will prompt for authentication if needed (bash)
copilot

Within the interactive session, use the /login slash command to authenticate:

/login

This initiates a device flow authentication similar to the GitHub CLI. A one-time code is displayed, and a browser window opens for you to authorize the application.

Token-Based Authentication (CI/CD and Automation)​

For non-interactive environments such as CI/CD pipelines, set the GH_TOKEN or GITHUB_TOKEN environment variable with a Personal Access Token (PAT) that has the Copilot Requests permission:

# Authenticate via environment variable (bash)
export GH_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
copilot --prompt "Explain the Dockerfile in this directory"
# Authenticate via environment variable (PowerShell)
$env:GH_TOKEN = "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
copilot --prompt "Explain the Dockerfile in this directory"

The token precedence order is:

  1. GH_TOKEN environment variable (highest priority)
  2. GITHUB_TOKEN environment variable
  3. Stored credentials from interactive login

Fine-Grained PAT Configuration​

For enterprise use, create a fine-grained PAT with the minimum required permissions:

  1. Navigate to Settings > Developer settings > Fine-grained personal access tokens
  2. Click Generate new token
  3. Under Permissions, add Copilot Requests (required for CLI interactions)
  4. Set the token expiration according to your organization's security policy
  5. Save the token and configure it in your environment

Enterprise Scenario: A consulting firm with 150 developers working across multiple client organizations creates dedicated fine-grained PATs for each client engagement. Each token is scoped to the specific organization and stored in HashiCorp Vault. Their CI/CD pipelines retrieve the appropriate token at runtime based on the repository's organization, ensuring proper isolation and audit trails across engagements.

2.5 Model Selection and Configuration​

The Copilot CLI supports multiple Large Language Models (LLMs) from different providers, giving teams flexibility to choose the best model for their workflow.

Default Model​

The Copilot CLI uses Claude Sonnet 4.5 (by Anthropic) as the default model. This model provides a strong balance of reasoning capability, code generation quality, and response speed for terminal-based workflows.

Switching Models​

Use the /model slash command within an interactive session to view and select available models:

/model

This displays all available models. Current options include:

ModelProviderBest For
Claude Sonnet 4.5 (default)AnthropicGeneral-purpose coding, multi-step tasks
Claude Sonnet 4AnthropicFaster responses, lighter tasks
GPT-4oOpenAIBroad knowledge, documentation tasks
GPT-5OpenAIAdvanced reasoning, complex architecture

You can also specify the model at launch:

# Start copilot with a specific model (bash)
copilot --model "claude-sonnet-4"
# Start copilot with a specific model (PowerShell)
copilot --model "claude-sonnet-4"

Model Selection Priority Order​

The model used by the CLI follows this priority (highest to lowest):

  1. Command-line flag: copilot --model "claude-sonnet-4"
  2. Environment variable: GITHUB_COPILOT_MODEL
  3. User configuration file: ~/.copilot/config
  4. System default: Claude Sonnet 4.5

Persistent Model Configuration​

To set a default model that persists across sessions, update the configuration file:

# Set a persistent default model (bash)
# Edit ~/.copilot/config and add:
# model: gpt-4o

On Windows, the configuration directory is located at %USERPROFILE%\.copilot\config.

Enterprise Model Governance​

Enterprise administrators can control which models are available to their organization through Copilot policies (see Chapter 5: Copilot Policies & Content Controls). If a developer selects a model that has been disabled by policy, the CLI prompts them to choose an enabled alternative. This allows organizations to restrict usage to approved models that meet their data residency, compliance, or cost requirements.

Enterprise Scenario: A European financial institution with 400 developers restricts Copilot to models that process data within their compliance boundary. The enterprise administrator disables specific models at the enterprise policy level. When a developer runs /model in the CLI, only the approved models appear. The platform team distributes a standard ~/.copilot/config file during onboarding that sets the organization's preferred model as the default.

2.6 Enterprise Policy Controls​

The Copilot CLI respects the same policy hierarchy that governs all GitHub Copilot features. Enterprise administrators control access through a two-level policy system.

Policy Hierarchy​

  1. Enterprise level: The enterprise owner sets the policy to Enabled, Disabled, or Unconfigured (delegates to organization)
  2. Organization level: If the enterprise delegates the decision, the organization owner enables or disables the CLI for their organization

As of November 2025, if an enterprise policy is set to Unconfigured, the corresponding organization policy defaults to Disabled rather than allowing organizations to enable it independently. This ensures that new features remain restricted unless the enterprise administrator explicitly enables or delegates the policy.

Enabling the Copilot CLI for Your Organization​

To enable the Copilot CLI:

  1. Navigate to your organization's settings on GitHub
  2. In the left sidebar, click Copilot and then Policies
  3. Locate the Copilot CLI policy (listed under Copilot agents or preview features)
  4. Set the policy to Enabled

If the toggle is grayed out, the enterprise administrator has set the policy at the enterprise level. Contact your enterprise owner to change it.

Policy Inheritance​

The Copilot CLI automatically inherits all organization-level Copilot governance settings, including:

  • Content exclusions: Files and repositories excluded from Copilot context
  • IP indemnity settings: Code suggestion filtering policies
  • Telemetry and data collection: Prompt and suggestion logging preferences
  • Model restrictions: Which models are available for use

This means that enterprise administrators do not need to create separate policies for the CLI -- existing Copilot policies apply uniformly across IDE, web, and CLI surfaces.

Premium Request Quotas​

Each prompt submitted to the Copilot CLI counts as one premium request against your plan's monthly quota. The quota varies by plan:

PlanPremium Requests per Month
Copilot Pro300
Copilot Pro+1,500
Copilot Business300 per seat
Copilot Enterprise1,000 per seat

Use the /usage slash command within a session to monitor consumption:

/usage

This displays the number of premium requests used, session duration, lines of code edited, and a token usage breakdown per model.

Enterprise Scenario: A retail technology company with 500 Copilot Business seats monitors premium request consumption through their FinOps dashboard. They notice that their platform engineering team (50 developers) consistently exceeds their quota due to heavy CLI usage in automation scripts. The enterprise administrator upgrades the platform team to Copilot Enterprise seats (1,000 requests per month) while keeping the remaining developers on Business seats, optimizing cost without restricting productivity.

2.7 MCP Server Integration​

The Model Context Protocol (MCP) is an open standard that allows AI tools to connect to external data sources and services. The Copilot CLI supports MCP servers, enabling it to access internal datasets, knowledge bases, and domain-specific tools.

Built-in MCP Server​

The Copilot CLI ships with GitHub's MCP server enabled by default. This server provides access to:

  • Repository information and metadata
  • GitHub Issues and Pull Requests
  • GitHub Actions workflow data
  • Copilot Spaces for project-specific context

Adding Custom MCP Servers​

Within an interactive session, use the /mcp add slash command to connect to additional MCP servers:

/mcp add my-internal-api

The CLI prompts for:

  1. Server Type: Local (stdio) or Remote (HTTP)
  2. Command: The command to start the server (for local servers)
  3. Environment Variables: Any required environment variables
  4. Tools: Which tools from the server to enable (* for all)

MCP Configuration File​

MCP server configurations are stored in ~/.copilot/mcp-config.json (or %USERPROFILE%\.copilot\mcp-config.json on Windows). You can edit this file directly to add servers:

{
"mcpServers": {
"internal-docs": {
"type": "local",
"command": "node",
"args": ["/path/to/internal-docs-mcp-server/index.js"],
"env": {
"DOCS_API_KEY": "${DOCS_API_KEY}"
},
"tools": "*"
}
}
}

Use /mcp show to display all configured servers, including default and custom servers.

Enterprise Scenario: A logistics company with 200 developers builds a custom MCP server that exposes their internal API documentation, database schemas, and infrastructure inventory. When a developer asks the Copilot CLI "How do I connect to the shipping-events Kafka topic?", the agent queries the internal MCP server for the relevant connection configuration, authentication method, and code examples specific to the company's infrastructure. This eliminates the need to search through internal wikis and Confluence pages.

2.8 Using Copilot CLI in CI/CD Pipelines​

The Copilot CLI can be integrated into CI/CD pipelines for automated code review, documentation generation, and workflow assistance. However, enterprise teams should approach this carefully due to premium request quotas and the nondeterministic nature of LLM outputs.

Non-Interactive Mode​

For CI/CD usage, the Copilot CLI supports a --prompt flag that runs a single prompt and exits:

# Run a single prompt non-interactively (bash)
copilot --prompt "Review the Dockerfile in this directory for security issues"

GitHub Actions Integration​

# .github/workflows/copilot-review.yml
name: Copilot CLI Code Review
on:
pull_request:
types: [opened, synchronize]

jobs:
review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- name: Install Copilot CLI
run: npm install -g @github/copilot

- name: Run Copilot analysis
env:
GH_TOKEN: ${{ secrets.COPILOT_PAT }}
run: |
# Generate a summary of changes in this PR
DIFF=$(gh pr diff ${{ github.event.pull_request.number }} --name-only)
copilot --prompt "Summarize the following file changes: $DIFF"

Security Considerations for Pipeline Usage​

  1. Token scoping: Use a dedicated fine-grained PAT with only the Copilot Requests permission. Do not reuse GITHUB_TOKEN for Copilot CLI interactions in pipelines.
  2. Quota management: Each pipeline run consumes a premium request. For high-volume repositories, consider running Copilot analysis only on specific triggers (e.g., PRs targeting main, PRs with the needs-review label).
  3. Output variability: LLM responses are nondeterministic. Do not use Copilot CLI output as a blocking gate in your pipeline. Use it for advisory purposes only.
  4. Trusted directories: In CI/CD environments, the working directory should be explicitly trusted. Set the COPILOT_TRUST_DIRS environment variable or pre-configure trust in the runner image.

2.9 Comparison: Legacy gh copilot vs. New Copilot CLI​

Understanding the architectural differences between the two tools helps enterprise teams plan their migration strategy.

Interaction Model​

The legacy gh copilot extension followed a suggest-and-confirm model: it proposed a single command, the user reviewed it, and then decided whether to execute it. The new Copilot CLI follows an agent-and-execute model: it creates a plan, requests confirmation for each step, executes commands, observes results, and iterates until the task is complete.

Security Model​

The legacy extension had minimal security concerns because it never executed commands directly. The new CLI introduces a more sophisticated security model:

  • Directory trust: The agent cannot access files in untrusted directories
  • Command confirmation: Each shell command requires user approval before execution
  • URL access control: The ~/.copilot/config file supports allowed_urls and denied_urls patterns that control what URLs the agent can fetch
  • Auto-compaction: When approaching 95% of the token limit, the CLI automatically compresses conversation history to prevent context overflow

Migration Checklist​

For enterprise teams migrating from gh copilot to the new copilot CLI:

  • Verify Node.js 22+ is available on all developer workstations
  • Update organization Copilot policies to enable the CLI feature
  • Install @github/copilot via the approved package management method
  • Update internal documentation to reference copilot instead of gh copilot
  • Configure trusted directories for standard project locations
  • Set up MCP servers for internal knowledge bases (optional)
  • Remove the legacy gh-copilot extension from managed workstation images
  • Train developers on the new slash commands and agentic workflow

3. Diagrams​

Copilot CLI Architecture and Request Flow​

flowchart TD
A[Developer Terminal] --> B{copilot command}
B -->|First launch| C[Trust Prompt]
C -->|Yes, proceed| D[Interactive Session]
C -->|Yes, remember| E[Persist Trust + Session]
C -->|No, exit| F[Session Ends]

D --> G{User Input}
E --> G

G -->|Slash command| H[Local Handler]
H -->|/model| I[Model Selector]
H -->|/mcp add| J[MCP Configuration]
H -->|/login| K[Auth Flow]
H -->|/usage| L[Quota Display]

G -->|Natural language prompt| M[Prompt Router]
M --> N[Context Assembly]
N -->|Local files| O[Trusted Directory Files]
N -->|MCP data| P[MCP Servers]
N -->|Session history| Q[Conversation Context]

N --> R[Selected LLM]
R -->|Default| S[Claude Sonnet 4.5]
R -->|User choice| T[GPT-4o / GPT-5 / Claude Sonnet 4]

R --> U[Agent Response]
U -->|Text explanation| V[Display to User]
U -->|File modification| W{Trust Check}
W -->|Trusted dir| X[Apply Changes]
W -->|Untrusted dir| Y[Request Approval]
U -->|Shell command| Z{User Confirmation}
Z -->|Approved| AA[Execute Command]
Z -->|Denied| AB[Skip Step]

AA --> AC[Observe Output]
AC --> M

style A fill:#e1f5fe
style R fill:#fff3e0
style S fill:#c8e6c9
style T fill:#c8e6c9
style W fill:#ffecb3
style Z fill:#ffecb3

Figure 10.1: Copilot CLI architecture showing the request flow from terminal input through context assembly, LLM processing, and agent action execution. Slash commands are handled locally without consuming premium requests, while natural language prompts route through the selected AI model. File modifications and shell commands require trust verification and user confirmation respectively.

Enterprise Policy and Authentication Flow​

flowchart LR
subgraph Enterprise["Enterprise Level"]
A1[Enterprise Owner] --> A2{Copilot CLI Policy}
A2 -->|Enabled| A3[All Orgs Can Use]
A2 -->|Disabled| A4[Blocked for All Orgs]
A2 -->|Unconfigured| A5[Defaults to Disabled]
end

subgraph Org["Organization Level"]
B1[Org Admin] --> B2{CLI Policy Toggle}
B2 -->|Enabled| B3[Available to Members]
B2 -->|Disabled| B4[Blocked for Members]
end

subgraph Auth["Authentication"]
C1[Developer Workstation]
C1 -->|Interactive| C2[/login → Device Flow]
C1 -->|CI/CD| C3[GH_TOKEN / GITHUB_TOKEN]
C1 -->|Fine-grained PAT| C4[Copilot Requests Permission]
end

subgraph Models["Model Access"]
D1[Available Models]
D1 --> D2[Claude Sonnet 4.5]
D1 --> D3[Claude Sonnet 4]
D1 --> D4[GPT-4o]
D1 --> D5[GPT-5]
end

A3 --> B2
B3 --> C1
C2 --> D1
C3 --> D1
C4 --> D1

style Enterprise fill:#e3f2fd
style Org fill:#fce4ec
style Auth fill:#f3e5f5
style Models fill:#e8f5e9

Figure 10.2: Enterprise policy hierarchy for the Copilot CLI showing how enterprise-level policies flow down to organizations, how developers authenticate through different methods, and how model access is governed by policy controls. When the enterprise policy is set to "Unconfigured," it defaults to "Disabled" at the organization level.

Legacy vs. Agentic CLI Comparison​

flowchart TB
subgraph Legacy["Legacy: gh copilot (Deprecated Oct 2025)"]
L1[User types natural language] --> L2[gh copilot suggest]
L2 --> L3[Single command suggestion]
L3 --> L4{User decision}
L4 -->|Copy| L5[User pastes and runs]
L4 -->|Revise| L2
L4 -->|Cancel| L6[Done]

L7[User provides command] --> L8[gh copilot explain]
L8 --> L9[Plain-text explanation]
end

subgraph Agentic["New: copilot CLI (Current)"]
N1[User types natural language] --> N2[Agent creates plan]
N2 --> N3[Step 1: Read files]
N3 --> N4[Step 2: Modify code]
N4 --> N5[Step 3: Run tests]
N5 --> N6{Tests pass?}
N6 -->|Yes| N7[Step 4: Commit changes]
N6 -->|No| N8[Iterate and fix]
N8 --> N4
N7 --> N9[Task complete]
end

style Legacy fill:#fff3e0
style Agentic fill:#e8f5e9

Figure 10.3: Comparison of the legacy suggest-and-confirm interaction model with the new agentic plan-and-execute model. The legacy CLI required the user to manually execute each suggestion, while the new CLI autonomously plans, executes, and iterates on multi-step tasks with user confirmation at each step.


4. Summary​

Key Takeaways:

  • The GitHub Copilot CLI has evolved from a simple command suggestion tool (gh copilot suggest and gh copilot explain) into a fully agentic terminal assistant that can plan multi-step workflows, read and modify files, execute commands, and iterate on errors autonomously.
  • The legacy gh copilot extension was deprecated in October 2025. Enterprise teams should migrate to the new standalone copilot CLI, which is installed via npm (@github/copilot), Homebrew, or winget, and requires Node.js 22 or later.
  • Model selection is a key enterprise governance concern. The CLI defaults to Claude Sonnet 4.5 but supports multiple models from Anthropic and OpenAI. Enterprise administrators control model availability through Copilot policies, and developers can switch models using the /model slash command or persistent configuration.
  • The Copilot CLI inherits all existing Copilot enterprise policies, including content exclusions, model restrictions, and data handling preferences. The two-level policy hierarchy (enterprise then organization) ensures centralized governance, with the November 2025 policy update defaulting "Unconfigured" enterprise policies to "Disabled" at the organization level.
  • MCP server integration extends the CLI beyond GitHub into organization-specific knowledge bases, internal APIs, and custom tooling. Enterprise teams can build and distribute custom MCP servers to give developers instant access to institutional knowledge directly from the terminal.

What's Next: See Chapter 11: IDE Integration for how GitHub Copilot enhances the development experience inside code editors, including code completion, inline chat, and agent mode in Visual Studio Code and JetBrains IDEs.


5. Hands-On Assignment​

Prerequisites Check: Before starting this lab, ensure you have completed:

  • Copilot policies configured at enterprise/org level (Chapter 5: Copilot Policies & Content Controls)
  • GitHub CLI installed and authenticated (Chapter 9: GitHub CLI (gh) for Enterprise)
  • An active Copilot license assigned to your user account (Chapter 4: Copilot Licensing & Plan Management)

Lab: Enterprise Copilot CLI Setup and Multi-Step Workflow​

Objective: Install the Copilot CLI, configure enterprise authentication and model selection, execute both legacy-style and agentic workflows, and integrate an MCP server for extended capabilities.

Prerequisites:

  • A GitHub account with an active Copilot Business or Enterprise subscription
  • Organization admin access to enable the Copilot CLI policy (or an organization where it is already enabled)
  • Node.js version 22 or later installed on your workstation
  • npm version 10 or later
  • A test repository in your organization with at least one source code file
  • The GitHub CLI (gh) installed and authenticated (see Chapter 9: GitHub CLI (gh) for Enterprise)

Assignment:

  1. Install the Copilot CLI on your workstation using the appropriate method for your operating system. Verify the installation produces a valid version number.
  2. Launch the Copilot CLI in your test repository directory. When prompted, trust the directory for the current session. Verify authentication by running the /usage slash command.
  3. Use the Copilot CLI to explain a complex command. Type a natural language prompt asking it to explain an existing script or command in your repository.
  4. Use the Copilot CLI to perform a multi-step task: ask it to add a .editorconfig file to your repository with enterprise-standard settings (e.g., 4-space indentation, UTF-8 encoding, LF line endings). Observe how it creates a plan, generates the file, and confirms the changes.
  5. Switch the model to a different option using the /model slash command. Ask the same question with the new model and compare the responses.
  6. Check your premium request usage with the /usage slash command. Note how many requests were consumed by your session.

Expected Outcome: You should have a working Copilot CLI installation authenticated to your enterprise organization, a new .editorconfig file generated by the agent, and an understanding of how model selection affects responses and quota consumption.

Validation:

  • copilot --version returns a valid version number
  • The Copilot CLI starts successfully and accepts the directory trust prompt
  • /usage shows your current premium request consumption
  • The .editorconfig file exists in your repository with the requested settings
  • /model displays available models and allows switching

6. Step-by-Step Walkthrough​

This section provides a guided solution for the hands-on assignment above. If you completed the assignment independently, you can skip this section or use it to verify your approach.

Step 1: Install the Copilot CLI​

On Windows (PowerShell):

# Verify Node.js version (must be 22+)
node --version

# Install Copilot CLI globally via npm
npm install -g @github/copilot

# Verify installation
copilot --version

On macOS (bash):

# Verify Node.js version (must be 22+)
node --version

# Install Copilot CLI via Homebrew
brew install github/copilot-cli/copilot

# Alternatively, install via npm
npm install -g @github/copilot

# Verify installation
copilot --version

On Linux/Ubuntu (bash):

# Verify Node.js version (must be 22+)
node --version

# Install Copilot CLI via npm
npm install -g @github/copilot

# Verify installation
copilot --version

Expected output (version number will vary):

GitHub Copilot CLI v0.0.395

If node --version returns a version below 22, install or update Node.js first:

# Install Node.js 22 using nvm (bash)
nvm install 22
nvm use 22
# Install Node.js 22 using winget (PowerShell)
winget install OpenJS.NodeJS.LTS

Step 2: Launch the Copilot CLI and Verify Authentication​

Navigate to your test repository directory:

# Navigate to your test repository (bash)
cd ~/repos/my-test-repo
# Navigate to your test repository (PowerShell)
cd C:\repos\my-test-repo

Launch the Copilot CLI:

# Start the Copilot CLI (bash)
copilot
# Start the Copilot CLI (PowerShell)
copilot

When the trust prompt appears, select Yes, proceed for this session.

If you are not authenticated, the CLI displays a message prompting you to log in. Type:

/login

Follow the device flow authentication:

  1. A one-time code is displayed in the terminal
  2. A browser window opens (or a URL is displayed for you to navigate to)
  3. Enter the code and authorize the application

Once authenticated, verify your session:

/usage

Expected output:

Session usage:
Premium requests used: 0
Session duration: 0m 30s
Lines of code edited: 0
Model: Claude Sonnet 4.5

Step 3: Explain a Complex Command​

In the Copilot CLI session, type a natural language prompt to explain a command. For example:

Explain what this command does: find . -name "*.test.js" -not -path "*/node_modules/*" -exec grep -l "describe.skip" {} \;

Expected output (responses will vary due to LLM nondeterminism):

This command searches for JavaScript test files while excluding the
node_modules directory, then finds which of those files contain skipped
test suites.

Breaking it down:
1. `find .` — starts searching from the current directory
2. `-name "*.test.js"` — matches files ending in .test.js
3. `-not -path "*/node_modules/*"` — excludes the node_modules directory
4. `-exec grep -l "describe.skip" {} \;` — for each matching file,
runs grep to check if it contains "describe.skip" and prints the
filename if found

This is useful for finding test files where test suites have been
temporarily skipped, which could indicate technical debt.

Step 4: Perform a Multi-Step Agentic Task​

Ask the Copilot CLI to create an .editorconfig file:

Create an .editorconfig file for this repository with enterprise standards: UTF-8 encoding, LF line endings, 4-space indentation for all files, 2-space indentation for YAML and JSON files, trim trailing whitespace, and ensure a final newline.

The agent will:

  1. Plan the task -- it may check if an .editorconfig already exists
  2. Generate the file content with the specified settings
  3. Request confirmation before writing the file
  4. Write the file to disk

When the agent proposes creating the file, it will ask for your confirmation. Approve the file creation.

Expected file content (the agent should produce something similar to):

# .editorconfig
# Enterprise standard editor configuration

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yml,yaml}]
indent_size = 2

[*.json]
indent_size = 2

[Makefile]
indent_style = tab

Verify the file was created:

# Verify the file exists (in a separate terminal, bash)
cat .editorconfig
# Verify the file exists (in a separate terminal, PowerShell)
Get-Content .editorconfig

Step 5: Switch Models and Compare Responses​

In the Copilot CLI session, switch to a different model:

/model

A list of available models is displayed. Select a different model (e.g., GPT-4o).

Now ask a question to compare responses:

What are the best practices for organizing a monorepo with 50+ microservices?

Observe how the response differs from what Claude Sonnet 4.5 would have produced. Different models may emphasize different aspects (tooling recommendations, directory structure, build system choices, etc.).

To switch back to the default model:

/model

Select Claude Sonnet 4.5.

Step 6: Check Premium Request Usage​

/usage

Expected output (values will vary):

Session usage:
Premium requests used: 4
Session duration: 12m 15s
Lines of code edited: 18
Model breakdown:
Claude Sonnet 4.5: 3 requests (2,847 tokens)
GPT-4o: 1 request (1,203 tokens)

To exit the Copilot CLI session:

/exit

Or press Ctrl+C.

Verification​

Run the following commands to confirm all lab objectives are met:

# 1. Verify Copilot CLI is installed
copilot --version

# 2. Verify the .editorconfig file was created
cat .editorconfig

# 3. Verify the file contains the expected settings
grep "indent_size = 4" .editorconfig
grep "end_of_line = lf" .editorconfig
grep "charset = utf-8" .editorconfig
# 1. Verify Copilot CLI is installed (PowerShell)
copilot --version

# 2. Verify the .editorconfig file was created
Get-Content .editorconfig

# 3. Verify the file contains the expected settings
Select-String -Path .editorconfig -Pattern "indent_size = 4"
Select-String -Path .editorconfig -Pattern "end_of_line = lf"
Select-String -Path .editorconfig -Pattern "charset = utf-8"

7. Q&A -- Chapter Review​

Instructions: Select the best answer for each question. Answers and explanations follow after all questions.

Question 1​

What command installs the new GitHub Copilot CLI globally via npm?

  • A) npm install -g gh-copilot
  • B) npm install -g @github/copilot
  • C) npm install -g github-copilot-cli
  • D) npm install -g copilot

Question 2​

The legacy gh copilot extension was officially deprecated in favor of the new Copilot CLI. When was it deprecated?

  • A) June 2025
  • B) August 2025
  • C) October 2025
  • D) January 2026

Question 3​

Which slash command in the Copilot CLI allows you to switch between available AI models during an interactive session?

  • A) /switch-model
  • B) /model
  • C) /set-model
  • D) /ai-model

Question 4​

What is the default AI model used by the GitHub Copilot CLI?

  • A) GPT-4o
  • B) GPT-5
  • C) Claude Sonnet 4
  • D) Claude Sonnet 4.5

Question 5​

An enterprise administrator sets the Copilot CLI policy to "Unconfigured" at the enterprise level. What is the default behavior at the organization level?

  • A) Organizations can independently enable or disable the CLI
  • B) The CLI is enabled by default for all organizations
  • C) The CLI defaults to disabled at the organization level
  • D) Organizations must contact GitHub support to enable it

Question 6​

A DevOps engineer wants to use the Copilot CLI in a CI/CD pipeline. Which environment variable should they set for authentication?

  • A) COPILOT_API_KEY
  • B) GH_TOKEN
  • C) COPILOT_AUTH_TOKEN
  • D) GITHUB_COPILOT_KEY

Question 7​

The Copilot CLI uses a directory trust model for security. What happens when the agent needs to modify a file in a directory that has not been trusted?

  • A) The modification is silently blocked and logged
  • B) The agent requests approval before accessing the untrusted directory
  • C) The CLI terminates the session immediately
  • D) The file is modified but marked as "unverified"

Question 8​

Which of the following is a capability of the new agentic Copilot CLI that was NOT available in the legacy gh copilot extension?

  • A) Suggesting a shell command from natural language
  • B) Explaining what a command does
  • C) Reading and modifying files as part of a multi-step plan
  • D) Displaying help text for CLI options

Question 9​

An organization wants to extend the Copilot CLI with access to their internal API documentation. Which technology enables this integration?

  • A) GitHub Actions webhooks
  • B) OAuth2 application registration
  • C) Model Context Protocol (MCP) servers
  • D) GitHub App installation tokens

Question 10​

Each prompt submitted to the Copilot CLI counts against the user's monthly quota. Which slash command displays the current premium request consumption within a session?

  • A) /quota
  • B) /billing
  • C) /usage
  • D) /stats

Answer Key​

QAnswerExplanation
1BThe GitHub Copilot CLI is published as the @github/copilot package on npm. Installing it globally with npm install -g @github/copilot makes the copilot command available system-wide.
2CGitHub officially deprecated the gh copilot extension on October 25, 2025, replacing it with the new standalone Copilot CLI that provides agentic capabilities.
3BThe /model slash command displays available models and allows the user to select a different one for the current session. It is processed locally and does not consume premium requests.
4DThe Copilot CLI defaults to Claude Sonnet 4.5 by Anthropic. Users can change this via the /model slash command, command-line flags, environment variables, or the user configuration file.
5CAs of the November 2025 policy update, when an enterprise policy is set to "Unconfigured," the corresponding organization-level policy defaults to "Disabled." This prevents organizations from enabling features that the enterprise administrator has not explicitly approved.
6BThe Copilot CLI reads the GH_TOKEN environment variable (with GITHUB_TOKEN as a fallback) for authentication in non-interactive environments. The PAT must include the "Copilot Requests" permission.
7BThe Copilot CLI's trust model requires explicit approval before the agent can access files in directories that have not been previously trusted. The agent pauses and requests the user's consent.
8CThe legacy gh copilot extension only suggested or explained commands. The new agentic Copilot CLI can read files, modify code, execute shell commands, and perform multi-step tasks with iterative error correction.
9CModel Context Protocol (MCP) servers allow the Copilot CLI to connect to external data sources and services. Organizations can build custom MCP servers to expose internal APIs, documentation, and knowledge bases.
10CThe /usage slash command displays premium requests consumed, session duration, lines of code edited, and a token usage breakdown per model within the current session.