← Tech Guides
Complete Reference Guide

GitHub Copilot CLI

The AI coding agent in your terminal. Master interactive sessions, model selection, permissions, MCP integration, and automation workflows.

Cheat Sheet

Essential Commands

  • copilot Start interactive session
  • copilot -p "..." Single-shot prompt
  • copilot --continue Resume last session
  • copilot --resume Browse sessions
  • copilot login Authenticate
  • copilot update Update to latest
/

Slash Commands

  • /help Show commands
  • /model Switch model
  • /compact Compress context
  • /clear Reset context
  • /review Review code changes
  • /delegate Send to coding agent
  • /share gist Export as Gist

Keyboard Shortcuts

  • Tab Autocomplete paths
  • Shift+Tab Toggle plan mode
  • Ctrl+T Toggle reasoning
  • Ctrl+C Cancel current
🔒

Permissions

  • --yolo All permissions
  • --allow-all-tools Auto-approve tools
  • --allow-all-paths All file access
  • --allow-tool "..." Specific tool (glob)
  • --deny-tool "..." Block tool (precedence)
🤖

Top Models

  • claude-opus-4.6 Deep reasoning
  • claude-sonnet-4.5 Balanced default
  • gpt-5.2-codex Code generation
  • gpt-5-mini Fast & free*
  • gemini-3-pro-preview Data & analytics
🔌

MCP & Context

  • --enable-all-github-mcp-tools GitHub tools
  • --add-dir [path] Add directory
  • --additional-mcp-config Custom MCP
  • /add-dir Add dir in session

Getting Started

Installation

Install GitHub Copilot CLI via npm:

npm install -g @github/copilot

Alternatively, install as a GitHub CLI extension:

gh extension install github/gh-copilot
gh copilot

Authentication

Authenticate with your GitHub account:

copilot login

Non-Interactive / CI Authentication

For automated environments, use a Personal Access Token with the "Copilot Requests" permission:

# Set token as environment variable
export GH_TOKEN=your_token_here
# or
export GITHUB_TOKEN=your_token_here

# For credential managers
export GITHUB_ASKPASS=/path/to/executable/that/returns/token
ℹ️
Enterprise Authentication

Non-interactive workflows respect the GH_HOST environment variable for GitHub Enterprise Server authentication.

Initial Setup

copilot init           # Initialize configuration
copilot version        # Check installed version
copilot update         # Update to latest version
copilot help           # View available commands

Interactive Mode

Starting a Session

copilot                # Start interactive session (default)
copilot --continue     # Resume most recent session
copilot --resume       # Browse and resume sessions

Slash Commands

Type / during an interactive session to see all available commands. Here is the full reference:

Session Management

/help Display command help and descriptions
/clear Reset conversation context
/exit End session cleanly
/session Show session metrics (duration, changes)
/usage Display token usage statistics
/resume ID Resume a specific session by ID
/compact Manually compress context

Directory & File Access

/cwd Display or change working directory
/cd Change directory (tab completion)
/add-dir Grant access to a directory
/list-dirs Show directory permissions

Code, Models & Agents

/model Switch AI model mid-session
/review Analyze staged/unstaged changes
/delegate Push to Copilot coding agent (opens draft PR)
/agent NAME Invoke a custom agent

Sharing

/share Export session to markdown
/share gist Create GitHub Gist (prompts for visibility)
/feedback Submit product feedback

Keyboard Shortcuts

Shortcut Action
TabAutocomplete paths in /cwd and /add-dir
Shift+TabToggle plan mode (collaborative planning before implementation)
Ctrl+TToggle model reasoning visibility (supported models)
Ctrl+CCancel current operation

Plan Mode

Press Shift+Tab to enter plan mode. Copilot will analyze your request, ask clarifying questions, and build a structured implementation plan before writing any code. This is ideal for major refactors or complex features.

New in 2026

"Plan before you build, steer as you go." Plan mode enables collaborative planning with step-by-step approval before any code changes are made.

Non-Interactive Mode

Use the -p (or --prompt) flag for single-shot execution, perfect for scripting and CI/CD pipelines.

Basic Usage

copilot -p "your prompt here"
copilot --prompt "your prompt here"

Examples

# Find information
copilot -p "List all open issues assigned to me in OWNER/REPO"

# Code generation
copilot -p "Generate unit tests for main.js"

