Skip to content

Conversation

@d-kimuson
Copy link

@d-kimuson d-kimuson commented Nov 4, 2025

Background

I'm the author of d-kimuson/claude-code-viewer, which uses the Agent SDK to provide a web-based GUI for Claude Code. I received this issue from a user who wanted to use it with claude-code-router.

After reading the implementation, I realized it should work in principle by running ccr start and setting the appropriate environment variables. However, manually converting the config file to environment variables is cumbersome. I thought it would be beneficial to have a CLI command that just handles the environment variable setup. This would enable seamless integration not only with claude-code-viewer but with any Agent SDK-based application.

Implementation

This PR adds a ccr activate command to achieve this goal. This is also a proof of concept - if a different interface design is preferred, feel free to reject this and recreate it, or let me know and I can make the changes.

Usage

Basic Usage

$ ccr activate
export ANTHROPIC_AUTH_TOKEN="test"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
export NO_PROXY="127.0.0.1"
export DISABLE_TELEMETRY="true"
export DISABLE_COST_WARNINGS="true"
export API_TIMEOUT_MS="600000"
unset CLAUDE_CODE_USE_BEDROCK

$ eval $(ccr activate)

$ echo $ANTHROPIC_AUTH_TOKEN
test

With Agent SDK Applications

# Start the router
ccr start

# Activate environment variables
eval $(ccr activate)

# Now any Agent SDK application will use ccr's routing
npx @kimuson/claude-code-viewer@latest
# or any other Agent SDK application

Technical Details

  • Refactored environment variable creation logic from ccr code into a shared createEnvVariables() function
  • The activate command outputs in shell-friendly format by default (no --shell flag needed)
  • Environment variables match exactly what ccr code uses internally
  • Updated both English and Chinese documentation

Testing

Tested on my local environment:

  • ccr activate outputs correct environment variables ✅
  • eval $(ccr activate) successfully sets environment variables ✅
  • ccr code still works correctly with refactored code ✅

This commit adds a new `ccr activate` command that outputs environment
variables in shell-friendly format, making it easy to integrate
claude-code-router with Agent SDK applications.

Usage:
  eval $(ccr activate)

This sets the following environment variables:
- ANTHROPIC_AUTH_TOKEN
- ANTHROPIC_API_KEY
- ANTHROPIC_BASE_URL
- NO_PROXY
- DISABLE_TELEMETRY
- DISABLE_COST_WARNINGS
- API_TIMEOUT_MS
- CLAUDE_CODE_USE_BEDROCK

The implementation refactors the environment variable creation logic
from `ccr code` into a shared `createEnvVariables()` function in
`src/utils/createEnvVariables.ts`, ensuring consistency between both
commands.

Related: musistudio#855
@d-kimuson
Copy link
Author

related: #855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant