Open
Conversation
- Add support for ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN environment variables - Skip authentication when CCR is configured for anthropic provider - Display CCR configuration in 'opencode auth list' command - Auto-detect and inform users when CCR is available during 'opencode auth login' This allows users to use Claude Code Router (CCR) to route Anthropic requests to alternative providers like OpenRouter, DeepSeek, or local models without needing separate Anthropic authentication. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Created new CCR module to handle automatic detection and activation - CCR.autoActivate() checks if 'ccr' command is available - If available, runs 'ccr activate' and parses environment variables - Automatically sets ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN - Integrated into opencode startup flow via middleware - Users now only need to run 'opencode' - no manual ccr activation needed This eliminates the need for users to manually run 'eval "$(ccr activate)"' before running opencode. The integration is transparent and only activates when ccr is installed and not already configured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive support for Claude Code Router (CCR) in opencode, allowing users to route Anthropic API requests through alternative providers like OpenRouter, DeepSeek, or local models.
🎉 Key Feature: Automatic CCR Activation
Users no longer need to manually run
ccr activatebefore using opencode. The tool now automatically detects and activates CCR if available!Changes
1. Automatic CCR Detection & Activation (NEW!)
CCRmodule (packages/opencode/src/ccr/index.ts)ccrcommand is available on startupccr activateand parses environment variables2. Environment Variable Support
ANTHROPIC_BASE_URLandANTHROPIC_AUTH_TOKENenvironment variables3. Authentication Flow Updates
opencode auth login: Detects CCR configuration and informs users that no additional authentication is neededopencode auth list: Displays CCR configuration when environment variables are set (with partial token masking)4. Provider Configuration
anthropicCUSTOM_LOADER inprovider.tsto auto-detect and apply CCR settingsUsage
Option 1: Automatic (Recommended) ✨
Just install ccr and run opencode - it will automatically detect and activate ccr:
Option 2: Manual Environment Variables
Set environment variables manually:
Option 3: Shell Integration (for other tools)
For compatibility with other tools that don't auto-activate:
Technical Details
Files Modified
packages/opencode/src/ccr/index.ts(new): CCR auto-detection and activation modulepackages/opencode/src/index.ts: Integrated CCR.autoActivate() into startup middlewarepackages/opencode/src/provider/provider.ts: Added CCR environment variable support for anthropic providerpackages/opencode/src/cli/cmd/auth.ts: Enhanced auth commands to display and handle CCR configurationActivation Logic
ccrcommand exists in PATHccr activateand parse the outputTesting
Benefits