Skip to content

GitHub Copilot CLI 是 GitHub 推出的終端 AI 編碼代理工具,能夠理解您的程式碼庫、進行修改、執行指令,協助您更快地開發軟體。

您可以透過 Ollama 在 Copilot CLI 中使用開源模型,例如 qwen3.5glm-5.1:cloudkimi-k2.5:cloud 等。

安裝

安裝 Copilot CLI

shell
brew install copilot-cli
shell
npm install -g @github/copilot
shell
curl -fsSL https://gh.io/copilot-install | bash
powershell
winget install GitHub.Copilot

使用 Ollama 的方式

快速設定

shell
ollama launch copilot

直接指定模型執行

shell
ollama launch copilot --model kimi-k2.5:cloud

推薦模型

  • kimi-k2.5:cloud
  • glm-5:cloud
  • minimax-m2.7:cloud
  • qwen3.5:cloud
  • glm-4.7-flash
  • qwen3.5

雲端模型也可在 ollama.com/search?c=cloud 查閱。

非互動(無介面)模式

適用於 Docker、CI/CD 或腳本場景,可在無互動的情況下執行 Copilot CLI:

shell
ollama launch copilot --model kimi-k2.5:cloud --yes -- -p "how does this repository work?"

--yes 參數會自動拉取模型、跳過選擇器,且必須指定 --model 參數。-- 之後的參數會直接傳遞給 Copilot CLI。

手動設定

Copilot CLI 會透過環境變數,使用相容 OpenAI 的 API 連線至 Ollama。

  1. 設定環境變數:
shell
export COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1
export COPILOT_PROVIDER_API_KEY=
export COPILOT_PROVIDER_WIRE_API=responses
export COPILOT_MODEL=qwen3.5
  1. 執行 Copilot CLI:
shell
copilot

或者直接在指令中內嵌環境變數執行:

shell
COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 COPILOT_PROVIDER_API_KEY= COPILOT_PROVIDER_WIRE_API=responses COPILOT_MODEL=glm-5:cloud copilot

注意: Copilot 需要較大的上下文視窗,建議至少 64k tokens。您可以參考 上下文長度文件 了解如何在 Ollama 中調整上下文長度。