Lumoswitch 文档
Agent 接入

GitHub Copilot CLI 接入

GitHub Copilot CLI 是 GitHub 的终端编码 Agent,可以理解代码库、修改文件、运行命令并调用工具。它的 BYOK 模式支持 OpenAI Chat Completions-compatible 端点,因此可以把 Agent 请求交给 Lumoswitch。

配置 API 必须启用 OpenAI-compatible 输出,目标模型至少应支持流式输出与 Tool / Function Calling;GitHub 建议上下文窗口不低于 128K。以下 CLI 命令适用于 macOS、Linux 的 Bash / Zsh;开始前请确认 copilot --version 能返回版本号。

方式总览

方式适合什么情况会写入什么退出后是否保留
仅本次启动测试地址、Key 或模型不写 Copilot CLI 配置
永久使用日常从终端启动用户级 BYOK 环境与可选维护启动器
Copilot app / IDE / GitHub Desktop使用对应图形界面由各应用单独保存 BYOK 提供方

CLI 与 Copilot 的图形界面是不同的启动入口。CLI 环境变量不会自动成为 Copilot app、原生 IDE 聊天或 GitHub Desktop 的设置,图形界面也没有等价的“仅本次启动”命令,原因见下文。

准备连接信息

占位符应填写的内容
{{api_base_url}}配置 API 显示的 OpenAI-compatible 请求地址,应以 /v1 结尾
{{access_key}}配置 API 的 Access Key
{{model}}配置 API 显示的下游模型名称
{{copilot_reasoning_effort}}默认模型可安全使用的推理档位;不应发送时为空

从控制台复制的命令会自动填入真实值。{{copilot_reasoning_effort}} 为空时命令不会发送 --effort;不要手动用一个固定档位覆盖所有模型。

仅本次启动

这条命令只给新启动的 Copilot CLI 进程传入 Lumoswitch 配置。退出后立即失效,不会污染当前终端,也不会修改 Copilot 原有设置。

(
  set -e
  LUMOSWITCH_COPILOT_REASONING_EFFORT="{{copilot_reasoning_effort}}"
  set --
  if [ -n "$LUMOSWITCH_COPILOT_REASONING_EFFORT" ]; then
    set -- --effort "$LUMOSWITCH_COPILOT_REASONING_EFFORT"
  fi
  env \
    COPILOT_PROVIDER_TYPE="openai" \
    COPILOT_PROVIDER_BASE_URL="{{api_base_url}}" \
    COPILOT_PROVIDER_API_KEY="{{access_key}}" \
    COPILOT_MODEL="{{model}}" \
    COPILOT_OFFLINE="true" \
    copilot "$@"
)

BYOK 模式不要求先登录 GitHub。COPILOT_OFFLINE=true 会阻止当前进程为了仓库集成等附加能力连接 GitHub;需要这些在线能力时,可从导入模板和受管环境中删除这一项。

永久使用

首次设置,或 Lumoswitch 地址、Access Key、模型发生变化时,运行下面的完整命令。它会写入 Copilot 支持的用户级 BYOK 环境,不覆盖其他 Copilot 配置,并保存可选的 Lumoswitch 维护启动器。

永久导入会把 Access Key 保存到仅当前用户可读的受管环境或 Agent 配置文件中。请只在可信的个人设备上使用。

set -e
LUMOSWITCH_ROOT="$HOME/.config/lumoswitch/agents/github-copilot-cli"
LUMOSWITCH_ENV="$LUMOSWITCH_ROOT/env.sh"
LUMOSWITCH_LAUNCHER="$HOME/.local/bin/lumoswitch-github-copilot-cli"
mkdir -p "$LUMOSWITCH_ROOT" "$(dirname "$LUMOSWITCH_LAUNCHER")"
umask 077

