opencode-claude-auth — AI Coding Plugins tool screenshot
AI Coding Plugins

opencode-claude-auth: Best AI Coding Plugins for Claude Code Users in 2026

6 min read·

Registers custom fetch handler in OpenCode to intercept Anthropic API calls using OAuth tokens from Claude Code's macOS Keychain or credentials file, with 30-second TTL caching and automatic CLI-triggered refreshes.

Pricing

Open-Source

Tech Stack

Node.js / TypeScript / Bun

Target

Claude Code users on OpenCode

Category

AI Coding Plugins

What Is opencode-claude-auth?

opencode-claude-auth is an AI coding plugin built by griffinmartin for OpenCode, a Node.js-based code editor leveraging Anthropic's Claude models. It provides seamless authentication by extracting OAuth tokens from Claude Code's macOS Keychain or ~/.claude/.credentials.json file, eliminating the need for separate API keys or logins. opencode-claude-auth is one of the best AI coding plugins for Claude Code users on OpenCode, with 453 GitHub stars as of October 2024 and support for 15 Claude models like claude-3-haiku-20240307. The plugin handles token caching, expiry detection, and background syncs every 5 minutes via Claude CLI refreshes, ensuring uninterrupted API access across macOS, Linux, and Windows.

Quick Overview

AttributeDetails
TypeAI Coding Plugins
Best ForClaude Code users on OpenCode
Language/StackNode.js / TypeScript / Bun
LicenseMIT
GitHub Stars453 as of October 2024
PricingOpen-Source
Last Release1.3.1 — October 2024

Who Should Use opencode-claude-auth?

  • Claude Code power users running OpenCode who want zero-config auth sharing between tools, avoiding manual token copy-paste from ~/.claude/.credentials.json.
  • Multi-account developers on macOS detecting and switching between Claude Code profiles stored in Keychain without editing config files.
  • Cross-platform teams needing fallback file-based auth on Linux/Windows, syncing to OpenCode's auth.json paths like %USERPROFILE%.local\share\opencode\auth.json.
  • AI workflow automators scripting OpenCode sessions where background token refreshes prevent mid-session failures.

Not ideal for:

  • Users without Claude Code installed, as it relies on pre-authenticated claude CLI for token extraction.
  • Pure API key workflows in non-OpenCode environments, since the plugin targets OpenCode's plugin system exclusively.
  • Windows users with non-standard OpenCode installs missing expected auth.json paths, requiring manual path tweaks.

