function cc { param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs) # 颜色表(常用后缀高亮,其他白色) $colorMap = @{ mscope = 'Cyan'; streamlake = 'Magenta'; opendevin = 'Green'; deepseek = 'Yellow' groq = 'DarkCyan'; together = 'DarkMagenta'; azure = 'Blue'; openrouter = 'DarkGreen' deepinfra = 'Red'; ollama = 'DarkYellow'; lmstudio = 'White'; local = 'Gray' } $selected = $env:CLAUDE_DEFAULT $actualArgs = @() for($i=0; $i -lt $UserArgs.Count; $i++) { $arg = $UserArgs[$i] # 支持 cc modescope(无 -)和 cc -mscope 两种写法 if ($arg -match '^-?(.+)$') { $selected = $matches[1] continue } $actualArgs += $arg } # 构建 settings 路径 $defaultFile = "$HOME\.claude\settings.json" $selectedFile = if ($selected) { "$HOME\.claude\settings.json-$selected" } else { $defaultFile } # 检查文件是否存在,不存在则不传 --settings(避免报错) if ($selected -and -not (Test-Path $selectedFile)) { Write-Host "警告:配置文件不存在 $selectedFile,使用默认配置" -ForegroundColor Yellow $settings = $defaultFile if (-not (Test-Path $defaultFile)) { $settings = $null } # 连默认都没有 } elseif (-not (Test-Path $defaultFile)) { $settings = $null } else { $settings = $selectedFile } # 构建命令 $cmd = @('claude') if ($settings) { $cmd += '--settings', $settings } $cmd += $actualArgs # 显示命令(美化) $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } $color = if ($colorMap.ContainsKey($selected)) { $colorMap[$selected] } else { 'White' } $disp = if ($selected) { "($selected)" } else { "(default)" } Write-Host "Executing cc $disp → $cmdStr" -ForegroundColor $color # 执行 if ($settings) { & claude --settings $settings @actualArgs } else { & claude @actualArgs } }