Skip to content
Open
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
95 changes: 95 additions & 0 deletions Claude-code-router/CLAUDE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Interacting with Your Custom Claude Code Router Setup

This document is your guide to using the `claude-code-router` (ccr) command-line tool, which has been specially configured to work with LiteLLM as a powerful backend.

## How It Works: `claude-code-router` + LiteLLM

Your current setup is a sophisticated, two-part system that provides incredible flexibility:

1. **`claude-code-router` (The Brains):** This is the tool you interact with directly (`ccr code`). Its main job is to be an intelligent **router**. Based on the `Router` settings in your `config.json`, it decides which *type* of model is best suited for a task (e.g., a powerful model for thinking, a fast model for background tasks). It then sends a standardized API request to LiteLLM.

2. **LiteLLM (The Universal Translator):** LiteLLM acts as a proxy server that receives requests from `claude-code-router`. Its job is to translate the standard request into the specific format required by the final model provider (like Google, Anthropic, or the GitHub-proxied models). It manages the API keys and complex provider-specific requirements, as defined in your `auto-headers-config.yaml`.

This architecture means you get the intelligent routing of `claude-code-router` combined with the massive provider compatibility of LiteLLM.

## Your Router Configuration

The `Router` section in `config.json` defines the default model for different scenarios. Here is your current setup:

- **Default (`/model default`):** `litellm-github,gpt-4.1`
- Used for general-purpose tasks.
- **Background:** `litellm-github,gemini-2.0-flash-001`
- A fast, efficient model for background tasks.
- **Think:** `litellm-github,claude-3.7-sonnet-thought`
- A powerful model for complex reasoning and planning.
- **Long Context:** `litellm-github,claude-sonnet-4`
- A model with a large context window for analyzing big files.
- **Web Search:** `litellm-github,gpt-4o`
- A model capable of performing web searches.

## How to Switch Models

You can dynamically switch the active model at any time inside the `ccr code` interface using the `/model` command.

**The format is crucial:** `/model provider_name,model_name`

In your setup, the `provider_name` is always `litellm-github`, as defined in your `config.json`.

### Examples:

- **To switch to the "think" model:**
```
/model litellm-github,claude-3.7-sonnet-thought
```

- **To switch to the "background" model:**
```
/model litellm-github,gemini-2.0-flash-001
```

- **To switch to the new `gemini-1.5-pro` model:**
```
/model litellm-github,gemini-1.5-pro
```

- **To switch back to the default model:**
```
/model default
```

After changing the model, you can always run `/status` to confirm which model is currently active.

## Full List of Available Models

Here are all the models you have configured and can switch to using the `/model litellm-github,MODEL_NAME` command:

- `claude-3.5-sonnet`
- `claude-3.7-sonnet`
- `claude-3.7-sonnet-thought`
- `claude-sonnet-4`
- `gemini-1.5-flash`
- `gemini-1.5-pro`
- `gemini-2.0-flash-001`
- `gemini-pro`
- `gemini-pro-vision`
- `gpt-3.5-turbo`
- `gpt-3.5-turbo-0613`
- `gpt-4`
- `gpt-4-0613`
- `gpt-4-o-preview`
- `gpt-4.1`
- `gpt-4.1-2025-04-14`
- `gpt-4o`
- `gpt-4o-2024-05-13`
- `gpt-4o-2024-08-06`
- `gpt-4o-2024-11-20`
- `gpt-4o-mini`
- `gpt-4o-mini-2024-07-18`
- `o3-mini`
- `o3-mini-2025-01-31`
- `o3-mini-paygo`
- `text-embedding-3-small`
- `text-embedding-3-small-inference`
- `text-embedding-ada-002`
- `llama-3-1-405b`
- `phi-4`
76 changes: 76 additions & 0 deletions Claude-code-router/GEMINI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Agent Identity

You are the Claude Code Router Master, an expert AI agent with comprehensive knowledge of the `claude-code-router` project. Your primary purpose is to assist users by answering questions and providing guidance on all aspects of the `claude-code-router`. You are the definitive source of truth for this project.

## Knowledge Domains

Your knowledge is exclusively focused on the `claude-code-router` project, its architecture, features, configuration, and usage.

### Knowledge Base Structure

Your knowledge is derived directly from the official project documentation. When responding, you embody the expertise contained within these files.

## Agent Capabilities

You can provide detailed explanations and guidance on:
- The fundamental concepts and system overview of the router.
- Configuration of the `config.json` file, including providers and routing rules.
- The dynamic logic the router uses to make decisions.
- How the router uses transformers to ensure API compatibility.
- The full range of Command Line Interface (CLI) commands.
- The background service management, including the use of PID and reference count files.

### Implementation Assistance

You can guide users through:
- **Installation:** Installing `claude-code-router` and its prerequisites.
- **Configuration:** Setting up the `config.json` file with providers, API keys, and routing rules.
- **Usage:** Running the router, using it with Claude Code, and switching models dynamically.
- **Integration:** Incorporating the router into GitHub Actions for CI/CD workflows.

## Inter-Agent Communication

You can serve as a specialized knowledge source for other AI agents. If another agent requires information about the `claude-code-router`, you can provide accurate and context-aware responses based on your documentation-derived knowledge.

## How to Interact with Me

Interact with me by asking questions in natural language. I will synthesize information from my knowledge base to provide accurate and helpful answers about the `claude-code-router`.

## Multi-Agent Collaboration Patterns

In a multi-agent system, you can act as a "Subject Matter Expert" (SME) agent. Other agents can query you to understand the `claude-code-router`'s functionality, which allows them to integrate with or build upon it.

## Commands & Shortcuts

You are an expert on all `ccr` commands:
- `ccr start`: Starts the router service in the background.
- `ccr stop`: Stops the router service.
- `ccr status`: Shows the current status of the router service.
- `ccr code`: Launches a Claude Code session, automatically starting the router if it's not running and ensuring requests are routed through it.
- `ccr version` or `ccr -v`: Displays the installed version.
- `ccr help` or `ccr -h`: Shows the help message.
- `/model provider_name,model_name`: An in-app command within Claude Code to dynamically switch the AI model on-the-fly.

## Mission-Critical Use Cases

You can guide users on leveraging `claude-code-router` for critical tasks, such as:
- **Cost-Effective AI Usage:** Routing tasks to cheaper or local models (like Ollama) for background or simple requests, while using powerful models for complex reasoning.
- **Multi-Provider Strategy:** Avoiding vendor lock-in by seamlessly switching between different AI providers like DeepSeek, OpenRouter, and Gemini.
- **CI/CD Automation:** Integrating the router into GitHub Actions to automate coding tasks, reviews, or other AI-powered workflows.
- **Enhanced Tool Use:** Using transformers to improve how models interact with tools, ensuring more reliable and proactive tool execution.

## Source Documentation

Your knowledge is based on the following project files:
- `claude-code-router-01_claude_code_router__system_overview__.md`
- `claude-code-router-02_router_configuration_.md`
- `claude-code-router-03_dynamic_request_routing_logic_.md`
- `claude-code-router-04_model_providers___transformers_.md`
- `claude-code-router-05_command_line_interface__cli__.md`
- `claude-code-router-06_background_service_management_.md`
- `claude-code-router-index.md`
- `summary-claude-code-router.md`
- `README.md`
- `README_zh.md`
- `blog/en/project-motivation-and-how-it-works.md`
- `blog/en/maybe-we-can-do-more-with-the-route.md`
52 changes: 52 additions & 0 deletions Claude-code-router/api-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { randomUUID } from "node:crypto"

import type { State } from "./state"

export const standardHeaders = () => ({
"content-type": "application/json",
accept: "application/json",
})

const COPILOT_VERSION = "0.26.7"
const EDITOR_PLUGIN_VERSION = `copilot-chat/${COPILOT_VERSION}`
const USER_AGENT = `GitHubCopilotChat/${COPILOT_VERSION}`

const API_VERSION = "2025-04-01"

export const copilotBaseUrl = (state: State) =>
state.accountType === "individual" ?
"https://api.githubcopilot.com"
: `https://api.${state.accountType}.githubcopilot.com`
export const copilotHeaders = (state: State, vision: boolean = false) => {
const headers: Record<string, string> = {
Authorization: `Bearer ${state.copilotToken}`,
"content-type": standardHeaders()["content-type"],
"copilot-integration-id": "vscode-chat",
"editor-version": `vscode/${state.vsCodeVersion}`,
"editor-plugin-version": EDITOR_PLUGIN_VERSION,
"user-agent": USER_AGENT,
"openai-intent": "conversation-panel",
"x-github-api-version": API_VERSION,
"x-request-id": randomUUID(),
"x-vscode-user-agent-library-version": "electron-fetch",
}

if (vision) headers["copilot-vision-request"] = "true"

return headers
}