if [ -f "$LUMOSWITCH_LAUNCHER" ]; then
  LUMOSWITCH_BACKUP="$LUMOSWITCH_LAUNCHER.backup.$(date +%Y%m%d-%H%M%S)-$$"
  cp "$LUMOSWITCH_LAUNCHER" "$LUMOSWITCH_BACKUP"
  chmod 600 "$LUMOSWITCH_BACKUP"
fi

:

cat > "$LUMOSWITCH_ENV" <<'LUMOSWITCH_ENV_EOF'
export COPILOT_PROVIDER_TYPE="openai"
export COPILOT_PROVIDER_BASE_URL="{{api_base_url}}"
export COPILOT_PROVIDER_API_KEY="{{access_key}}"
export COPILOT_MODEL="{{model}}"
export COPILOT_OFFLINE="true"
LUMOSWITCH_ENV_EOF

case "$SHELL" in
  */zsh) LUMOSWITCH_PROFILE="$HOME/.zshrc" ;;
  */bash) LUMOSWITCH_PROFILE="$HOME/.bashrc" ;;
  *) LUMOSWITCH_PROFILE="$HOME/.profile" ;;
esac
touch "$LUMOSWITCH_PROFILE"
LUMOSWITCH_PROFILE_MARKER='# Lumoswitch Agent: github-copilot-cli'
LUMOSWITCH_SOURCE_LINE='[ -f "$HOME/.config/lumoswitch/agents/github-copilot-cli/env.sh" ] && . "$HOME/.config/lumoswitch/agents/github-copilot-cli/env.sh"'
if ! grep -Fqx "$LUMOSWITCH_SOURCE_LINE" "$LUMOSWITCH_PROFILE"; then
  printf '\n%s\n%s\n' "$LUMOSWITCH_PROFILE_MARKER" "$LUMOSWITCH_SOURCE_LINE" >> "$LUMOSWITCH_PROFILE"
fi
printf '%s\n' "$LUMOSWITCH_PROFILE" > "$LUMOSWITCH_ROOT/profile-path"

cat > "$LUMOSWITCH_LAUNCHER" <<'LUMOSWITCH_LAUNCHER_EOF'
#!/usr/bin/env bash
set -e
LUMOSWITCH_ROOT="$HOME/.config/lumoswitch/agents/github-copilot-cli"
LUMOSWITCH_ENV="$LUMOSWITCH_ROOT/env.sh"
LUMOSWITCH_LAUNCHER="$HOME/.local/bin/lumoswitch-github-copilot-cli"

if [ "$1" = "--lumoswitch-clean" ]; then
  if [ -f "$LUMOSWITCH_ROOT/profile-path" ]; then
    LUMOSWITCH_PROFILE="$(cat "$LUMOSWITCH_ROOT/profile-path")"
    if [ -f "$LUMOSWITCH_PROFILE" ]; then
      LUMOSWITCH_PROFILE_MARKER='# Lumoswitch Agent: github-copilot-cli'
      LUMOSWITCH_SOURCE_LINE='[ -f "$HOME/.config/lumoswitch/agents/github-copilot-cli/env.sh" ] && . "$HOME/.config/lumoswitch/agents/github-copilot-cli/env.sh"'
      LUMOSWITCH_PROFILE_TMP="$LUMOSWITCH_PROFILE.lumoswitch.$$"
      awk -v marker="$LUMOSWITCH_PROFILE_MARKER" -v source="$LUMOSWITCH_SOURCE_LINE" '$0 != marker && $0 != source' "$LUMOSWITCH_PROFILE" > "$LUMOSWITCH_PROFILE_TMP"
      mv "$LUMOSWITCH_PROFILE_TMP" "$LUMOSWITCH_PROFILE"
    fi
  fi
  if [ -d "$LUMOSWITCH_ROOT" ]; then
    find "$LUMOSWITCH_ROOT" -depth \( -type f -o -type l \) -delete
    find "$LUMOSWITCH_ROOT" -depth -type d -exec rmdir {} \; 2>/dev/null || true
  fi
  find "$(dirname "$LUMOSWITCH_LAUNCHER")" -maxdepth 1 -type f -name 'lumoswitch-github-copilot-cli.backup.*' -delete
  rm -f "$LUMOSWITCH_LAUNCHER"
  printf '%s\n' 'Lumoswitch native setup and optional launcher removed. Open a new terminal to refresh the environment.'
  exit 0