# Code analysis
copilot -p "Find all TODO comments in src/ directory"

Piping & Chaining

# Pipe input to Copilot
echo "Explain this code" | copilot -p

# Chain with other tools
copilot -p "Run tests" --allow-all-tools

# Export results to file
copilot -p "Analyze code quality" --share > report.md

CI/CD Integration

# Automated quality check in pipeline
copilot -p "Run full test suite and generate coverage report" \
  --allow-all-tools \
  --share-gist \
  --model gpt-5-mini
⚠️
Automation Tip

Always use --allow-all-tools or specific --allow-tool patterns in automated contexts to bypass interactive approval prompts.

Model Selection

Choose the right model for your task. Switch at launch with --model or mid-session with /model.

Available Models

Claude (Anthropic)

claude-opus-4.6

Premium

Deep reasoning, complex system design, architecture decisions, greenfield projects.

Best for: Complex refactors, system architecture, design work

claude-sonnet-4.5

Default

Balanced speed and capability. Great general-purpose development model.

Best for: Everyday coding, routine tasks, balanced performance

claude-haiku-4.5

Light

Lightweight Claude variant for quick, simple tasks.

Best for: Quick lookups, simple edits, fast responses

GPT (OpenAI)

gpt-5.2-codex

Premium

Latest high-performance code generation model.

Best for: High-volume code generation

gpt-5.1-codex-max

Premium

Maximum capability codex variant for demanding workloads.

Best for: Complex generation, maximum accuracy

gpt-5-mini

Free*

Fast and lightweight. Does not consume premium requests on paid plans.

Best for: Quick iterations, high-volume simple tasks

gpt-4.1

Free*

Reliable GPT-4.1. Does not consume premium requests.

Best for: Cost-conscious standard work

Other available models: gpt-5.2, gpt-5.1-codex, gpt-5.1, gpt-5, gpt-5.1-codex-mini

Google

gemini-3-pro-preview

Preview

Data transformation, analytics, and multimodal tasks.

Best for: Data-heavy workflows, analytics, multimodal input

Model Selection Strategy

💡
Recommended Approach

Start with claude-sonnet-4.5 for balanced performance. Switch to claude-opus-4.6 for architecture decisions. Use gpt-5-mini for high-volume simple tasks. Try gemini-3-pro-preview for data-heavy work. Use /model to switch mid-session as task complexity changes.

Permission System

Copilot CLI uses a layered permission system. By default, each tool execution requires interactive approval. Use flags to grant broader access.

Tool Permissions

# Allow specific tools (glob patterns supported)
--allow-tool "shell(npm run test:*)"
--allow-tool "read"

# Deny specific tools (takes precedence over allow)
--deny-tool "shell"
--deny-tool "write(*.env)"

# Auto-approve all tool executions
--allow-all-tools

Path Permissions

# Allow access to all file paths
--allow-all-paths

# Grant directory access in session
/add-dir /path/to/directory

URL Permissions

# Allow specific URL patterns
--allow-url "https://api.example.com/*"

# Deny URL patterns
--deny-url "https://internal.corp/*"
⚠️
URL rules apply to shell commands too

URL permission rules also affect commands like curl and wget executed through the shell tool.

Convenience Flags

Flag Effect
--allow-allEnable all permissions at once
--yoloSame as --allow-all (trust Copilot to run freely)
--allow-all-toolsAuto-approve all tool executions
--allow-all-pathsAllow access to any file path
--allow-all-urlsAllow all URL access

Permission Examples

# Secure code review (read-only, no shell)
copilot -p "Review security in auth module" \
  --allow-tool "read" \
  --deny-tool "shell" \
  --allow-all-paths

# Enterprise-safe automation (specific tools only)
copilot -p "Deploy to staging" \
  --allow-tool "shell(kubectl *)" \
  --allow-tool "shell(docker *)" \
  --deny-url "*" \
  --config-dir /etc/copilot

# Fast prototyping (full trust)
copilot --yolo --model claude-opus-4.6

MCP Integration

Model Context Protocol (MCP) is an industry-standard protocol that allows Copilot CLI to integrate with custom context providers and external tools.

Configuration

MCP servers are configured in ~/.copilot/mcp-config.json:

{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "my-mcp-server"],
      "env": {
        "API_KEY": "your-key"
      }
    }
  }
}

