This guide provides comprehensive instructions for integrating GitHub Copilot CLI with various tools, environments, and workflows.
- Terminal Integration
- VS Code Integration
- MCP Server Configuration
- Shell Completions
- Git Hooks Integration
- CI/CD Integration
- Custom Workflows
Add to your ~/.bashrc or ~/.bash_profile:
# GitHub Copilot CLI alias
alias ai='copilot'
# Quick prompt mode
alias aip='copilot -p'
# Enable terminal integration
eval "$(copilot /terminal-setup bash)"Add to your ~/.zshrc:
# GitHub Copilot CLI alias
alias ai='copilot'
# Quick prompt mode
alias aip='copilot -p'
# Enable terminal integration
eval "$(copilot /terminal-setup zsh)"Add to your PowerShell profile ($PROFILE):
# GitHub Copilot CLI alias
Set-Alias -Name ai -Value copilot
# Quick prompt mode
function aip { copilot -p $args }
# Enable terminal integration
Invoke-Expression (copilot /terminal-setup powershell)Add to your ~/.config/fish/config.fish:
# GitHub Copilot CLI alias
alias ai='copilot'
alias aip='copilot -p'
# Enable terminal integration
copilot /terminal-setup fish | sourceCopilot CLI can leverage VS Code's MCP configuration. Create or update ~/.vscode/mcp.json:
{
"mcpServers": {
"filesystem": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
},
"github": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
}
}
}
}In your VS Code workspace settings (.vscode/settings.json):
{
"terminal.integrated.env.linux": {
"COPILOT_WORKSPACE": "${workspaceFolder}"
},
"terminal.integrated.env.osx": {
"COPILOT_WORKSPACE": "${workspaceFolder}"
},
"terminal.integrated.env.windows": {
"COPILOT_WORKSPACE": "${workspaceFolder}"
}
}Create ~/.copilot/mcp-config.json:
{
"mcpServers": {
"filesystem": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "${HOME}/projects"],
"tools": ["*"]
},
"git": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-git"],
"tools": ["*"]
},
"postgres": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"],
"tools": ["*"]
},
"sequential-thinking": {
"type": "local",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"],
"tools": ["*"]
}
}
}Create .copilot/mcp-config.json in your project root:
{
"mcpServers": {
"project-specific": {
"type": "local",
"command": "node",
"args": ["./tools/mcp-server.js"],
"tools": ["*"]
}
}
}Pass MCP configuration at runtime:
# Inline JSON
copilot --additional-mcp-config '{"mcpServers": {"my-tool": {...}}}'
# From file
copilot --additional-mcp-config @/path/to/config.json
# Multiple configurations (later values override earlier ones)
copilot --additional-mcp-config @base.json --additional-mcp-config @overrides.jsonFor Bash, add to ~/.bashrc:
# Basic command completion
complete -C copilot copilotFor Zsh, add to ~/.zshrc:
# Enable completion system
autoload -Uz compinit && compinit
# Basic command completion
compdef _gnu_generic copilotFor PowerShell, add to your $PROFILE:
# Basic command completion
Register-ArgumentCompleter -Native -CommandName copilot -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
copilot --help | Select-String "^\s*--" | ForEach-Object {
$_.Line.Trim() -split '\s+' | Select-Object -First 1
} | Where-Object { $_ -like "$wordToComplete*" }
}Create .git/hooks/pre-commit:
#!/bin/bash
# Use Copilot to review staged changes
echo "Running Copilot pre-commit review..."
git diff --cached | copilot -p "Review these changes for potential issues, security vulnerabilities, and code quality. Be concise."
# Exit code doesn't block commit, just provides feedback
exit 0Make it executable:
chmod +x .git/hooks/pre-commitCreate .git/hooks/prepare-commit-msg:
#!/bin/bash
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
# Only generate message for regular commits (not amend, merge, etc.)
if [ -z "$COMMIT_SOURCE" ]; then
# Get staged changes
DIFF=$(git diff --cached)
# Generate commit message using Copilot
if [ -n "$DIFF" ]; then
MESSAGE=$(echo "$DIFF" | copilot -p "Generate a concise, conventional commit message for these changes. Use format: type(scope): description")
# Prepend generated message to commit file
echo "$MESSAGE" > "$COMMIT_MSG_FILE.tmp"
echo "" >> "$COMMIT_MSG_FILE.tmp"
cat "$COMMIT_MSG_FILE" >> "$COMMIT_MSG_FILE.tmp"
mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE"
fi
fiMake it executable:
chmod +x .git/hooks/prepare-commit-msgCreate .github/workflows/copilot-review.yml:
name: Copilot Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Copilot CLI
run: npm install -g @github/copilot
- name: Review Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get PR diff
git diff origin/${{ github.base_ref }}...HEAD > pr_diff.txt
# Review with Copilot
copilot -p "Review this PR for code quality, security issues, and best practices. Provide specific, actionable feedback." < pr_diff.txt > review.txt
# Post as comment (requires gh CLI)
gh pr comment ${{ github.event.pull_request.number }} --body-file review.txtCreate .gitlab-ci.yml:
copilot-review:
stage: review
image: node:22
before_script:
- npm install -g @github/copilot
script:
- git diff $CI_MERGE_REQUEST_TARGET_BRANCH_SHA...$CI_COMMIT_SHA > mr_diff.txt
- copilot -p "Review these changes for quality and security issues" < mr_diff.txt > review.txt
- cat review.txt
only:
- merge_requests
variables:
GITHUB_TOKEN: $COPILOT_TOKENCreate Jenkinsfile:
pipeline {
agent any
environment {
GITHUB_TOKEN = credentials('github-token')
}
stages {
stage('Setup') {
steps {
sh 'npm install -g @github/copilot'
}
}
stage('Code Review') {
steps {
sh '''
git diff ${GIT_PREVIOUS_COMMIT}..${GIT_COMMIT} > changes.txt
copilot -p "Review these changes for issues" < changes.txt > review.txt
cat review.txt
'''
}
}
}
}Create scripts/copilot-review.sh:
#!/bin/bash
# Review specific files or directories
TARGET=${1:-.}
echo "Reviewing: $TARGET"
# For files
if [ -f "$TARGET" ]; then
cat "$TARGET" | copilot -p "Review this code for quality, security, and best practices. Be specific and actionable."
exit 0
fi
# For directories
if [ -d "$TARGET" ]; then
find "$TARGET" -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" -o -name "*.go" \) | while read file; do
echo "=== Reviewing: $file ==="
cat "$file" | copilot -p "Quick security and quality review. Flag only critical issues."
echo ""
done
fiCreate scripts/generate-docs.sh:
#!/bin/bash
# Generate documentation for source files
SOURCE_DIR=${1:-src}
DOCS_DIR=${2:-docs}
mkdir -p "$DOCS_DIR"
find "$SOURCE_DIR" -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" \) | while read file; do
filename=$(basename "$file")
doc_file="$DOCS_DIR/${filename%.*}.md"
echo "Generating docs for: $file"
cat "$file" | copilot -p "Generate comprehensive documentation for this code. Include function descriptions, parameters, return values, and usage examples in Markdown format." > "$doc_file"
done
echo "Documentation generated in: $DOCS_DIR"Create scripts/generate-tests.sh:
#!/bin/bash
# Generate tests for source files
SOURCE_FILE=$1
if [ -z "$SOURCE_FILE" ]; then
echo "Usage: $0 <source-file>"
exit 1
fi
# Determine test file path
case "$SOURCE_FILE" in
*.js) TEST_FILE="${SOURCE_FILE%.js}.test.js" ;;
*.ts) TEST_FILE="${SOURCE_FILE%.ts}.test.ts" ;;
*.py) TEST_FILE="${SOURCE_FILE%.py}_test.py" ;;
*) echo "Unsupported file type"; exit 1 ;;
esac
echo "Generating tests for: $SOURCE_FILE"
echo "Output: $TEST_FILE"
cat "$SOURCE_FILE" | copilot -p "Generate comprehensive unit tests for this code. Include edge cases, error handling, and integration scenarios. Use appropriate testing framework for the language." > "$TEST_FILE"
echo "Tests generated: $TEST_FILE"Create scripts/refactor-code.sh:
#!/bin/bash
FILE=$1
GOAL=${2:-"improve code quality and maintainability"}
if [ -z "$FILE" ]; then
echo "Usage: $0 <file> [goal]"
exit 1
fi
echo "Refactoring: $FILE"
echo "Goal: $GOAL"
# Backup original
cp "$FILE" "$FILE.backup"
# Generate refactored version
cat "$FILE" | copilot -p "Refactor this code to $GOAL. Maintain functionality but improve structure, readability, and performance. Provide only the refactored code." > "$FILE.new"
# Show diff
echo "=== Changes ==="
diff -u "$FILE" "$FILE.new"
echo ""
echo "Review the changes above."
echo "To apply: mv $FILE.new $FILE"
echo "To revert: mv $FILE.backup $FILE"Copilot CLI recognizes these environment variables:
# Authentication
export GITHUB_TOKEN="your-token-here"
export GH_TOKEN="your-token-here" # Alternative
# Configuration
export COPILOT_WORKSPACE="/path/to/workspace"
export COPILOT_MODEL="claude-sonnet-4.5" # Default model
# MCP Configuration
export COPILOT_MCP_CONFIG="/path/to/mcp-config.json"
# Behavior
export COPILOT_STREAM="on" # Enable streaming
export COPILOT_DEBUG="true" # Enable debug loggingIf MCP tools are not visible:
- Verify MCP configuration file location:
~/.copilot/mcp-config.json - Check server executables are in PATH:
which npx,which uvx - Test server startup manually:
npx -y @modelcontextprotocol/server-filesystem - Check server processes:
ps aux | grep mcp - Enable debug logging:
COPILOT_DEBUG=true copilot
If authentication fails:
- Verify token is set:
echo $GITHUB_TOKEN - Check token permissions at: https://github.com/settings/tokens
- Ensure "Copilot Requests" permission is enabled
- Try re-authenticating:
/logincommand in Copilot CLI
If Copilot is slow:
- Reduce context size by limiting file access
- Disable unnecessary MCP servers
- Use
--stream offif streaming causes issues - Check network connectivity
- Verify system resources (RAM, CPU)
- Use Project-Specific Configuration: Keep MCP configs in project root
- Secure Tokens: Never commit tokens to version control
- Limit Tool Access: Only enable MCP tools you need (
tools: ["specific-tool"]) - Version Control Hooks: Make hooks non-blocking (always exit 0)
- CI/CD Integration: Use read-only operations in CI pipelines
- Regular Updates: Keep Copilot CLI updated:
npm update -g @github/copilot
For issues or feature requests, visit: https://github.com/github/copilot-cli/issues