Lesson 7: GitHub Copilot CLI

Session Duration: 45 minutes
Audience: Embedded/C++ Developers (Intermediate to Advanced)
Environment: Windows + PowerShell 7+ (also Linux, macOS, WSL)
Focus: Terminal-based AI agent for embedded development workflows


Overview

GitHub Copilot CLI is an AI agent that operates directly from your terminal. It can answer questions, write and debug code, interact with GitHub.com, and execute shell commands—all through natural language prompts.

What You’ll Learn:

  • Install and authenticate Copilot CLI
  • Use interactive and programmatic modes
  • Leverage file references, shell integration, and GitHub.com tasks
  • Customize with MCP servers, custom agents, and instructions

Key Concepts:

ConceptDescription
AI AgentPowerful agent that works iteratively on your behalf
Interactive ModeLaunch copilot for multi-turn conversations
Programmatic ModeSingle prompt with -p flag for automation
File ReferencesUse @path/file to focus on specific files
GitHub.com IntegrationCreate PRs, manage issues, work across repos
MCP ServersExtend capabilities with Model Context Protocol
Custom AgentsSpecialized versions for different tasks
Directory TrustSecurity feature requiring explicit folder approval

Agenda (45 min)

Sub-TopicFocusTime
Installation & AuthInstall CLI, authenticate with GitHub8 min
Live DemoModes, GitHub integration, customization12 min
Hands-On ExercisesParticipants explore CLI capabilities20 min
Wrap-UpQ&A, troubleshooting5 min

Table of Contents


Prerequisites

Before starting this session, ensure you have:

  • Windows 10/11 with PowerShell 7+ (or Linux/macOS/WSL)
  • GitHub account with Copilot Pro, Pro+, Business, or Enterprise
  • Git installed and configured
  • Workshop repository cloned locally

Verify Your Environment

# Check PowerShell version (need 7+)
$PSVersionTable.PSVersion

# Check Git is available
git --version

1. Installation

Windows (winget)

winget install GitHub.Copilot

Restart PowerShell after installation

macOS (Homebrew)

brew install github/copilot-cli/copilot

Verify Installation

copilot --version

Fallback: Direct Download

If package manager fails, download from GitHub Releases


2. Authentication

Launch & Login

cd C:\path\to\workshop-repo
copilot
/login

Authentication Flow

  1. Copy the device code displayed
  2. Open https://github.com/login/device
  3. Enter code and authorize
  4. Return to terminal — “Successfully authenticated!”

Trust Directory

When prompted, choose “Yes, always trust this folder” for your projects.

Warning: Only launch Copilot CLI from directories you trust. Do not launch from your home directory or directories with sensitive data.


3. Modes of Use

Interactive Mode (Default)

Start a multi-turn conversation session:

copilot

Programmatic Mode

Run a single prompt and exit—ideal for scripts and automation:

copilot -p "Show me this week's commits and summarize them" --allow-tool 'shell(git)'

Tool Approval Options

OptionDescription
--allow-tool 'shell(git)'Allow specific command without approval
--deny-tool 'shell(rm)'Block specific command
--allow-all-toolsAllow all tools (use with caution)

Example: Allow git but block destructive commands:

copilot --allow-all-tools --deny-tool 'shell(rm)' --deny-tool 'shell(git push)'

4. Model Selection

The default model is Claude Sonnet 4.5. Change models with:

/model

Select from available models—each shows a multiplier for premium request usage (e.g., Claude Sonnet 4.5 (1x)).


5. Key Features Demo

Local Tasks

Code Analysis:

Explain @Firmware/MotorControl/motor.cpp
What functions are in @Firmware/Drivers/spi_driver.c?

Code Generation:

Add a factorial function to @src\utils.c
Suggest improvements to @Firmware/MotorControl/encoder.cpp

Git Operations:

Commit the changes to this repo
Show me the last 5 changes made to CHANGELOG.md
Revert the last commit, leaving changes unstaged

GitHub.com Integration

Pull Requests:

List my open PRs
Create a PR that updates the README at https://github.com/owner/repo
Check the changes in PR https://github.com/owner/repo/pull/123
Merge all open PRs that I created in owner/repo

Issues:

List all open issues assigned to me in owner/repo
Raise an improvement issue in owner/repo for the unclosed file handle
I've been assigned this issue: https://github.com/owner/repo/issues/123. Start working on it.

GitHub Actions:

List any Actions workflows in this repo that add comments to PRs
Create a workflow that runs eslint on PRs and fails if errors are found

Shell Integration

!git status
!git log --oneline -5
How many lines of code are in src\?