GitHub MCP Server

The built-in GitHub MCP server provides tools for issues, PRs, repositories, and Copilot Spaces:

# Enable all GitHub MCP tools
copilot --enable-all-github-mcp-tools

# Add a specific tool
copilot --add-github-mcp-tool github_search_code

# Add a toolset (e.g., all issue-related tools)
copilot --add-github-mcp-toolset issues

MCP Flags Reference

Flag Description
--additional-mcp-config [path]Load additional MCP config file
--add-github-mcp-tool [tool]Add specific GitHub MCP tool
--add-github-mcp-toolset [set]Add GitHub MCP toolset
--enable-all-github-mcp-toolsEnable all GitHub MCP tools
--disable-builtin-mcpsDisable built-in MCP servers
--disable-mcp-server [name]Disable specific MCP server

Custom MCP Servers

Define custom servers at the user level (~/.copilot/mcp-config.json), in organization/enterprise agent profiles, or via the --additional-mcp-config flag.

🔌
Best Practice

Start with the GitHub MCP toolset for common needs. Add custom MCP servers for specialized tools. Test configurations with simple prompts first before using in automation.

Session Management

Continuing Sessions

# Resume the most recently closed session
copilot --continue

# Browse and pick from local and remote sessions
copilot --resume

# Resume a specific session by ID (in interactive mode)
/resume SESSION-ID

Session Storage

Context Management

Automatic compression: When approaching 95% of the token limit, Copilot automatically compresses history in the background without interruption. This enables virtually infinite sessions.

# Manually compress context anytime
/compact

# Reset context completely
/clear

Sharing Sessions

Export to Markdown

# In interactive mode
/share

# As a CLI flag (exports on completion)
copilot -p "..." --share

Export to GitHub Gist

# In interactive mode (prompts for visibility, description, filename)
/share gist

# As a CLI flag
copilot -p "..." --share-gist

Exports include timestamp, model used, token usage, and full conversation history with formatting preserved.

📋
Enterprise Note

With GitHub Enterprise Cloud and data residency enabled, Gist creation may be restricted by organization policy.

Configuration

Config Directory Structure

~/.copilot/
  ├─ copilot-instructions.md  ← User-level instructions
  ├─ mcp-config.json  ← MCP server config
  ├─ config
  ├─ session-state/  ← Local session storage
  └─ agents/  ← Custom agent profiles

Custom Instructions

Copilot CLI loads instructions from multiple sources, in order of priority:

User-Level

$HOME/.copilot/copilot-instructions.md

Repository-Level

.github/copilot-instructions.md
.github/instructions/**/*.instructions.md
CLAUDE.md                   # Claude-specific
GEMINI.md                   # Gemini-specific
AGENTS.md                   # Agent definitions

Custom Directories

# Set via environment variable (comma-separated)
export COPILOT_CUSTOM_INSTRUCTIONS_DIRS="/path/to/dir1,/path/to/dir2"

Repository-level instructions take precedence and enforce team conventions. Instructions are cached; restart CLI or use /resume after editing.

Custom Agents

Create specialized agents using Markdown files with YAML frontmatter:

# ~/.copilot/agents/test-agent.md
---
name: test-agent
description: Runs tests and analyzes failures
tools:
  - shell
  - read
---

Always run tests with verbose output.
If failures occur, analyze stack traces and suggest fixes.

Agent Locations

Built-in Agents (2026)

# Invoke a custom agent in interactive mode
/agent my-agent

# Invoke the explore agent
/agent explore

Plugin System

Plugins extend Copilot CLI with custom agents, MCP servers, skills, and LSP configurations.

# Manage plugins
copilot plugin [command]

Plugin sources include GitHub repositories, direct URLs, and local file paths. The copilot-plugins repository serves as a centralized registry.

Disabling Custom Instructions

# Ignore all custom instruction files for this session
copilot --no-custom-instructions

CLI Flags Reference

Core Commands

Command Description
copilot loginAuthenticate with GitHub
copilot helpDisplay help information
copilot initInitialize configuration
copilot updateUpdate to latest version
copilot versionShow version information
copilot pluginManage plugins

Operating Modes

Flag Description
-i, --interactiveStart interactive session (default)
-p, --prompt [text]Non-interactive mode with single prompt
--agentAgent mode (orchestrator with system prompt)
--acpStart as ACP (Agent Client Protocol) server
--acp --port [num]Start ACP server in TCP mode on port

