Claude Auth
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"]
}