feat: add support for GitHub Models provider

- Introduced environment variable CLAUDE_CODE_USE_GITHUB to enable GitHub Models.
- Added checks for GITHUB_TOKEN or GH_TOKEN for authentication.
- Updated base URL handling to include GitHub Models default.
- Enhanced provider detection and error handling for GitHub Models.
- Updated relevant functions and components to accommodate the new provider.
This commit is contained in:
Rithul Kamesh
2026-04-02 11:25:28 +05:30
parent e54c39e3cb
commit 25c5987276
24 changed files with 1069 additions and 42 deletions

View File

@@ -46,7 +46,22 @@ function isLocalProviderUrl(baseUrl: string | undefined): boolean {
}
function validateProviderEnvOrExit(): void {
if (!isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI)) {
const useOpenAI = isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI)
const useGithub = isEnvTruthy(process.env.CLAUDE_CODE_USE_GITHUB)
if (useGithub && !useOpenAI) {
const token =
(process.env.GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim()) ?? ''
if (!token) {
console.error(
'GITHUB_TOKEN or GH_TOKEN is required when CLAUDE_CODE_USE_GITHUB=1.',
)
process.exit(1)
}
return
}
if (!useOpenAI) {
return
}
@@ -77,8 +92,15 @@ function validateProviderEnvOrExit(): void {
}
if (!process.env.OPENAI_API_KEY && !isLocalProviderUrl(request.baseUrl)) {
console.error('OPENAI_API_KEY is required when CLAUDE_CODE_USE_OPENAI=1 and OPENAI_BASE_URL is not local.')
process.exit(1)
const hasGithubToken = !!(
process.env.GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim()
)
if (!(useGithub && hasGithubToken)) {
console.error(
'OPENAI_API_KEY is required when CLAUDE_CODE_USE_OPENAI=1 and OPENAI_BASE_URL is not local. When CLAUDE_CODE_USE_GITHUB=1, GITHUB_TOKEN or GH_TOKEN may be used instead.',
)
process.exit(1)
}
}
}
@@ -98,6 +120,15 @@ async function main(): Promise<void> {
return;
}
{
const { enableConfigs } = await import('../utils/config.js')
enableConfigs()
const { applySafeConfigEnvironmentVariables } = await import('../utils/managedEnv.js')
applySafeConfigEnvironmentVariables()
const { hydrateGithubModelsTokenFromSecureStorage } = await import('../utils/githubModelsCredentials.js')
hydrateGithubModelsTokenFromSecureStorage()
}
validateProviderEnvOrExit()
// Print the gradient startup screen before the Ink UI loads