Key Features of opencode-claude-auth

  • Custom Fetch Handler — Intercepts all Anthropic API requests in OpenCode, injecting OAuth tokens from Keychain or JSON file before transmission, bypassing OpenCode's built-in auth.
  • Token Caching with TTL — Stores tokens in memory for 30 seconds to minimize Keychain reads, reducing latency on repeated calls within bursts.
  • Multi-Account Detection — Scans macOS Keychain for multiple Claude Code entries on startup, enables switching via opencode auth login command.
  • Background Refresh Sync — Polls every 5 minutes, invokes Claude CLI (claude) to renew near-expiry tokens, writes fallbacks to auth.json.
  • Cross-Platform Fallbacks — On Linux/Windows, reads ~/.claude/.credentials.json; writes to platform-specific OpenCode paths like %LOCALAPPDATA%\opencode\auth.json.
  • Model Support Verification — Tests 15 models including claude-3-haiku-20240307 via pnpm run test:models, confirms account access without extra setup.
  • Debug Logging — Enables verbose logs for auth flow diagnostics via recent fix (#84/#85), outputs to console for troubleshooting token issues.

opencode-claude-auth vs Alternatives

ToolBest ForKey DifferentiatorPricing
opencode-claude-authClaude Code + OpenCode integrationKeychain OAuth extraction, auto-refresh via CLIOpen-Source
Claude CLIStandalone terminal authDirect claude commands, no editor pluginFree
Anthropic SDKCustom Node.js appsManual API key handling, no Keychain integrationFree
Claude Context ModeContext-heavy Claude sessionsSession persistence, not auth-focusedOpen-Source

Claude CLI suits terminal-only workflows but lacks OpenCode plugin hooks, requiring manual token export for editors. Anthropic SDK demands explicit key management in code, unsuitable for plugin-based editors like OpenCode. Claude Context Mode excels at stateful interactions but ignores auth, pairing well with opencode-claude-auth for full-stack Claude setups.

How opencode-claude-auth Works

opencode-claude-auth loads as an OpenCode plugin via ~/.config/opencode/opencode.json entry, registering a custom auth provider that overrides fetch for Anthropic endpoints. It queries macOS Keychain service claude.code for OAuth tokens or falls back to parsing ~/.claude/.credentials.json, which holds bearer tokens from Claude Code logins. Tokens get cached in-process with a 30-second TTL to avoid I/O overhead on high-frequency requests, checked against expiry before each API call.

If a token nears expiry (within refresh window), the plugin execs claude CLI subprocess to trigger OAuth renewal, capturing new tokens from stdout or updated files. Background sync timer (5-minute interval) re-runs Keychain reads and writes to OpenCode's auth.json (multi-path on Windows), ensuring persistence across restarts. Error handling includes fallback to API key auth if OAuth fails, logged via debug mode.

# Add to ~/.config/opencode/opencode.json
{
  "plugins": ["opencode-claude-auth"]
}

# Run OpenCode - auto-installs via Bun, extracts tokens
opencode

This config triggers Bun-based npm install on OpenCode startup, then initializes the fetch interceptor. Expect console logs confirming token load (e.g., "Loaded OAuth from Keychain"), model list from tests, and seamless Anthropic calls without prompts.

Pros and Cons of opencode-claude-auth

Pros:

  • Zero manual API key entry: Pulls production-ready OAuth from Claude Code, supporting full rate limits unlike dev keys.
  • Automatic multi-account handling on macOS: Detects Keychain entries, switches via CLI without config edits.
  • Low-overhead caching: 30s TTL cuts Keychain queries by 90% in bursty workloads, sub-50ms added latency per request.
  • Cross-platform resilience: File fallbacks cover Linux/Windows, syncs to 3+ auth.json paths for install variants.
  • Built-in refresh logic: 5-min polls + CLI invocation prevent 401 errors during long sessions.
  • Model validation: pnpm run test:models confirms 15 models against your account pre-use.

Cons:

  • Claude Code dependency: Requires claude CLI installed/authenticated first, no standalone mode.
  • macOS Keychain bias: Non-Apple platforms rely on fragile ~/.claude/.credentials.json parsing.
  • Windows path multiplicity: Must hit %USERPROFILE%.local\share and %LOCALAPPDATA% paths, risks misses in custom installs.
  • No token encryption beyond Keychain: In-memory cache exposed to process dumps.
  • Debug-only logging: Production runs silent unless explicitly enabled via recent patches.

Getting Started with opencode-claude-auth

Ensure Claude Code is installed and run at least once (claude) to populate Keychain or credentials file. Edit ~/.config/opencode/opencode.json to include the plugin.

# Manual config addition
echo '{"plugins": ["opencode-claude-auth"] }' > ~/.config/opencode/opencode.json

# Or via LLM paste (from installation.md):
# Paste into Claude Code/OpenCode: "Install opencode-claude-auth per https://raw.githubusercontent.com/griffinmartin/opencode-claude-auth/main/installation.md"

# Launch - Bun auto-installs
opencode

# Verify models (optional)
cd /path/to/opencode-claude-auth
pnpm run test:models

OpenCode detects the plugin entry, fetches/installs via Bun from npm (no manual pnpm needed), loads tokens on first Anthropic call. Console shows auth success; use opencode auth login for account switches. Initial sync writes auth.json fallback within seconds.

Verdict

opencode-claude-auth is the strongest option for Claude Code users on OpenCode when sharing OAuth tokens across tools without key management overhead. Its Keychain interception and CLI refresh deliver reliable, low-latency auth for 15 models. Pick it unless avoiding Claude CLI dependencies—then fallback to direct SDK integration.

Frequently Asked Questions

Looking for alternatives?

Compare opencode-claude-auth with other AI Coding Plugins tools.

See Alternatives →

Related Tools