Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
npm-debug.log
node_modules
npm-debug.log
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish to npm

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
.env
log.txt
.idea
node_modules
.env
log.txt
.idea
dist
28 changes: 14 additions & 14 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
src
node_modules
.claude
CLAUDE.md
screenshoots
.DS_Store
.vscode
.idea
.env
.blog
docs
.log
blog
config.json
src
node_modules
.claude
CLAUDE.md
screenshoots
.DS_Store
.vscode
.idea
.env
.blog
docs
.log
blog
config.json
14 changes: 14 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Registry configuration
registry=https://registry.npmjs.org/

# Authentication token (will be set by npm login or CI/CD)
# //registry.npmjs.org/:_authToken=${NPM_TOKEN}

# Package access level
access=public

# Ignore optional dependencies during install
omit=optional

# Save exact versions
save-exact=false
84 changes: 42 additions & 42 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

- **Build the project**:
```bash
npm run build
```
- **Start the router server**:
```bash
ccr start
```
- **Stop the router server**:
```bash
ccr stop
```
- **Check the server status**:
```bash
ccr status
```
- **Run Claude Code through the router**:
```bash
ccr code "<your prompt>"
```
- **Release a new version**:
```bash
npm run release
```

## Architecture

This project is a TypeScript-based router for Claude Code requests. It allows routing requests to different large language models (LLMs) from various providers based on custom rules.

- **Entry Point**: The main command-line interface logic is in `src/cli.ts`. It handles parsing commands like `start`, `stop`, and `code`.
- **Server**: The `ccr start` command launches a server that listens for requests from Claude Code. The server logic is initiated from `src/index.ts`.
- **Configuration**: The router is configured via a JSON file located at `~/.claude-code-router/config.json`. This file defines API providers, routing rules, and custom transformers. An example can be found in `config.example.json`.
- **Routing**: The core routing logic determines which LLM provider and model to use for a given request. It supports default routes for different scenarios (`default`, `background`, `think`, `longContext`, `webSearch`) and can be extended with a custom JavaScript router file. The router logic is likely in `src/utils/router.ts`.
- **Providers and Transformers**: The application supports multiple LLM providers. Transformers adapt the request and response formats for different provider APIs.
- **Claude Code Integration**: When a user runs `ccr code`, the command is forwarded to the running router service. The service then processes the request, applies routing rules, and sends it to the configured LLM. If the service isn't running, `ccr code` will attempt to start it automatically.
- **Dependencies**: The project is built with `esbuild`. It has a key local dependency `@musistudio/llms`, which probably contains the core logic for interacting with different LLM APIs.
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Commands
- **Build the project**:
```bash
npm run build
```
- **Start the router server**:
```bash
ccr start
```
- **Stop the router server**:
```bash
ccr stop
```
- **Check the server status**:
```bash
ccr status
```
- **Run Claude Code through the router**:
```bash
ccr code "<your prompt>"
```
- **Release a new version**:
```bash
npm run release
```
## Architecture
This project is a TypeScript-based router for Claude Code requests. It allows routing requests to different large language models (LLMs) from various providers based on custom rules.
- **Entry Point**: The main command-line interface logic is in `src/cli.ts`. It handles parsing commands like `start`, `stop`, and `code`.
- **Server**: The `ccr start` command launches a server that listens for requests from Claude Code. The server logic is initiated from `src/index.ts`.
- **Configuration**: The router is configured via a JSON file located at `~/.claude-code-router/config.json`. This file defines API providers, routing rules, and custom transformers. An example can be found in `config.example.json`.
- **Routing**: The core routing logic determines which LLM provider and model to use for a given request. It supports default routes for different scenarios (`default`, `background`, `think`, `longContext`, `webSearch`) and can be extended with a custom JavaScript router file. The router logic is likely in `src/utils/router.ts`.
- **Providers and Transformers**: The application supports multiple LLM providers. Transformers adapt the request and response formats for different provider APIs.
- **Claude Code Integration**: When a user runs `ccr code`, the command is forwarded to the running router service. The service then processes the request, applies routing rules, and sends it to the configured LLM. If the service isn't running, `ccr code` will attempt to start it automatically.
- **Dependencies**: The project is built with `esbuild`. It has a key local dependency `@musistudio/llms`, which probably contains the core logic for interacting with different LLM APIs.
- `@musistudio/llms` is implemented based on `fastify` and exposes `fastify`'s hook and middleware interfaces, allowing direct use of `server.addHook`.
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2025 musistudio

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2025 musistudio
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 88 additions & 0 deletions README-npm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# ccr-next

