Skip to main content

Advanced Topics

Prerequisites

  • Completed Modules 1-11
  • Comfortable with Copilot CLI basics
  • Understanding of CI/CD concepts

Learning Objectives

  • Configure environment variables and paths
  • Set up Copilot CLI for CI/CD pipelines
  • Use advanced command-line flags
  • Troubleshoot common issues
  • Apply best practices for team workflows

Configuration Hierarchy

Environment Variables

XDG_CONFIG_HOME (~/.copilot)

Repository Configuration

Session Overrides (flags)

Key Directories

DirectoryPurpose
~/.copilot/Default config location
~/.copilot/config.jsonUser settings
~/.copilot/mcp-config.jsonMCP servers
~/.copilot/skills/Personal skills
.github/Repository config

Exercise 1: Environment Variables

important

Use COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN (in order of precedence) as the authentication token. These take precedence over previously stored credentials.

Goal: Configure Copilot CLI behavior via environment.

Steps:

  1. XDG_CONFIG_HOME - Change config location:

    # Set custom config directory
    export XDG_CONFIG_HOME=/custom/path

    # Copilot will now use /custom/path/copilot/
    copilot
  2. GITHUB_TOKEN - Authentication for CI/CD:

    export GITHUB_TOKEN="ghp_your_personal_access_token"

    # Use in scripts
    copilot -p "Run the test suite" --allow-tool 'shell'
  3. GITHUB_ASKPASS - Credential helper:

    # Create a credential helper script
    cat > ~/credential-helper.sh << 'EOF'
    #!/bin/bash
    echo "$COPILOT_TOKEN"
    EOF
    chmod +x ~/credential-helper.sh

    export GITHUB_ASKPASS=~/credential-helper.sh
    export COPILOT_TOKEN="your-token"

    copilot
  4. NO_COLOR - Disable colored output:

    export NO_COLOR=1
    copilot -p "List files"
  5. View effective configuration:

    copilot --help | head -50

Expected Outcome: Environment variables customize Copilot behavior.

Exercise 2: CI/CD Integration

Goal: Set up Copilot CLI in automated pipelines.

Steps:

  1. GitHub Actions workflow:

    # .github/workflows/copilot-review.yml
    name: Copilot Code Review

    on:
    pull_request:
    types: [opened, synchronize]

    jobs:
    review:
    runs-on: ubuntu-latest
    steps:
    - 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 Code Review
    env:
    GITHUB_TOKEN: ${{ secrets.COPILOT_TOKEN }}
    run: |
    copilot -p "Review the changes in this PR and provide feedback" \
    --allow-tool 'shell(git)' \
    --deny-tool 'write' \
    --silent
  2. Pre-commit hook:

    # .git/hooks/pre-commit
    #!/bin/bash

    # Run Copilot analysis on staged files
    STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)

    if [ -n "$STAGED_FILES" ]; then
    copilot -p "Review these staged files for issues: $STAGED_FILES" \
    --allow-tool 'shell(cat)' \
    --allow-tool 'shell(git diff)' \
    --deny-tool 'write' \
    --silent
    fi
  3. Docker container usage:

    FROM node:22-slim

    RUN npm install -g @github/copilot

    # Set up config directory
    ENV XDG_CONFIG_HOME=/app/config

    WORKDIR /workspace

    # Entry point for CI
    ENTRYPOINT ["copilot"]
  4. Safe CI flags:

    copilot -p "Your prompt" \
    --allow-tool 'shell(npm test)' \
    --allow-tool 'shell(npm run lint)' \
    --deny-tool 'shell(rm)' \
    --deny-tool 'shell(git push)' \
    --deny-tool 'write' \
    --silent

Expected Outcome: Copilot CLI integrated into automated workflows.

Exercise 3: Advanced Command-Line Flags

Goal: Master all available flags.

Steps:

  1. Output control:

    # Silent mode - minimal output
    copilot -p "Count lines of code" --silent

    # Export session to markdown
    copilot -p "Analyze project" --share ./analysis.md

    # Export to GitHub Gist
    copilot -p "Generate report" --share-gist
  2. Tool control:

    # Allow specific tools only
    copilot --available-tools 'shell,read'

    # Exclude specific tools
    copilot --excluded-tools 'write,web_fetch'
  3. Model selection:

    # Use specific model
    copilot --model gpt-4.1

    # Use faster model for simple tasks
    copilot --model gpt-5-mini -p "What time is it?"
  4. Session control:

    # Resume last session
    copilot --resume

    # Use additional MCP config temporarily
    copilot --additional-mcp-config ./custom-mcp.json
  5. View all flags:

    copilot --help

Expected Outcome: Full command-line control over Copilot behavior.

Quick Reference

Configuration Files

FilePurposeVersion Added
~/.copilot/config.jsonUser settingsBase
~/.copilot/mcp-config.jsonMCP serversBase
~/.copilot/lsp.jsonLSP timeout configurationv0.0.412
~/.copilot/skills/Personal skillsBase
.github/copilot-instructions.mdRepository instructionsBase

Environment Variables

VariablePurpose
XDG_CONFIG_HOMEConfig directory location
GITHUB_TOKENAuthentication token
GITHUB_ASKPASSCredential helper script
NO_COLORDisable colored output
COPILOT_DEBUGEnable debug logging

Command-Line Flags

FlagDescriptionVersion
-p, --promptProgrammatic mode promptBase
--modelSelect AI modelBase
--resumeResume last sessionBase
--yoloAllow all toolsBase
--allow-toolAllow specific toolBase
--deny-toolDeny specific toolBase
--silentSuppress outputBase
--share PATHExport to markdownBase
--share-gistExport to GistBase
--additional-mcp-configAdd MCP configBase
--autopilotEnable autonomous multi-step executionv0.0.411
--bash-envSource BASH_ENV in shell sessionsv0.0.412
--experimentalEnable experimental featuresv0.0.413

Shell Mode Access

note

Changed in v0.0.410: Shell mode removed from Shift+Tab cycle.

MethodDescriptionVersion
!Direct access to shell modev0.0.410+
Shift+TabCycle (chat) / (command) onlyv0.0.410+

Useful Aliases

# Add to ~/.bashrc or ~/.zshrc

# Quick Copilot start
alias cop='copilot'

# Read-only analysis
alias cop-analyze='copilot --deny-tool write'

# Safe automation mode
alias cop-safe='copilot --allow-tool "shell(cat)" --allow-tool "shell(grep)" --deny-tool write'

# Full autonomy (careful!)
alias cop-yolo='copilot --yolo'

# Resume session
alias cop-resume='copilot --resume'

Next Steps

Continue to Automation Patterns for autopilot mode, fleet command, and LSP configuration.