fi

if [ -f "$LUMOSWITCH_ENV" ]; then . "$LUMOSWITCH_ENV"; fi
exec copilot "$@"
LUMOSWITCH_LAUNCHER_EOF

chmod 600 "$LUMOSWITCH_ENV"
find "$LUMOSWITCH_ROOT" -type f -exec chmod 600 {} \;
chmod 700 "$LUMOSWITCH_LAUNCHER"
. "$LUMOSWITCH_ENV"
printf '%s\n' 'Native Lumoswitch setup saved. Future command: copilot'
printf '%s\n' 'Optional maintenance launcher: ~/.local/bin/lumoswitch-github-copilot-cli'
copilot

以后从终端启动时只需运行:

copilot

可以在命令末尾继续传入 Copilot CLI 参数。更新启动器前会保留一个带时间戳、权限为 0600 的现有启动器备份。

Windows PowerShell 原生导入

以下命令在 Windows PowerShell 中原生运行,不需要 WSL。它们与本页的 macOS/Linux 模板使用同一组连接值。

仅本次使用(Windows)

& {
  $ErrorActionPreference = 'Stop'
  $lumoswitchEnvironmentNames = @('COPILOT_MODEL', 'COPILOT_OFFLINE', 'COPILOT_PROVIDER_API_KEY', 'COPILOT_PROVIDER_BASE_URL', 'COPILOT_PROVIDER_TYPE')
  $lumoswitchPreviousEnvironment = @{}
  foreach ($lumoswitchName in $lumoswitchEnvironmentNames) {
    $lumoswitchPreviousEnvironment[$lumoswitchName] = [Environment]::GetEnvironmentVariable($lumoswitchName, 'Process')
  }
  $lumoswitchExitCode = 0
  try {
    [Environment]::SetEnvironmentVariable('COPILOT_MODEL', '{{model}}', 'Process')
    [Environment]::SetEnvironmentVariable('COPILOT_OFFLINE', 'true', 'Process')
    [Environment]::SetEnvironmentVariable('COPILOT_PROVIDER_API_KEY', '{{access_key}}', 'Process')
    [Environment]::SetEnvironmentVariable('COPILOT_PROVIDER_BASE_URL', '{{api_base_url}}', 'Process')
    [Environment]::SetEnvironmentVariable('COPILOT_PROVIDER_TYPE', 'openai', 'Process')
    $lumoswitchArguments = @()
    if ('{{copilot_reasoning_effort}}') { $lumoswitchArguments += @('--effort', '{{copilot_reasoning_effort}}') }
    $lumoswitchExecutable = Get-Command 'copilot.cmd' -CommandType Application -ErrorAction SilentlyContinue
    if ($null -eq $lumoswitchExecutable) { $lumoswitchExecutable = Get-Command 'copilot' -CommandType Application -ErrorAction Stop }
    & $lumoswitchExecutable.Path @lumoswitchArguments
    if ($null -ne $LASTEXITCODE) { $lumoswitchExitCode = $LASTEXITCODE }
  } finally {
    foreach ($lumoswitchName in $lumoswitchEnvironmentNames) {
      [Environment]::SetEnvironmentVariable($lumoswitchName, $lumoswitchPreviousEnvironment[$lumoswitchName], 'Process')
    }
  }
  if ($lumoswitchExitCode -ne 0) { throw 'copilot exited with code ' + $lumoswitchExitCode }
}

永久使用(Windows)

该命令会备份已有的 Lumoswitch 专用文件,并为配置和启动器收紧当前用户的访问权限。