Model & Session

Flag Description
--model [name]Specify AI model to use
--continueResume most recently closed local session
--resumeCycle through and resume local/remote sessions
--shareExport session to markdown on completion
--share-gistExport session to GitHub Gist on completion

Permission Flags

Flag Description
--allow-tool [tools...]Allow specific tools (glob patterns supported)
--deny-tool [tools...]Deny specific tools (takes precedence)
--allow-all-toolsAuto-approve all tool executions
--allow-all-pathsAllow access to any file path
--allow-url [patterns...]Allow URL patterns
--deny-url [patterns...]Deny URL patterns
--allow-all-urlsAllow all URL access
--allow-allEnable all permissions
--yoloEnable all permissions (alias)

MCP Configuration

Flag Description
--additional-mcp-config [path]Load additional MCP config file
--add-github-mcp-tool [tool]Add specific GitHub MCP tool
--add-github-mcp-toolset [set]Add GitHub MCP toolset
--enable-all-github-mcp-toolsEnable all GitHub MCP tools
--disable-builtin-mcpsDisable built-in MCP servers
--disable-mcp-server [name]Disable specific MCP server

Directory, Context & Misc

Flag Description
--add-dir [path]Grant access to specific directory
--config-dir [path]Specify config directory (default: ~/.copilot)
--no-custom-instructionsIgnore custom instruction files
--experimentalEnable experimental features

Pro Tips

Effective Usage Patterns

1. Break Down Complex Tasks

Be specific about requirements and provide examples:

copilot -p "Refactor AuthService to use dependency injection. \
Current implementation uses singletons. Preserve existing test coverage."

2. Use Plan Mode for Major Changes

Press Shift+Tab before implementing major features. Copilot asks clarifying questions, builds a structured plan, and you approve before execution.

3. Switch Models Based on Task Complexity

# Start fast with sonnet
copilot --model claude-sonnet-4.5

# Switch mid-session when hitting complex decisions
/model
# Select claude-opus-4.6

# Back to fast model for iterations
/model
# Select gpt-5-mini

4. Leverage Custom Agents

Create specialized agents for recurring workflows:

# ~/.copilot/agents/security-review.md
---
name: security-review
description: Reviews code for security vulnerabilities
tools:
  - read
---

Analyze code for OWASP Top 10 vulnerabilities.
Focus on authentication, input validation, and data exposure.
Report findings with severity levels.

5. Use Memory Features

As you work, Copilot stores coding standards, project structure insights, and your preferred approaches. This makes future sessions progressively more productive.

Scripting Recipes

Automated Code Quality Check

#!/bin/bash
copilot -p "
1. Run eslint on src/
2. Run prettier --check
3. Run unit tests
4. Generate summary report
" --allow-all-tools --share > quality-report.md

Interactive Development Loop

#!/bin/bash
while true; do
  copilot --continue --model claude-sonnet-4.5
  read -p "Continue? (y/n) " choice
  [[ "$choice" != "y" ]] && break
done

Collaborative Review & Share

#!/bin/bash
copilot -p "Review changes in $(git diff --name-only)" \
  --model claude-opus-4.6 \
  --share-gist > review-url.txt

echo "Review shared at: $(cat review-url.txt)"

Best Practices

Context Management

Permission Safety

Custom Instructions Hierarchy

Session Workflow

Advanced Patterns

Delegate to Copilot Coding Agent

# In interactive mode - pushes session to GitHub,
# opens draft PR, makes changes in background
/delegate

Explore Without Context Pollution

# Use the explore agent to ask questions
# without cluttering your main context
/agent explore
"How is authentication implemented?"
"Find all database queries in services/"

ACP Server for Third-Party Integration

# Start as Agent Client Protocol server
copilot --acp

# Or with TCP mode on a specific port
copilot --acp --port 3000

This allows third-party tools, IDEs, and automation systems to integrate with Copilot's agentic capabilities.

Enterprise Configuration Management

# Central config for team
export COPILOT_CUSTOM_INSTRUCTIONS_DIRS="/opt/company/copilot-config"

# Run with enterprise settings
copilot --config-dir /etc/copilot \
  --additional-mcp-config /etc/copilot/enterprise-mcp.json