Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

49 Commits

Folders and files

Repository files navigation

OpenCode Anthropic Auth

OpenCode plugin that lets you use Anthropic models with your Claude Pro/Max subscription. No API key required.

This is a fork of opencode-anthropic-login-via-cli with a workaround for copying the OAuth URL in remote and containerized environments (see Remote OAuth URL below).

Features

Binary Introspection

Reads the Claude CLI binary to extract current beta headers, OAuth scopes, and version info. Stays in sync with Anthropic's API automatically instead of relying on hardcoded values.

Cross-Platform Support

Works on macOS, Linux, and Windows.

Auto Login

If you have Claude CLI installed and logged in, the plugin picks up your credentials automatically:

  • macOS: System Keychain
  • Linux / Windows: ~/.claude/.credentials.json

CCS Support

If you use CCS for multiple Claude Code instances, each instance in ~/.ccs/instances/ is detected and shows up as a separate auth method.

Browser Login

Opens an OAuth flow through claude.com for users without the CLI. Log in, paste the code, done.

Token Refresh

Handles expired tokens automatically. Falls back to the CLI if the standard refresh fails.

Request Patching

Patches requests so OpenCode talks to Anthropic's API the same way Claude Code does.

Install

Add to your opencode.json:

{
  "plugin": ["opencode-anthropic-login-via-cli-remote@latest"]
}

Then open OpenCode and go to Connect Provider > Anthropic.

Auth Methods

Method Label How it works
Auto Claude Code (auto) Reads existing CLI credentials from Keychain/filesystem
CCS CCS (instance-name) Auto-detects each CCS instance in ~/.ccs/instances/
Browser Claude Pro/Max (browser) OAuth flow via claude.com with PKCE
API Key API Key (manual) Standard Anthropic API key

Remote OAuth URL

When authenticating via Claude Pro/Max (browser), the OAuth URL is too long to fit on one line in the OpenCode TUI dialog. The TUI intercepts mouse and keyboard events, making it impossible to cleanly select and copy the URL. This affects anyone without direct desktop access to the machine running OpenCode.

When the env var OAUTH_URL_DIR is set, the plugin writes the full OAuth URL to $OAUTH_URL_DIR/oauth-url.txt as a single line each time the browser auth dialog opens. You can then read it from a second terminal and copy it cleanly into your browser.

If OAUTH_URL_DIR is not set, the plugin behaves exactly as the original — nothing is written and no message is shown.

Docker

export OAUTH_URL_HOST_DIR=~/.opencode-auth
export OAUTH_URL_DIR=/root/.opencode-auth

docker run -it --rm \
  -e OAUTH_URL_DIR="${OAUTH_URL_DIR}" \
  -v "${OAUTH_URL_HOST_DIR}":"${OAUTH_URL_DIR}" \
  -v /path/to/opencode-config/:/root/.config/opencode \
  -v "$PWD":/workspace \
  -w /workspace \
  ghcr.io/anomalyco/opencode
Argument Purpose
-it Keeps stdin open and allocates a TTY — required for the interactive OpenCode UI
--rm Removes the container automatically when it exits
-e OAUTH_URL_DIR Tells the plugin where inside the container to write the OAuth URL file
-v "${OAUTH_URL_HOST_DIR}":"${OAUTH_URL_DIR}" Mounts the host directory into the container so the URL file is readable from your host
-v /path/to/opencode-config/:/root/.config/opencode Mounts the directory containing your opencode.json so OpenCode can find and load the plugin. Without this mount the plugin will not be loaded. Replace /path/to/opencode-config/ with the actual host path.
-v "$PWD":/workspace Mounts your current working directory as the project root inside the container
-w /workspace Sets the container's working directory to match the mounted project

When the auth dialog appears, on your host:

cat ~/.opencode-auth/oauth-url.txt

Remote environment (SSH, devcontainers, etc.)

Set the env var to any writable directory on the remote machine before starting OpenCode:

export OAUTH_URL_DIR=~/.opencode-auth
opencode

When the auth dialog appears, in a second session to the same machine:

cat ~/.opencode-auth/oauth-url.txt

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages