feat: 添加环境变量写入功能
- Claude Code: 写入 ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN - Codex: 写入 OPENAI_API_KEY, OPENAI_BASE_URL - Bash 脚本: 自动检测 shell 配置文件 (.bashrc/.zshrc/.profile) - PowerShell 脚本: 使用 [Environment]::SetEnvironmentVariable 设置用户环境变量 - 添加 API key 格式验证 - 修复文件末尾换行问题,使用单引号包裹值更安全 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,19 @@ $DefaultBaseUrl = "https://api2.xcodecli.com"
|
||||
$ClaudeConfigDir = "$env:USERPROFILE\.claude"
|
||||
$ClaudeSettingsFile = "$ClaudeConfigDir\settings.json"
|
||||
|
||||
# Function to write environment variable (User level)
|
||||
function Set-EnvVariable {
|
||||
param(
|
||||
[string]$Name,
|
||||
[string]$Value
|
||||
)
|
||||
# Set for current session
|
||||
[Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::Process)
|
||||
# Set permanently for user
|
||||
[Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::User)
|
||||
Write-Info "Environment variable set: $Name"
|
||||
}
|
||||
|
||||
# Color functions for output
|
||||
function Write-Info {
|
||||
param([string]$Message)
|
||||
@@ -165,7 +178,7 @@ function New-Settings {
|
||||
[string]$BaseUrl,
|
||||
[string]$ApiKey
|
||||
)
|
||||
|
||||
|
||||
$settings = @{
|
||||
env = @{
|
||||
ANTHROPIC_BASE_URL = $BaseUrl
|
||||
@@ -175,7 +188,7 @@ function New-Settings {
|
||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$json = $settings | ConvertTo-Json -Depth 10
|
||||
Set-Content -Path $ClaudeSettingsFile -Value $json -Encoding UTF8
|
||||
@@ -186,6 +199,13 @@ function New-Settings {
|
||||
$configJson = @{ primaryApiKey = "xcodecli" }
|
||||
$configJson | ConvertTo-Json | Set-Content -Path $configJsonPath -Encoding UTF8
|
||||
Write-Success "VSCode Claude config written to: $configJsonPath"
|
||||
|
||||
# Set environment variables
|
||||
Write-Info "Setting environment variables..."
|
||||
Set-EnvVariable -Name "ANTHROPIC_BASE_URL" -Value $BaseUrl
|
||||
Set-EnvVariable -Name "ANTHROPIC_AUTH_TOKEN" -Value $ApiKey
|
||||
Write-Success "Environment variables configured"
|
||||
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
|
||||
Reference in New Issue
Block a user