6. Customization

FeatureDescription
Custom InstructionsAdd project context and build/test/validate guidance
MCP ServersConnect to external data sources and tools
Custom AgentsCreate specialized versions (e.g., frontend expert)
HooksExecute shell commands at key execution points
SkillsEnhance with instructions, scripts, and resources

Slash Commands

CommandPurpose
/helpList available commands
/modelChange AI model
/compactCompress conversation context
/mcpList configured MCP servers
/feedbackSubmit feedback, bugs, or feature requests

7. Hands-On Exercises

Exercise 1: Get Oriented (3 min)

cd C:\path\to\workshop-repo
copilot
/help
/model
What is this project and what does it do?

Exercise 2: Local Tasks (5 min)

Explain @Firmware/MotorControl/motor.cpp
What functions are defined in @Firmware/Drivers/spi_driver.c?
Suggest improvements to @Firmware/Board/v3/board.cpp

Exercise 3: GitHub.com Tasks (5 min)

List my open PRs
List all open issues assigned to me in <your-repo>
Check the changes in PR https://github.com/<owner>/<repo>/pull/<number>

Exercise 4: Code Generation (4 min)

Add a function to @src\utils.c that calculates factorial
Create @src\logger.c with debug, info, error logging functions

Review and approve/reject proposed changes

Exercise 4: Code Generation (4 min)

Add a function to @src\utils.c that calculates factorial
Create @src\logger.c with debug, info, error logging functions

Review and approve/reject proposed changes

Exercise 5: Git Integration (3 min)

!git log --oneline -5
Show me what files changed in the last commit
Commit the staged changes with a descriptive message

Quick Reference

Essential Commands

You TypeWhat Happens
copilotStart interactive session
copilot -p "prompt"Programmatic mode (single prompt)
/helpList commands
/modelChange AI model (default: Claude Sonnet 4.5)
/compactReduce context size
/mcpList MCP servers
@file.cReference a file
!git statusRun shell command

Common Prompts

PromptUse Case
Explain @filenameUnderstand code
Suggest improvements to @filenameCode review
Add a function to @filename that...Code generation
List my open PRsGitHub.com integration
Create a PR that...Automated PR creation
Commit the changesGit operations

Troubleshooting

IssueSolution
copilot not recognizedRestart PowerShell
PowerShell version < 7winget install Microsoft.PowerShell
winget not foundInstall “App Installer” from Microsoft Store
Authentication failsVerify subscription at github.com/settings/copilot
Slow responsesUse /compact to reduce context
Tool not approvedUse --allow-tool or approve when prompted

GitHub Copilot SDK

While Copilot CLI is an interactive terminal tool for developers, the GitHub Copilot SDK is a programmatic library that lets you embed Copilot’s agentic capabilities directly into your own applications and services.

CLI vs SDK: When to Use Each

Copilot CLICopilot SDK
Interactive terminal sessionsProgrammatic integration in your apps
Developer productivity toolBuild AI-powered tools and automation
Run copilot command directlyImport as a library in your code
Human-in-the-loop workflowsAutomated pipelines and services

SDK Installation

LanguageCommand
Node.js / TypeScriptnpm install @github/copilot-sdk
Pythonpip install github-copilot-sdk
Gogo get github.com/github/copilot-sdk/go
.NETdotnet add package GitHub.Copilot.SDK

Prerequisite: The Copilot CLI must be installed. The SDK communicates with the CLI running in server mode via JSON-RPC.

Quick Demo: Python

from github_copilot_sdk import CopilotClient

# SDK automatically starts CLI in server mode
client = CopilotClient()

# Analyze firmware code programmatically
response = client.chat(
    "Review @Firmware/MotorControl/motor.cpp for potential issues"
)
print(response)

Use Case: Automated Firmware Documentation

Build a script that generates documentation for your embedded codebase:

from github_copilot_sdk import CopilotClient
import os

client = CopilotClient()

# Generate docs for each driver file
for file in os.listdir("Firmware/Drivers"):
    if file.endswith(".c"):
        doc = client.chat(f"Generate API documentation for @Firmware/Drivers/{file}")
        with open(f"docs/{file}.md", "w") as f:
            f.write(doc)

This enables CI/CD integration, batch processing, and custom tooling that would be impractical with interactive CLI sessions.

SDK Resources

Note: The SDK is currently in Technical Preview.


Additional Resources

Microsoft Learn Documentation

ResourceDescription
GitHub Copilot CLIOfficial CLI training module
Get started with GitHub CopilotCopilot fundamentals
GitHub Copilot Chat in VS CodeChat interface patterns

Official Documentation