A powerful terminal-based chat application that integrates with GitHub Copilot using real OAuth device flow authentication and dynamic model discovery.
- π 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
- Node.js 18+
- GitHub account with Copilot access
- Terminal with color support
# 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# Start the application
npm run dev
# Authenticate with GitHub Copilot
/auth
# Start chatting!
Hello, can you help me write a Python function?- Start the app:
npm run dev - Authenticate: Use
/authcommand - Visit GitHub: Go to the provided URL
- Enter code: Input the device code shown
- Start chatting: Begin your conversation!
| 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 |
π 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
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
- Model: First available model (auto-detected)
- Temperature: 0.7
- Max Tokens: 2000
- Cache Timeout: 5 minutes
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β CLI Interface β ββ β GitHub Copilot β ββ β Authentication β
β β β Provider β β Manager β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Chat Session β β Model Discovery β β Token Storage β
β Management β β & Caching β β & Refresh β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
- Device Code Request β GitHub OAuth endpoint
- User Authorization β GitHub web interface
- Token Exchange β GitHub Copilot API token
- Secure Storage β Encrypted local storage
- Auto Refresh β Seamless token renewal
- API Endpoint β
https://api.githubcopilot.com/models - Model Testing β Test known model availability
- Caching β 5-minute intelligent cache
- Fallback β Minimal working model set
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 artifactssrc/
βββ 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
# Clone and setup
git clone <repository-url>
cd copilot-cli-chat
npm install
# Development
npm run dev
# Production build
npm run build
npm startProblem: GitHub Copilot authentication required
- Solution: Run
/authto authenticate - Check: Ensure you have GitHub Copilot access
- Debug: Set
DEBUG_COPILOT_AUTH=truein.env
Problem: Token exchange failed
- Solution: Try
/logoutthen/authagain - Check: Verify internet connection
- Info: Tokens expire and need refresh
Problem: No models currently available
- Solution: Run
/refreshto refresh models - Check: Verify Copilot subscription is active
- Fallback: App uses default models if discovery fails
Problem: Model not found error
- Solution: Use
/modelsto see available models - Check: Set model with
/model <model-name> - Info: Models vary by Copilot subscription
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
Problem: tsx: not found
- Solution: Run
npm installto install dependencies - Check: Ensure Node.js 18+ is installed
Problem: TypeScript compilation errors
- Solution: Run
npm run type-checkfor details - Fix: Update code to match TypeScript requirements
Enable detailed logging:
# In .env file
DEBUG_COPILOT_AUTH=true
# Run with debug output
npm run devAuthentication data is stored securely at:
- Default:
~/.copilot-cli/auth.json - Custom: Set
AUTH_STORAGE_PATHenvironment variable - Permissions: 600 (owner read/write only)
[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 availableWe welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests if applicable
- Ensure builds pass:
npm run build - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Submit a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Discussions
- π Documentation: Check the
/docsfolder - β Questions: Use
/helpcommand in the CLI
Made with β€οΈ for developers who love the terminal
Star β this repo if you find it useful!