opencode-claude-auth  by griffinmartin

Seamless Anthropic API authentication for OpenCode

Created 1 week ago

New!

581 stars

Top 55.7% on SourcePulse

GitHubView on GitHub
Project Summary

This plugin provides seamless integration for OpenCode users by leveraging existing Claude Code credentials, eliminating the need for separate API keys or logins. It targets developers and power users of AI coding assistants who utilize both OpenCode and Anthropic's Claude models, offering a convenient way to manage authentication automatically. The primary benefit is a streamlined workflow, allowing users to access Claude models within OpenCode without manual setup or credential management.

How It Works

The plugin operates by registering a custom authentication provider within OpenCode. This provider intercepts all Anthropic API requests, extracts OAuth tokens from the macOS Keychain or a local credentials file (~/.claude/.credentials.json), and caches them in memory with a 30-second Time-To-Live (TTL). It handles the full request lifecycle, including injecting necessary headers like beta flags and user-agent strings, and translates tool names between OpenCode and the Anthropic API. When tokens approach expiry, it automatically triggers a refresh using the Claude CLI.

Quick Start & Requirements

  • Installation: Install globally via npm: npm install -g opencode-claude-auth. Then, add "opencode-claude-auth" to the plugin array in your opencode.json configuration. An alternative installation method involves fetching a script: Fetch https://raw.githubusercontent.com/griffinmartin/opencode-claude-auth/main/installation.md.
  • Prerequisites: Claude Code must be installed and authenticated (run claude at least once). OpenCode must also be installed.
  • Platform Notes: macOS is preferred due to its use of the Keychain. Linux and Windows are supported via the ~/.claude/.credentials.json fallback mechanism.
  • Relevant Links: Installation script: https://raw.githubusercontent.com/griffinmartin/opencode-claude-auth/main/installation.md

Highlighted Details

  • Supports 15 different Claude models, including various versions of Haiku, Sonnet, and Opus.
  • Credentials are synced to OpenCode's auth.json every 5 minutes as a fallback.
  • Handles API request retries for rate limiting (429) and server errors (529) with exponential backoff.
  • Injects Claude Code identity into system prompts via experimental experimental.chat.system.transform.

Maintenance & Community

No specific details regarding maintainers, community channels (like Discord or Slack), or project roadmaps are provided in the README.

Licensing & Compatibility

The project is licensed under the MIT license, which generally permits commercial use and integration into closed-source projects. However, a disclaimer notes potential conflicts with Anthropic's Terms of Service regarding the use of Claude Pro/Max subscription tokens.

Limitations & Caveats

This plugin relies on community workaround methods for authentication, utilizing Claude Code's OAuth tokens. Anthropic's Terms of Service suggest these tokens should only be used with official Anthropic clients, meaning this plugin may cease to function if Anthropic modifies its OAuth infrastructure. Users should proceed with discretion, acknowledging the potential for breakage. Authentication requires Claude Code to be installed and functional first.

Health Check
Last Commit

1 day ago

Responsiveness

Inactive

Pull Requests (30d)
85
Issues (30d)
27
Star History
589 stars in the last 12 days

Explore Similar Projects

Feedback? Help us improve.