opencode-anthropic-auth  by ex-machina-co

Anthropic authentication plugin for OpenCode IDE

Created 3 months ago
424 stars

Top 69.0% on SourcePulse

GitHubView on GitHub
Project Summary

This plugin integrates Anthropic's OAuth authentication into the OpenCode development environment, allowing Claude Pro/Max subscribers to utilize their existing subscriptions directly. It targets OpenCode users seeking to leverage advanced AI models without incurring additional API costs, simplifying authentication and ensuring compatibility with Anthropic's platform requirements.

How It Works

The plugin employs a PKCE OAuth flow to authenticate users with Anthropic's services. It manages the exchange of authorization codes for access and refresh tokens, automatically handling token expiration and renewal. A key feature is its system prompt sanitization, which rewrites prompts to meet Claude Code's specific identity and formatting requirements, preserving user instructions while removing or modifying specific elements like the OpenCode identity and URLs. This approach ensures seamless integration and cost-effective usage by zeroing out model costs associated with the user's subscription.

Quick Start & Requirements

To use the plugin, add it to your OpenCode configuration:

{
  "plugin": ["@ex-machina/opencode-anthropic-auth"]
}

It is strongly advised to pin the plugin version (e.g., "@ex-machina/opencode-anthropic-auth@1.7.0") to prevent unexpected automatic updates. The plugin supports three authentication methods: OAuth via claude.ai for Pro/Max users, OAuth via console.anthropic.com to create an API key, or manual API key entry. Environment variables ANTHROPIC_BASE_URL and ANTHROPIC_INSECURE can be used for proxying or skipping TLS verification. Local development can be initiated with bun run dev.

Highlighted Details

  • Enables using Claude Pro/Max subscriptions directly within OpenCode, eliminating additional API costs.
  • Automates the OAuth 2.0 flow, including token acquisition and refresh.
  • Implements robust system prompt sanitization using an anchor-based approach to ensure compatibility with Anthropic's Claude Code requirements.
  • Supports API endpoint overrides and insecure TLS connections via environment variables.

Maintenance & Community

The project utilizes changesets for version management and publishing, with CI automating release processes. No specific community links (e.g., Discord, Slack) or details on notable contributors or sponsorships are provided in the README.

Licensing & Compatibility

The project is released under the MIT license, which permits broad use, including commercial applications and linking within closed-source projects.

Limitations & Caveats

Users are strongly cautioned to pin plugin versions to mitigate security risks from automatic updates. For troubleshooting, the README suggests resetting the OpenCode configuration directory (~/.config/opencode) and verifying opencode.json. The system prompt sanitization, while resilient, may require adjustments if Anthropic's API requirements change significantly or if prompts are unusually complex.

Health Check
Last Commit

5 days ago

Responsiveness

Inactive

Pull Requests (30d)
15
Issues (30d)
8
Star History
58 stars in the last 30 days

Explore Similar Projects

Starred by Peter Norvig Peter Norvig(Author of "Artificial Intelligence: A Modern Approach"; Research Director at Google).

vet by imbue-ai

16.8%
386
AI-powered verification for code and agent actions
Created 3 months ago
Updated 1 day ago
Feedback? Help us improve.