- name
- github-copilot-cli
- description
- AI-powered command-line assistant for developers that provides code review, debugging, test generation, and development workflows directly in the terminal
- triggers
- ["how do I use GitHub Copilot CLI","review this code with copilot cli","debug using copilot in terminal","generate tests with copilot cli","explain this code with copilot","create custom copilot agents","set up copilot cli skills","integrate MCP servers with copilot"]
# GitHub Copilot CLI Skill
> Skill by [ara.so](https://ara.so) — Devtools Skills collection.
GitHub Copilot CLI brings AI-powered development assistance directly to your terminal. It enables code review, debugging, test generation, code explanation, and custom AI agents without leaving the command line. Think of it as having an expert developer available 24/7 in your terminal who can read your codebase, explain patterns, generate code, and help troubleshoot issues.
## Installation
### Prerequisites
- GitHub account with Copilot access (free tier, subscription, or education)
- GitHub CLI (`gh`) version 2.62.0 or later
- Terminal access
### Install GitHub CLI
**macOS:**
```bash
brew install gh
```
**Windows:**
```bash
winget install --id GitHub.cli
```
**Linux (Debian/Ubuntu):**
```bash
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
```
### Install Copilot CLI Extension
```bash
gh extension install github/gh-copilot
```
### Authenticate
```bash
gh auth login
```
Follow the prompts to authenticate with your GitHub account that has Copilot access.
### Verify Installation
```bash
gh copilot --version
```
## Core Commands
### Interactive Chat Mode
Start an interactive conversation with Copilot:
```bash
gh copilot
```
This opens a conversational interface where you can ask questions, get code suggestions, and iterate on solutions.
### Quick Explain
Get quick explanations without entering interactive mode:
```bash
gh copilot explain "git rebase -i HEAD~3"
```
```bash
gh copilot explain "docker-compose up -d"
```
### Quick Suggest
Get command suggestions for tasks:
```bash
gh copilot suggest "find all python files modified in last 7 days"
```
```bash
gh copilot suggest "compress all jpg files in current directory"
```
### Aliases (Shortcuts)
Set up convenient aliases:
```bash
gh copilot alias -- --shell bash
```
This creates three aliases:
- `ghcs` - suggest commands
- `ghce` - explain commands
- `ghcp` - open Copilot chat
After setup, you can use:
```bash
ghcs "list all running docker containers"
ghce "kubectl get pods -A"
```
## Interaction Modes
### 1. Chat Mode (Interactive)
Best for: Complex problems, iterative development, multi-step workflows
```bash
gh copilot
```
Example conversation:
```
> I need to review a Python Flask application for security issues
Copilot: I'll help you review your Flask application for security. Could you share:
1. The main application file
2. Any authentication/authorization code
3. Database interaction code
> @app.py @auth.py @models.py
Copilot: [Analyzes files and provides security review]
```
### 2. Explain Mode
Best for: Understanding unfamiliar commands, code snippets, or error messages
```bash
gh copilot explain "awk '{print $2}' file.txt | sort -u"
```
```bash
gh copilot explain "SELECT u.name, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id"
```
### 3. Suggest Mode
Best for: Getting shell commands for specific tasks
```bash
gh copilot suggest "recursively delete all node_modules folders"
```
```bash
gh copilot suggest "monitor CPU and memory usage in real-time"
```
## Context Awareness
### File Context (@-mentions)
Reference specific files in your prompts:
```bash
gh copilot
> Review @server.py for potential race conditions
```
```bash
gh copilot
> Compare @config.dev.json and @config.prod.json and explain differences
```
### Multi-File Context
Reference multiple files for comprehensive analysis:
```bash
gh copilot
> @models.py @views.py @serializers.py review this Django app for N+1 queries
```
### Directory Context
Analyze entire directories:
```bash
gh copilot
> @src/ explain the architecture of this application
```
## Development Workflows
### Code Review
```bash
gh copilot
> Review @pull_request_changes.diff for:
> - Security vulnerabilities
> - Performance issues
> - Code style violations
> - Missing error handling
```
### Debugging
```bash
gh copilot
> I'm getting "TypeError: Cannot read property 'map' of undefined" in @app.js line 42
> Here's the error stack: @error.log
```
### Test Generation
For Python:
```bash
gh copilot
> Generate pytest unit tests for @calculator.py covering edge cases
```
For JavaScript:
```bash
gh copilot
> Create Jest tests for @api-client.js including error scenarios
```
For Go:
```bash
gh copilot
> Write table-driven tests for @handler.go
```
### Refactoring
```bash
gh copilot
> Refactor @legacy-auth.js to use async/await instead of callbacks
```
```bash
gh copilot
> Convert @class-component.jsx to a functional component with hooks
```
## Custom Agents and Instructions
### Creating Custom Agents
Agents are reusable AI assistants with specific expertise. Create an agent configuration:
```bash
mkdir -p ~/.config/gh-copilot/agents
```
**Security Review Agent** (`~/.config/gh-copilot/agents/security-reviewer.md`):
```markdown
# Security Reviewer Agent
You are a security-focused code reviewer specializing in:
- OWASP Top 10 vulnerabilities
- Input validation and sanitization
- Authentication and authorization flaws
- SQL injection and XSS prevention
- Secrets and credential management
Always:
1. Identify specific line numbers with issues
2. Explain the security impact
3. Provide secure code examples
4. Reference relevant OWASP guidelines
```
**Python Expert Agent** (`~/.config/gh-copilot/agents/python-expert.md`):
```markdown
# Python Expert Agent
You are a Python expert focusing on:
- PEP 8 style compliance
- Type hints and mypy compatibility
- Pythonic idioms and patterns
- Performance optimization
- Testing with pytest
Provide:
- Specific improvement suggestions
- Code examples following best practices
- Performance benchmarks when relevant
```
### Using Agents
```bash
gh copilot
> @security-reviewer analyze @app.py
```
```bash
gh copilot
> @python-expert review @data_processor.py for optimization opportunities
```
### Custom Instructions (Global)
Set global instructions that apply to all interactions:
```bash
mkdir -p ~/.config/gh-copilot
```
Create `~/.config/gh-copilot/instructions.md`:
```markdown
# My Development Preferences
- **Language**: Prefer TypeScript over JavaScript
- **Testing**: Use Jest with React Testing Library
- **Style**: Follow Airbnb style guide
- **Error Handling**: Always use try-catch and log errors
- **Comments**: Add JSDoc comments for public functions
- **Security**: Flag any hardcoded credentials or secrets
```
## Skills (Automated Context)
Skills are automatically loaded based on your project structure.
### Creating a Skill
Create `.copilot/skills/` directory in your project:
```bash
mkdir -p .copilot/skills
```
**Django Project Skill** (`.copilot/skills/django-project.md`):
```markdown
# Django Project Configuration
## Stack
- Django 4.2
- PostgreSQL 15
- Redis for caching
- Celery for async tasks
## Code Standards
- Use Django REST Framework serializers
- Prefer class-based views
- Always use select_related/prefetch_related
- Write tests with pytest-django
## Database
- Use migrations for all schema changes
- Never use raw SQL without parameterization
- Connection: via DATABASE_URL environment variable
```
**React Project Skill** (`.copilot/skills/react-conventions.md`):
```markdown
# React Project Conventions
## Stack
- React 18 with TypeScript
- Vite for bundling
- React Query for data fetching
- Zustand for state management
## Patterns
- Functional components with hooks
- Custom hooks for reusable logic
- Error boundaries for fault tolerance
- Suspense for loading states
## File Structure
- Components in src/components
- Hooks in src/hooks
- Utils in src/utils
```
Skills are automatically loaded when you run `gh copilot` in a directory containing `.copilot/skills/`.
## MCP Server Integration
Model Context Protocol (MCP) servers extend Copilot CLI with external data sources and APIs.
### Configuration File
Create `~/.config/gh-copilot/mcp.json`:
```json
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
}
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
}
}
}
}
```
### Available MCP Servers
**GitHub Integration:**
```json
{
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
}
}
}
```
Usage:
```bash
gh copilot
> Search GitHub for recent issues tagged "bug" in owner/repo
```
**PostgreSQL Database:**
```json
{
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
}
}
}
```
Usage:
```bash
gh copilot
> Query the database for users created in the last 30 days
```
**Filesystem Access:**
```json
{
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
}
}
```
**Brave Search:**
```json
{
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
}
}
}
```
### Creating Custom MCP Servers
MCP servers are command-line tools that implement the MCP protocol. Example structure:
```javascript
// my-mcp-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server({
name: 'my-custom-server',
version: '1.0.0',
});
// Define tools
server.setRequestHandler('tools/list', async () => ({
tools: [{
name: 'get_data',
description: 'Fetch data from custom source',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' }
}
}
}]
}));
// Implement tool
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
if (name === 'get_data') {
const result = await fetchCustomData(args.query);
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
}
});
const transport = new StdioServerTransport();
await server.connect(transport);
```
Add to `mcp.json`:
```json
{
"my-custom": {
"command": "node",
"args": ["/path/to/my-mcp-server.js"]
}
}
```
## Real-World Examples
### Example 1: Code Review Workflow
```bash
# Start review session
gh copilot
> I need to review changes before committing. Review @src/auth.py @src/models.py for:
> 1. Security issues
> 2. Performance problems
> 3. Code style
> 4. Missing tests
# Copilot provides detailed review
> Generate pytest tests for the issues you found in @src/auth.py
# Copilot generates test code
> Now explain how to fix the SQL injection vulnerability you identified
GitHub에서 보기