Skip to content

sombaner/copilot-cli-agent-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Copilot CLI Agent Examples

A collection of automation scripts and examples for working with the GitHub Copilot CLI Agent. This repository demonstrates how to automate Copilot CLI workflows, including installation, authentication, and non-interactive execution.

πŸš€ What is the Copilot CLI Agent?

Copilot CLI Agent is GitHub's terminal-based agentic AI assistant that works seamlessly with existing GitHub Copilot entitlements. Unlike other tools that require separate subscriptions and API keys, Copilot CLI leverages your existing Copilot access and runs synchronously in your terminal with access to your local tools.

πŸ“ Repository Structure

.github/
β”œβ”€β”€ instructions/
β”‚   └── coding-agent-cli-instructions.instructions.md  # Copilot CLI documentation
scripts/
β”œβ”€β”€ copilot_run.sh              # Bash automation script
β”œβ”€β”€ copilot_run.py              # Python automation script
β”œβ”€β”€ .copilot_env                # Environment configuration (example)
β”œβ”€β”€ .env.example                # Template for environment variables
β”œβ”€β”€ prompt.txt                  # Sample prompt for non-interactive execution
└── README.md                   # Detailed usage instructions

πŸ› οΈ Features

  • Automated Installation: Installs Copilot CLI using npm with PAT authentication
  • Interactive Login: Handles Copilot authentication flow
  • Repository Cloning: Automatically clones target repositories for analysis
  • Non-Interactive Execution: Runs Copilot with predefined prompts using --full-auto
  • Cross-Platform: Both Bash and Python implementations
  • Secure Configuration: Environment-based configuration with example templates

πŸ“‹ Prerequisites

  • Node.js: Version 22 or higher
  • npm: Version 10 or higher
  • Git: For repository cloning (if using GIT_REPO)
  • GitHub PAT: Classic Personal Access Token with read:packages scope

Supported Platforms

  • Linux
  • macOS
  • Windows via WSL (Ubuntu recommended)

πŸš€ Quick Start

1. Set Up Environment

Copy the example environment file and configure it:

cp scripts/.env.example scripts/.copilot_env

Edit scripts/.copilot_env with your values:

# Classic GitHub PAT for npm package installation and git cloning
COPILOT_PAT=ghp_your_classic_pat_here

# Directory where code will be cloned and Copilot will run
COPILOT_WORKDIR=/path/to/your/workspace

# Path to the prompt file
PROMPT_FILE=./prompt.txt

# Git repository to clone (optional)
GIT_REPO=https://github.com/yourusername/your-repo.git

2. Create Your Prompt

Edit scripts/prompt.txt with your desired prompt:

Add a rating feature to this application. Add API to get books by rating. 
Improve the frontend with rating display. Only make changes. 
Compile the application and make sure it's compiled. 
Do not launch, run, or test the application.

3. Run the Automation

Choose either the Bash or Python script:

Using Bash:

cd scripts
chmod +x copilot_run.sh
./copilot_run.sh

Using Python:

cd scripts
python3 copilot_run.py

πŸ”§ How It Works

  1. Installation Check: Verifies if copilot binary exists, installs via npm if missing
  2. Authentication: Triggers interactive login using /login command
  3. Workspace Setup: Creates workspace directory and clones repository if specified
  4. Execution: Runs Copilot in non-interactive mode with --full-auto flag

πŸ”’ Security Considerations

⚠️ Important Security Notes:

  • Never commit real PATs to version control
  • Store sensitive values in secure locations outside the repository
  • The scripts use temporary npm configuration files to avoid modifying ~/.npmrc
  • PATs are embedded in git URLs temporarily for authentication and cleared after use

πŸ“– Configuration Reference

Environment Variables

Variable Description Required Example
COPILOT_PAT Classic GitHub PAT with read:packages scope Yes ghp_...
COPILOT_WORKDIR Target workspace directory Yes /path/to/workspace
PROMPT_FILE Path to prompt file No ./prompt.txt
GIT_REPO Repository to clone No https://github.com/user/repo.git
ENV_FILE Custom environment file path No ./.copilot_env

Copilot CLI Options Used

  • -p, --prompt: Execute prompt directly without interactive mode
  • --full-auto: Allow all tools to run automatically without confirmation

πŸ” Examples

Basic Code Analysis

# Set prompt to analyze a repository
echo "Analyze this codebase and suggest improvements" > scripts/prompt.txt
./scripts/copilot_run.sh

Feature Implementation

# Set prompt to add specific features
echo "Add authentication middleware to this Express.js application" > scripts/prompt.txt
python3 scripts/copilot_run.py

Code Review

# Set prompt for code review
echo "Review this code for security vulnerabilities and performance issues" > scripts/prompt.txt
./scripts/copilot_run.sh

πŸ› Troubleshooting

Installation Issues

If you encounter build errors during installation:

# On WSL/Ubuntu
sudo apt-get update
sudo apt-get install make build-essential

Authentication Problems

  • Ensure your PAT has read:packages scope
  • Enable SSO for the github organization (if applicable)
  • Keep PAT expiration under 90 days

Login Flow

The login step is interactive and may open a browser. Complete the OAuth flow when prompted.

πŸ“š Additional Resources

🀝 Contributing

Feel free to submit issues and enhancement requests! When contributing:

  1. Test scripts on multiple platforms
  2. Update documentation for new features
  3. Follow security best practices for handling credentials

πŸ“„ License

This project contains examples and automation scripts for GitHub Copilot CLI Agent. Please refer to GitHub's terms of service for Copilot usage.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors