Skip to content

Add GitHub Copilot provider support#4

Merged
notlikejuice merged 1 commit intomainfrom
codex/add-github-copilot-support-to-codex-cli
Jun 15, 2025
Merged

Add GitHub Copilot provider support#4
notlikejuice merged 1 commit intomainfrom
codex/add-github-copilot-support-to-codex-cli

Conversation

@notlikejuice
Copy link
Owner

Summary

  • handle login via GitHub device flow
  • save Copilot token in auth.json
  • create GithubCopilotClient for Copilot API requests
  • initialize Copilot client in agent loop
  • expose githubcopilot provider configuration

Testing

  • pnpm --filter @openai/codex run format
  • pnpm --filter @openai/codex run lint
  • pnpm --filter @openai/codex run test (fails: Process with PID XXXX failed to terminate within 500ms)

https://chatgpt.com/codex/tasks/task_e_684f272bac248326a07facb43efee33f

Copilot AI review requested due to automatic review settings June 15, 2025 20:15
@notlikejuice notlikejuice merged commit 2f06611 into main Jun 15, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for GitHub Copilot as a provider by implementing device flow login, token persistence, a dedicated Copilot client, and integrating it into the CLI and agent loop.

  • Introduced GithubCopilotClient for handling Copilot API authentication and requests
  • Added device-flow login in get-api-key and updated CLI to persist GITHUBCOPILOT_API_KEY
  • Registered the new provider in providers.ts and initialized the client in agent-loop.ts

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
codex-cli/src/utils/providers.ts Updated provider list with GitHub Copilot entry
codex-cli/src/utils/openai-client.ts Added GithubCopilotClient class and token-management logic
codex-cli/src/utils/get-api-key.tsx Implemented getGithubCopilotApiKey for device-flow login
codex-cli/src/utils/agent/agent-loop.ts Initialized GithubCopilotClient in the agent loop
codex-cli/src/cli.tsx Integrated Copilot login flow, auth file persistence, and env handling
Comments suppressed due to low confidence (3)

codex-cli/src/utils/providers.ts:56

  • [nitpick] Use the official branding 'GitHubCopilot' (capital 'H' in 'Hub') for the provider name to match GitHub’s naming.
name: "GithubCopilot",

codex-cli/src/utils/providers.ts:58

  • [nitpick] Consider using 'GITHUB_COPILOT_API_KEY' with an underscore for readability and to stay consistent with other environment variable names.
envKey: "GITHUBCOPILOT_API_KEY",

codex-cli/src/utils/providers.ts:57

baseURL: "https://api.githubcopilot.com",

>(headers: T): T {
const copy = { ...headers } as Record<string, string> & T;
copy["User-Agent"] = "GithubCopilot/1.155.0";
copy["editor-version"] = "vscode/1.85.1";
Copy link

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The 'editor-version' header is hardcoded to a VSCode plugin version; consider reflecting the CLI’s version or making this header configurable.

Copilot uses AI. Check for mistakes.
}

if (cli.flags.login) {
if (provider.toLowerCase() === "githubcopilot" && !apiKey) {
Copy link

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block triggers the Copilot login flow unconditionally when no key is present, even without the '--login' flag; consider guarding it under 'cli.flags.login' to avoid unexpected prompts.

Suggested change
if (provider.toLowerCase() === "githubcopilot" && !apiKey) {
if (provider.toLowerCase() === "githubcopilot" && !apiKey && cli.flags.login) {

Copilot uses AI. Check for mistakes.
});
}

if (this.provider.toLowerCase() === "githubcopilot") {
Copy link

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The GitHub Copilot client initialization mirrors logic in 'createOpenAIClient'; consider refactoring to reuse the factory for consistency and to reduce duplication.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant