Skip to content

A powerful terminal-based chat application that integrates with GitHub Copilot using real OAuth device flow authentication and dynamic model discovery.

Notifications You must be signed in to change notification settings

sosacrazy126/github-copilot-cli-chat

Repository files navigation

GitHub Copilot CLI Chat

A powerful terminal-based chat application that integrates with GitHub Copilot using real OAuth device flow authentication and dynamic model discovery.

GitHub Copilot CLI TypeScript Node.js

🌟 Features

  • πŸ” Real GitHub OAuth Authentication - Secure device flow authentication
  • πŸ€– Dynamic Model Discovery - Automatically detects available GitHub Copilot models
  • πŸ’¬ Interactive Terminal Chat - Rich CLI with colored output and commands
  • ⚑ Intelligent Caching - Smart model and token caching for performance
  • πŸ”„ Auto Token Refresh - Seamless token management and renewal
  • πŸŽ›οΈ Configurable Settings - Adjust temperature, max tokens, and model selection
  • πŸ“ Session Management - Persistent chat history during sessions
  • πŸ›‘οΈ Robust Error Handling - Graceful fallbacks and detailed error messages

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • GitHub account with Copilot access
  • Terminal with color support

Installation

# Clone the repository
git clone <repository-url>
cd copilot-cli-chat

# Install dependencies
npm install

# Run setup wizard
npm run setup

# Build the project
npm run build

First Run

# Start the application
npm run dev

# Authenticate with GitHub Copilot
/auth

# Start chatting!
Hello, can you help me write a Python function?

🎯 Usage

Authentication Flow

  1. Start the app: npm run dev
  2. Authenticate: Use /auth command
  3. Visit GitHub: Go to the provided URL
  4. Enter code: Input the device code shown
  5. Start chatting: Begin your conversation!

Available Commands

Command Description
/help Show all available commands
/auth Authenticate with GitHub Copilot
/status Show authentication and configuration status
/logout Log out and clear stored credentials
/clear Clear current chat history
/model [name] Set or show current model
/models Show detailed model information with availability
/refresh Refresh available models from GitHub Copilot API
/temperature [0-2] Set or show temperature setting
/tokens [1-4000] Set or show max tokens
/quit, /exit Exit the application

Example Session

πŸš€ Welcome to GitHub Copilot CLI Chat!
Type /help for available commands or just start chatting.

> /models
πŸ” Fetching detailed model information...

πŸ€– Available GitHub Copilot Models:
  βœ… gpt-4o (current)
      Owner: github-copilot
  βœ… gpt-4-turbo
      Owner: github-copilot
  βœ… claude-3-5-sonnet-20241022
      Owner: github-copilot

> /model gpt-4o
βœ… Model set to: gpt-4o

> Write a Python function to calculate fibonacci numbers
πŸ€– Thinking...

πŸ€– GitHub Copilot:
Here's a Python function to calculate Fibonacci numbers:

```python
def fibonacci(n):
    """Calculate the nth Fibonacci number."""
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

/temperature 0.3 βœ… Temperature set to: 0.3


## βš™οΈ Configuration

### Environment Variables

Create a `.env` file (copy from `.env.example`):

```bash
# Optional: Custom GitHub OAuth App Client ID
GITHUB_COPILOT_CLIENT_ID=your_custom_client_id

# Optional: Enable debug logging
DEBUG_COPILOT_AUTH=true

# Optional: Custom storage location
AUTH_STORAGE_PATH=./copilot-auth.json

Model Configuration

The application automatically discovers available models from your GitHub Copilot subscription:

  • Primary: Fetches from official GitHub Copilot models endpoint
  • Secondary: Tests known model names (gpt-4o, claude-3-5-sonnet, etc.)
  • Fallback: Uses cached models or minimal working set

Default Settings

  • Model: First available model (auto-detected)
  • Temperature: 0.7
  • Max Tokens: 2000
  • Cache Timeout: 5 minutes

πŸ—οΈ Architecture