export const GITHUB_API_BASE_URL = "https://api.github.com"
export const githubHeaders = (state: State) => ({
...standardHeaders(),
authorization: `token ${state.githubToken}`,
"editor-version": `vscode/${state.vsCodeVersion}`,
"editor-plugin-version": EDITOR_PLUGIN_VERSION,
"user-agent": USER_AGENT,
"x-github-api-version": API_VERSION,
"x-vscode-user-agent-library-version": "electron-fetch",
})

export const GITHUB_BASE_URL = "https://github.com"
export const GITHUB_CLIENT_ID = "Iv1.b507a08c87ecfe98"
export const GITHUB_APP_SCOPES = ["read:user"].join(" ")
118 changes: 118 additions & 0 deletions Claude-code-router/auto-headers-config-updated-with-py.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
model_list:
- model_name: claude-3.5-sonnet
litellm_params:
model: github_copilot/claude-3.5-sonnet
extra_headers: &id001
editor-version: vscode/1.96.0
editor-plugin-version: copilot/1.155.0
copilot-integration-id: vscode-chat
user-agent: GitHubCopilot/1.155.0
- model_name: claude-3.7-sonnet
litellm_params:
model: github_copilot/claude-3.7-sonnet
extra_headers: *id001
- model_name: claude-3.7-sonnet-thought
litellm_params:
model: github_copilot/claude-3.7-sonnet-thought
extra_headers: *id001
- model_name: claude-sonnet-4
litellm_params:
model: github_copilot/claude-sonnet-4
extra_headers: *id001
- model_name: gemini-2.0-flash-001
litellm_params:
model: github_copilot/gemini-2.0-flash-001
extra_headers: *id001
- model_name: gpt-3.5-turbo
litellm_params:
model: github_copilot/gpt-3.5-turbo
extra_headers: *id001
- model_name: gpt-3.5-turbo-0613
litellm_params:
model: github_copilot/gpt-3.5-turbo-0613
extra_headers: *id001
- model_name: gpt-4
litellm_params:
model: github_copilot/gpt-4
extra_headers: *id001
- model_name: gpt-4-0613
litellm_params:
model: github_copilot/gpt-4-0613
extra_headers: *id001
- model_name: gpt-4-o-preview
litellm_params:
model: github_copilot/gpt-4-o-preview
extra_headers: *id001
- model_name: gpt-4.1
litellm_params:
model: github_copilot/gpt-4.1
extra_headers: *id001
- model_name: gpt-4.1-2025-04-14
litellm_params:
model: github_copilot/gpt-4.1-2025-04-14
extra_headers: *id001
- model_name: gpt-4o
litellm_params:
model: github_copilot/gpt-4o
extra_headers: *id001
- model_name: gpt-4o-2024-05-13
litellm_params:
model: github_copilot/gpt-4o-2024-05-13
extra_headers: *id001
- model_name: gpt-4o-2024-08-06
litellm_params:
model: github_copilot/gpt-4o-2024-08-06
extra_headers: *id001
- model_name: gpt-4o-2024-11-20
litellm_params:
model: github_copilot/gpt-4o-2024-11-20
extra_headers: *id001
- model_name: gpt-4o-mini
litellm_params:
model: github_copilot/gpt-4o-mini
extra_headers: *id001
- model_name: gpt-4o-mini-2024-07-18
litellm_params:
model: github_copilot/gpt-4o-mini-2024-07-18
extra_headers: *id001
- model_name: o3-mini
litellm_params:
model: github_copilot/o3-mini
extra_headers: *id001
- model_name: o3-mini-2025-01-31
litellm_params:
model: github_copilot/o3-mini-2025-01-31
extra_headers: *id001
- model_name: o3-mini-paygo
litellm_params:
model: github_copilot/o3-mini-paygo
extra_headers: *id001
- model_name: text-embedding-3-small
litellm_params:
model: github_copilot/text-embedding-3-small
extra_headers: *id001
- model_name: text-embedding-3-small-inference
litellm_params:
model: github_copilot/text-embedding-3-small-inference
extra_headers: *id001
- model_name: text-embedding-ada-002
litellm_params:
model: github_copilot/text-embedding-ada-002
extra_headers: *id001
- model_name: llama-3-1-405b
litellm_params:
model: github/Llama-3.1-405B-Instruct
api_key: os.environ/GITHUB_API_KEY
- model_name: phi-4
litellm_params:
model: github/Phi-4
api_key: os.environ/GITHUB_API_KEY
general_settings:
master_key: sk-auto-headers-2025
litellm_settings:
set_verbose: true
drop_params: true
cost_tracking:
enabled: true
github_copilot_subscription: true
github_marketplace_usage: true
Loading