An enhanced fork of [claude-code-router](https://github.com/musistudio/claude-code-router) with additional features for dynamic provider configuration.

## Features

- Route Claude Code requests to different LLM providers
- Configure providers and transformers via command line
- Support for multiple LLM providers (OpenRouter, DeepSeek, Ollama, Gemini, etc.)
- Custom routing rules based on request context
- Background processing for non-critical tasks

## Installation

```bash
npm install -g ccr-next
```

## Quick Start

1. Start the router service:
```bash
ccr start
```

2. Configure providers on the fly:
```bash
ccr start --provider openrouter https://openrouter.ai/api/v1/chat/completions sk-xxx claude-3.5-sonnet,gpt-4
ccr start --transformer openrouter openrouter
```

3. Use Claude Code with the router:
```bash
ccr code "Write a Hello World program"
```

## Command Line Options

### Start Server with Provider Configuration

```bash
ccr start --provider <name> <url> <key> <models> --transformer <provider> <transformer>
```

Options:
- `--provider`: Add or update a provider
- `name`: Provider name (e.g., openrouter, deepseek)
- `url`: API base URL
- `key`: API key
- `models`: Comma-separated list of model names
- `--transformer`: Set transformer for a provider
- `provider`: Provider name
- `transformer`: Transformer name

Examples:
```bash
# Add OpenRouter provider
ccr start --provider openrouter https://openrouter.ai/api/v1/chat/completions sk-xxx claude-3.5-sonnet

# Add DeepSeek provider with transformer
ccr start --provider deepseek https://api.deepseek.com/chat/completions sk-xxx deepseek-chat --transformer deepseek deepseek

# Add multiple providers
ccr start \
--provider openrouter https://openrouter.ai/api/v1/chat/completions sk-xxx claude-3.5-sonnet \
--provider deepseek https://api.deepseek.com/chat/completions sk-xxx deepseek-chat
```

### Other Commands

- `ccr stop`: Stop the router service
- `ccr restart`: Restart the service (supports same options as start)
- `ccr status`: Show service status
- `ccr code "<prompt>"`: Execute Claude command through the router
- `ccr -v`: Show version
- `ccr -h`: Show help

## Configuration

The router uses a configuration file at `~/.claude-code-router/config.json`. You can either:
1. Edit this file directly
2. Use command line options to configure providers dynamically

See [config.example.json](https://github.com/yourusername/ccr-direct/blob/main/config.example.json) for configuration examples.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace placeholder URL with actual repository

The configuration example link contains a placeholder URL that should be updated to match the actual repository.

-See [config.example.json](https://github.com/yourusername/ccr-direct/blob/main/config.example.json) for configuration examples.
+See [config.example.json](https://github.com/<actual-username>/ccr-direct/blob/main/config.example.json) for configuration examples.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
See [config.example.json](https://github.com/yourusername/ccr-direct/blob/main/config.example.json) for configuration examples.
See [config.example.json](https://github.com/<actual-username>/ccr-direct/blob/main/config.example.json) for configuration examples.
🤖 Prompt for AI Agents
In README-npm.md at line 84, the URL in the configuration example link uses a
placeholder "yourusername" instead of the actual GitHub repository owner. Update
the URL to reflect the correct repository path by replacing "yourusername" with
the actual GitHub username or organization name that owns the ccr-direct
repository.


## License

MIT
Loading