logo
0
0
WeChat Login
Griffin Martin<me@griffinmartin.dev>
fix: write auth.json to both Windows paths to cover all install methods (#41)

opencode-claude-auth

npm CI Socket Badge

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

How it works

Claude Code stores OAuth tokens in the macOS Keychain (or ~/.claude/.credentials.json on other platforms). This plugin reads those tokens and writes them to OpenCode's ~/.local/share/opencode/auth.json (on Windows, it writes to both %USERPROFILE%\.local\share\opencode\auth.json and %LOCALAPPDATA%\opencode\auth.json to cover all installation methods), so you don't need to log in twice. It re-syncs every 5 minutes to pick up token refreshes. If a token is near expiry, it runs the Claude CLI to trigger a refresh.

Prerequisites

  • Claude Code installed and authenticated (run claude at least once)
  • OpenCode installed

macOS is preferred (uses Keychain). Linux and Windows work via the credentials file fallback.

Installation

Install with AI

Paste this into your AI agent (Claude Code, Cursor, Copilot, etc.):

Fetch https://raw.githubusercontent.com/griffinmartin/opencode-claude-auth/main/installation.md and follow every step exactly as written.

Manual install

npm install -g opencode-claude-auth

Then add to the plugin array in your opencode.json:

{ "plugin": ["opencode-claude-auth"] }

Usage

Just run OpenCode. The plugin syncs your Claude Code credentials to OpenCode's auth.json and refreshes them in the background.

Credential sources

The plugin checks these in order:

  1. macOS Keychain ("Claude Code-credentials" entry)
  2. ~/.claude/.credentials.json (fallback, works on all platforms)

Troubleshooting

ProblemSolution
"Credentials not found"Run claude to authenticate with Claude Code first
"Keychain is locked"Run security unlock-keychain ~/Library/Keychains/login.keychain-db
"Token expired and refresh failed"The plugin runs claude CLI to refresh automatically. If this fails, re-authenticate manually by running claude
Not working on Linux/WindowsEnsure ~/.claude/.credentials.json exists. Run claude to create it
Keychain access deniedGrant access when macOS prompts you
Keychain read timed outRestart Keychain Access (can happen on macOS Tahoe)

How it works (technical)

  • Reads OAuth tokens from macOS Keychain (Claude Code-credentials entry) or ~/.claude/.credentials.json fallback
  • Writes an anthropic entry to ~/.local/share/opencode/auth.json (on Windows, writes to both %USERPROFILE%\.local\share\opencode\auth.json and %LOCALAPPDATA%\opencode\auth.json) in OpenCode's native OAuth format
  • Preserves other provider entries already in auth.json
  • Re-syncs credentials every 5 minutes in the background
  • When a token is within 60 seconds of expiry, runs claude CLI to trigger a refresh
  • If credentials are unavailable or unreadable, the plugin disables itself and OpenCode continues without Claude auth

License

MIT