Core Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   CLI Interface β”‚ ── β”‚ GitHub Copilot   β”‚ ── β”‚ Authentication  β”‚
β”‚                 β”‚    β”‚ Provider         β”‚    β”‚ Manager         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Chat Session    β”‚    β”‚ Model Discovery  β”‚    β”‚ Token Storage   β”‚
β”‚ Management      β”‚    β”‚ & Caching        β”‚    β”‚ & Refresh       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Authentication Flow

  1. Device Code Request β†’ GitHub OAuth endpoint
  2. User Authorization β†’ GitHub web interface
  3. Token Exchange β†’ GitHub Copilot API token
  4. Secure Storage β†’ Encrypted local storage
  5. Auto Refresh β†’ Seamless token renewal

Model Discovery

  1. API Endpoint β†’ https://api.githubcopilot.com/models
  2. Model Testing β†’ Test known model availability
  3. Caching β†’ 5-minute intelligent cache
  4. Fallback β†’ Minimal working model set

πŸ› οΈ Development

Scripts

npm run dev           # Development mode with auto-reload
npm run build         # Build for production  
npm run start         # Run production build
npm run setup         # Configuration wizard
npm run type-check    # TypeScript type checking
npm run clean         # Clean build artifacts

Project Structure

src/
β”œβ”€β”€ auth/
β”‚   β”œβ”€β”€ github-copilot.ts    # OAuth authentication logic
β”‚   └── storage.ts           # Persistent token storage
β”œβ”€β”€ providers/
β”‚   └── github-copilot.ts    # Model provider & API integration
β”œβ”€β”€ cli.ts                   # Main CLI application
└── setup.ts                 # Setup wizard

dist/                        # Built files
docs/                        # Documentation

Building from Source

# Clone and setup
git clone <repository-url>
cd copilot-cli-chat
npm install

# Development
npm run dev

# Production build
npm run build
npm start

πŸ”§ Troubleshooting

Authentication Issues

Problem: GitHub Copilot authentication required

  • Solution: Run /auth to authenticate
  • Check: Ensure you have GitHub Copilot access
  • Debug: Set DEBUG_COPILOT_AUTH=true in .env

Problem: Token exchange failed

  • Solution: Try /logout then /auth again
  • Check: Verify internet connection
  • Info: Tokens expire and need refresh

Model Issues

Problem: No models currently available

  • Solution: Run /refresh to refresh models
  • Check: Verify Copilot subscription is active
  • Fallback: App uses default models if discovery fails

Problem: Model not found error

  • Solution: Use /models to see available models
  • Check: Set model with /model <model-name>
  • Info: Models vary by Copilot subscription

API Errors

Problem: 400 - bad request: error: invalid apiVersion

  • Status: βœ… Fixed in current version
  • Cause: Removed invalid API version headers

Problem: Rate limiting or 429 errors

  • Info: GitHub Copilot has usage limits
  • Wait: Try again after a short delay
  • Check: Monitor usage in GitHub settings

Build Issues

Problem: tsx: not found

  • Solution: Run npm install to install dependencies
  • Check: Ensure Node.js 18+ is installed

Problem: TypeScript compilation errors

  • Solution: Run npm run type-check for details
  • Fix: Update code to match TypeScript requirements

πŸ“Š Monitoring & Debugging

Debug Mode

Enable detailed logging:

# In .env file
DEBUG_COPILOT_AUTH=true

# Run with debug output
npm run dev

Storage Location

Authentication data is stored securely at:

  • Default: ~/.copilot-cli/auth.json
  • Custom: Set AUTH_STORAGE_PATH environment variable
  • Permissions: 600 (owner read/write only)

Log Output

[Copilot Auth] Starting device flow authorization
[Copilot Auth] Device flow initiated successfully
βœ… Model gpt-4o is available
❌ Model claude-3-5-sonnet-20241022 is not available

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests if applicable
  5. Ensure builds pass: npm run build
  6. Commit changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Submit a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • GitHub Copilot - For the amazing AI assistance
  • OpenCode - For authentication patterns and architecture inspiration
  • VS Code Team - For OAuth client ID reference implementation
  • Node.js Community - For excellent tooling and libraries

πŸ“ž Support

  • πŸ› Bug Reports: GitHub Issues
  • πŸ’‘ Feature Requests: GitHub Discussions
  • πŸ“– Documentation: Check the /docs folder
  • ❓ Questions: Use /help command in the CLI

Made with ❀️ for developers who love the terminal

Star ⭐ this repo if you find it useful!

About

A powerful terminal-based chat application that integrates with GitHub Copilot using real OAuth device flow authentication and dynamic model discovery.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •