Claude Auth

在 OpenCode 中使用現有的 Claude Code 憑證 — 無需單獨登入或 API 金鑰,token 由 Keychain 託管

本頁內文若連結到尚未提供繁體版本的頁面(例如 /ecosystem/plugins/、/news/),會開啟英文原頁;導覽與頁尾標有 EN 的項目即為這類頁面。

Claude Auth 透過自定義的 fetch 處理器註冊自己的 Anthropic 認證供應商,攔截所有 Anthropic API 請求,並使用你的 Claude Code 憑證。

核心特性

特性說明
無需單獨的 API 金鑰複用 Claude Code 安裝目錄中的 OAuth token
Keychain 優先從 macOS Keychain 讀取;在其他平台回退到 ~/.claude/.credentials.json(遵循 $CLAUDE_CONFIG_DIR)
30 秒 TTL 快取token 快取在記憶體中;即將過期的 token 透過 Anthropic OAuth 端點重新整理(不消耗 LLM token)
多帳號(macOS)自動檢測多個 Claude Code 帳號;透過 opencode auth login 切換
auth.json 回退憑證同步到 OpenCode 的 auth.json;在 Windows 上會寫入兩個已知位置
後台重新同步每 5 分鐘一次;直接重新整理失敗時回退到 Claude CLI

前置條件

  • 已安裝並登入 Claude Code(至少執行過一次 claude)
  • 已安裝 OpenCode
  • 推薦 macOS(Keychain);Linux 和 Windows 透過憑證檔案回退方案工作

安裝

把外掛新增到 ~/.config/opencode/opencode.json:

{
  "plugins": ["opencode-claude-auth@latest"]
}