griffinmartin/opencode-claude-auth

OpenCode plugin that uses your existing Claude Code credentials — no separate login needed.

What it solves

This project provides a way for OpenCode users to authenticate with the Anthropic API using their existing Claude Code credentials. It eliminates the need for separate API keys or manual login processes by leveraging the OAuth tokens already stored on the user's system.

How it works

The plugin acts as an authentication provider for OpenCode. It intercepts Anthropic API requests and attaches the necessary OAuth tokens. These tokens are retrieved from the macOS Keychain or a local credentials file on Linux and Windows.

To keep the session active, the plugin handles token refreshes automatically: it first attempts a direct refresh via Anthropic's OAuth endpoint and falls back to the calling the claude CLI if necessary. On macOS, it can detect and switch between multiple authenticated Claude Code accounts based on their subscription tier.

Who it’s for

Users of OpenCode who already have Claude Code installed and authenticated on their machines and want a seamless, single-sign-on experience without managing separate API keys.

Highlights

  • Automatic Credential Discovery: Automatically finds tokens in the macOS Keychain or ~/.claude/.credentials.json.
  • Zero-Config Setup: Once installed, it handles authentication and token refreshing in the background.
  • Multi-Account Support: Detects multiple Claude Code accounts on macOS and allows switching via opencode auth login.
  • Direct OAuth Refresh: Refreshes tokens via API calls to avoid consuming LLM tokens.
  • Robust Error Handling: Implements exponential backoff for rate limits (429) and automatic recovery for expired tokens (401).

Related

  • Project
  • Dispatch
  • Project
  • Project