& {
  $ErrorActionPreference = 'Stop'
  $lumoswitchRoot = Join-Path $env:LOCALAPPDATA 'Lumoswitch\agents\github-copilot-cli'
  $lumoswitchLauncher = Join-Path $env:LOCALAPPDATA 'Lumoswitch\bin\lumoswitch-github-copilot-cli.ps1'
  $lumoswitchBackupSuffix = (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + $PID

  function Protect-LumoswitchFile([string] $Path) {
    $lumoswitchSid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
    & icacls.exe $Path '/inheritance:r' '/grant:r' ('*' + $lumoswitchSid + ':(F)') '*S-1-5-18:(F)' '*S-1-5-32-544:(F)' | Out-Null
    if ($LASTEXITCODE -ne 0) { throw "Could not restrict access to $Path" }
  }

  function Install-LumoswitchFile([string] $Path, [string] $Content) {
    [IO.Directory]::CreateDirectory((Split-Path -Parent $Path)) | Out-Null
    if (Test-Path -LiteralPath $Path) {
      $lumoswitchItem = Get-Item -LiteralPath $Path -Force
      if ($lumoswitchItem.PSIsContainer -or ($lumoswitchItem.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
        throw "Lumoswitch refused to replace a directory or link: $Path"
      }
      $lumoswitchBackup = $Path + '.backup.' + $lumoswitchBackupSuffix
      Copy-Item -LiteralPath $Path -Destination $lumoswitchBackup
      Protect-LumoswitchFile $lumoswitchBackup
    }
    $lumoswitchTemporary = $Path + '.' + [Guid]::NewGuid().ToString('N') + '.tmp'
    try {
      [IO.File]::WriteAllText($lumoswitchTemporary, $Content, [Text.UTF8Encoding]::new($false))
      Move-Item -LiteralPath $lumoswitchTemporary -Destination $Path -Force
      Protect-LumoswitchFile $Path
    } finally {
      Remove-Item -LiteralPath $lumoswitchTemporary -Force -ErrorAction SilentlyContinue
    }
  }

  [IO.Directory]::CreateDirectory($lumoswitchRoot) | Out-Null
  # No Agent configuration file is required.

  $lumoswitchEnvironment = [ordered]@{}
  $lumoswitchEnvironment['COPILOT_PROVIDER_TYPE'] = 'openai'
  $lumoswitchEnvironment['COPILOT_PROVIDER_BASE_URL'] = '{{api_base_url}}'
  $lumoswitchEnvironment['COPILOT_PROVIDER_API_KEY'] = '{{access_key}}'
  $lumoswitchEnvironment['COPILOT_MODEL'] = '{{model}}'
  $lumoswitchEnvironment['COPILOT_OFFLINE'] = 'true'
  foreach ($lumoswitchEntry in $lumoswitchEnvironment.GetEnumerator()) {
    [Environment]::SetEnvironmentVariable($lumoswitchEntry.Key, $lumoswitchEntry.Value, 'User')
    [Environment]::SetEnvironmentVariable($lumoswitchEntry.Key, $lumoswitchEntry.Value, 'Process')
  }

  $lumoswitchLauncherContent = @'
param([Parameter(ValueFromRemainingArguments = $true)][string[]] $AgentArgs)
$ErrorActionPreference = 'Stop'
$lumoswitchRoot = Join-Path $env:LOCALAPPDATA 'Lumoswitch\agents\github-copilot-cli'
$lumoswitchLauncher = Join-Path $env:LOCALAPPDATA 'Lumoswitch\bin\lumoswitch-github-copilot-cli.ps1'

function Remove-LumoswitchFile([string] $Path) {
  if (-not (Test-Path -LiteralPath $Path)) { return }
  $lumoswitchItem = Get-Item -LiteralPath $Path -Force
  if ($lumoswitchItem.PSIsContainer -or ($lumoswitchItem.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
    throw "Lumoswitch refused to remove a directory or link: $Path"
  }
  Remove-Item -LiteralPath $Path -Force
}

if ($AgentArgs.Count -gt 0 -and $AgentArgs[0] -eq '--lumoswitch-clean') {
  foreach ($lumoswitchName in @('COPILOT_PROVIDER_TYPE', 'COPILOT_PROVIDER_BASE_URL', 'COPILOT_PROVIDER_API_KEY', 'COPILOT_MODEL', 'COPILOT_OFFLINE')) {
    [Environment]::SetEnvironmentVariable($lumoswitchName, $null, 'User')
    [Environment]::SetEnvironmentVariable($lumoswitchName, $null, 'Process')
  }
  if (Test-Path -LiteralPath $lumoswitchRoot -PathType Container) {
    $lumoswitchRootItem = Get-Item -LiteralPath $lumoswitchRoot -Force
    if ($lumoswitchRootItem.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'Lumoswitch refused to clean through a linked directory.' }
    foreach ($lumoswitchFile in @(Get-ChildItem -LiteralPath $lumoswitchRoot -File -Recurse -Force)) { Remove-LumoswitchFile $lumoswitchFile.FullName }
    foreach ($lumoswitchDirectory in @(Get-ChildItem -LiteralPath $lumoswitchRoot -Directory -Recurse -Force | Sort-Object FullName -Descending)) {
      if ($null -eq (Get-ChildItem -LiteralPath $lumoswitchDirectory.FullName -Force | Select-Object -First 1)) { Remove-Item -LiteralPath $lumoswitchDirectory.FullName -Force }
    }
    if ($null -eq (Get-ChildItem -LiteralPath $lumoswitchRoot -Force | Select-Object -First 1)) { Remove-Item -LiteralPath $lumoswitchRoot -Force }
  }
  $lumoswitchBin = Split-Path -Parent $lumoswitchLauncher
  if (Test-Path -LiteralPath $lumoswitchBin -PathType Container) {
    foreach ($lumoswitchBackup in @(Get-ChildItem -LiteralPath $lumoswitchBin -Filter 'lumoswitch-github-copilot-cli.ps1.backup.*' -File -Force)) { Remove-LumoswitchFile $lumoswitchBackup.FullName }
  }
  Remove-LumoswitchFile $lumoswitchLauncher
  Write-Host 'Lumoswitch native setup and optional launcher removed. Open a new terminal to refresh the environment.'
  exit 0
}

$lumoswitchEnvironment = [ordered]@{}
$lumoswitchEnvironment['COPILOT_PROVIDER_TYPE'] = 'openai'
$lumoswitchEnvironment['COPILOT_PROVIDER_BASE_URL'] = '{{api_base_url}}'
$lumoswitchEnvironment['COPILOT_PROVIDER_API_KEY'] = '{{access_key}}'
$lumoswitchEnvironment['COPILOT_MODEL'] = '{{model}}'
$lumoswitchEnvironment['COPILOT_OFFLINE'] = 'true'
foreach ($lumoswitchEntry in $lumoswitchEnvironment.GetEnumerator()) {
  [Environment]::SetEnvironmentVariable($lumoswitchEntry.Key, $lumoswitchEntry.Value, 'Process')
}
$lumoswitchExecutable = Get-Command 'copilot.cmd' -CommandType Application -ErrorAction SilentlyContinue
if ($null -eq $lumoswitchExecutable) { $lumoswitchExecutable = Get-Command 'copilot.exe' -CommandType Application -ErrorAction SilentlyContinue }
if ($null -eq $lumoswitchExecutable) { $lumoswitchExecutable = Get-Command 'copilot' -CommandType Application -ErrorAction Stop }
$lumoswitchArguments = @()
& $lumoswitchExecutable.Path @lumoswitchArguments @AgentArgs
if ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }
'@
  Install-LumoswitchFile $lumoswitchLauncher $lumoswitchLauncherContent
  Write-Host 'Native Lumoswitch setup saved. Future command: copilot'
  Write-Host 'Optional maintenance launcher:' $lumoswitchLauncher
  $lumoswitchExecutable = Get-Command 'copilot.cmd' -CommandType Application -ErrorAction SilentlyContinue
  if ($null -eq $lumoswitchExecutable) { $lumoswitchExecutable = Get-Command 'copilot.exe' -CommandType Application -ErrorAction SilentlyContinue }
  if ($null -eq $lumoswitchExecutable) { $lumoswitchExecutable = Get-Command 'copilot' -CommandType Application -ErrorAction Stop }
  $lumoswitchArguments = @()
  & $lumoswitchExecutable.Path @lumoswitchArguments
  if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) { throw 'copilot exited with code ' + $LASTEXITCODE }
}

导入会写入 Agent 支持的持久化配置,并直接启动 copilot。保存的 Lumoswitch 维护脚本不是启动 Agent 的必需入口;需要恢复或移除此接入时,运行它并追加 --lumoswitch-clean

清除 CLI 接入

Windows PowerShell

先退出该 Agent 的所有 Lumoswitch 会话,再运行下面的命令。可选维护启动器会删除受管原生配置、恢复已保留的共享文件、清除 Lumoswitch 用户环境变量,并移除自身。

& {
  $lumoswitchLauncher = Join-Path $env:LOCALAPPDATA 'Lumoswitch\bin\lumoswitch-github-copilot-cli.ps1'
  if (-not (Test-Path -LiteralPath $lumoswitchLauncher -PathType Leaf)) {
    throw 'The optional Lumoswitch maintenance launcher is missing. Run persistent import again before cleanup.'
  }
  & powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File $lumoswitchLauncher --lumoswitch-clean
}

macOS / Linux

下面的命令会清除 Copilot 的 Lumoswitch 用户环境,并删除可选维护启动器及其备份;它不会删除 Copilot 登录信息、历史记录或用户配置。

"$HOME/.local/bin/lumoswitch-github-copilot-cli" --lumoswitch-clean

临时命令的变量只属于 Copilot 子进程,退出后无需清理。

Copilot app、IDE 与 GitHub Desktop

当前 CLI 连接 VS Code

在已经通过本页命令启动的 Copilot CLI 内执行 /ide,可以把当前 CLI 进程连接到 VS Code。它继续使用当前 Lumoswitch 提供方,无需保存第二份凭证。这不等于修改 VS Code 原生 Copilot Chat 的模型设置。

图形界面单独接入

Copilot app、支持 BYOK 的 IDE 界面和 GitHub Desktop 需要在各自设置中选择 OpenAI-compatible 提供方,再填写 Lumoswitch 的 /v1 地址、Access Key 和下游模型名称。这类设置只提供永久保存:图形应用自己管理提供方和凭证,因此没有可靠的命令行“仅本次启动”模式。

清除 CLI 启动器不会清除这些图形界面设置。若曾在界面中添加 Lumoswitch,请在对应应用中切换提供方或删除该 BYOK 配置;GitHub Desktop 中的 Copilot 只影响提交信息、冲突解决等 Desktop 功能,并不等同于完整编码 Agent。

参见 Copilot CLI 连接 VS CodeCopilot app BYOKGitHub Desktop Copilot 配置

验证与排查

  • 仍使用默认模型:请打开新终端,让它继承持久化 BYOK 环境,再重新运行 copilot
  • 无法编辑或执行工具:候选模型可能不支持工具调用,或上下文窗口过小。
  • 返回 404:Base URL 应以 /v1 结尾,不要附加 /chat/completions
  • 模型不存在:必须使用配置 API 的下游模型名称。

参考:GitHub Copilot CLI BYOK 官方文档

维护者发布字段
  • 平台 ID:github-copilot-cli
  • 展示名称:GitHub Copilot CLI
  • 下游协议:openai-compatible
  • commandTemplate:复制「仅本次启动」代码框的完整内容
  • 永久策略:native
  • persistentCommandTemplate:复制「永久使用」代码框的完整内容
  • futureCommandcopilot
  • 展示顺序:40
  • 最近核验:2026-08-27

On this page