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
19 changes: 19 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"permissions": {
"allow": [
"mcp__serena__search_for_pattern",
"mcp__serena__get_symbols_overview",
"mcp__serena__find_symbol",
"mcp__serena__think_about_collected_information",
"WebSearch",
"mcp__zen__chat",
"mcp__serena__list_dir",
"mcp__zen__planner"
],
"deny": [],
"ask": [],
"additionalDirectories": [
"/Users/fredrikbranstrom/claude-code"
]
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
.env
log.txt
.idea
dist
dist.claude/settings.local.json
Binary file not shown.
68 changes: 68 additions & 0 deletions .serena/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
# * For C, use cpp
# * For JavaScript, use typescript
# Special requirements:
# * csharp: Requires the presence of a .sln file in the project folder.
language: typescript

# whether to use the project's gitignore file to ignore files
# Added on 2025-04-07
ignore_all_files_in_gitignore: true
# list of additional paths to ignore
# same syntax as gitignore, so you can use * and **
# Was previously called `ignored_dirs`, please update your config if you are using that.
# Added (renamed)on 2025-04-07
ignored_paths: []

# whether the project is in read-only mode
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
# Added on 2025-04-18
read_only: false


# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
# Below is the complete list of tools for convenience.
# To make sure you have the latest list of tools, and to view their descriptions,
# execute `uv run scripts/print_tool_overview.py`.
#
# * `activate_project`: Activates a project by name.
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
# * `create_text_file`: Creates/overwrites a file in the project directory.
# * `delete_lines`: Deletes a range of lines within a file.
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
# * `execute_shell_command`: Executes a shell command.
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
# * `initial_instructions`: Gets the initial instructions for the current project.
# Should only be used in settings where the system prompt cannot be set,
# e.g. in clients you have no control over, like Claude Desktop.
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
# * `insert_at_line`: Inserts content at a given line in a file.
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
# * `list_memories`: Lists memories in Serena's project-specific memory store.
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
# * `read_file`: Reads a file within the project directory.
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
# * `remove_project`: Removes a project from the Serena configuration.
# * `replace_lines`: Replaces a range of lines within a file with new content.
# * `replace_symbol_body`: Replaces the full definition of a symbol.
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
# * `search_for_pattern`: Performs a search for a pattern in the project.
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
# * `switch_modes`: Activates modes by providing a list of their names
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
excluded_tools: []

# initial prompt for the project. It will always be given to the LLM upon activating the project
# (contrary to the memories, which are loaded on demand).
initial_prompt: ""

project_name: "ccr-dev"
101 changes: 96 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
```bash
ccr stop
```
- **Restart the server**:
```bash
ccr restart
```
- **Check the server status**:
```bash
ccr status
Expand All @@ -24,21 +28,108 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
```bash
ccr code "<your prompt>"
```
Note: The CCR proxy service auto-launches when you run `ccr code`
- **Local development with yalc**:
```bash
yalc publish # After building changes
yalc update @musistudio/llms # Force CCR to use latest version
ccr restart # Restart to load updated package
```
- **GPT-5/o3 Support Status**: ✅ PRODUCTION READY via OpenAI Chat Completions API with transformer chain `["reasoning", "openai"]` in config.json
- **Release a new version**:
```bash
npm run release
```

## Inline Reasoning Control Tokens

CCR supports inline tokens to control GPT-5 reasoning effort and response verbosity without requiring separate flags or configuration. Tokens are automatically detected, processed, and stripped from prompts before sending to the API.

### **Token Formats**

| Token | Position | Reasoning Effort | Verbosity | Thinking Budget | Use Case |
|-------|----------|------------------|-----------|-----------------|----------|
| `Quick:` | Prefix only | low | low | 500 tokens | Fast responses, simple queries |
| `Deep:` | Prefix only | high | medium | 2000 tokens | Complex analysis, thorough research |
| `Explain:` | Prefix only | medium | high | 1000 tokens | Detailed explanations, tutorials |
| `Brief:` | Prefix only | medium | low | 1000 tokens | Concise summaries, quick facts |
| `:quick` | Anywhere | low | low | 500 tokens | Same as Quick: |
| `:deep` | Anywhere | high | medium | 2000 tokens | Same as Deep: |
| `:explain` | Anywhere | medium | high | 1000 tokens | Same as Explain: |
| `:brief` | Anywhere | medium | low | 1000 tokens | Same as Brief: |

### **Usage Examples**

```bash
# Prefix tokens (beginning of prompt)
ccr code "Quick: List the OWASP Top 3"
ccr code "Deep: Analyze SQL injection attack patterns"
ccr code "Explain: How does JWT authentication work?"
ccr code "Brief: Summarize the OAuth 2.0 flow"

# Inline colon tokens (anywhere in prompt)
ccr code "Analyze this vulnerability :brief and suggest fixes"
ccr code "I need :deep analysis of this cryptographic implementation"
ccr code "Can you :explain the difference between XSS types?"
```

### **Parameter Mapping**

- **Reasoning Effort**: Controls internal GPT-5 thinking depth (`minimal/low/medium/high`)
- **Verbosity**: Controls output length and detail level (`low/medium/high`)
- **Thinking Budget**: Token allocation for reasoning process (impacts response time)
- **Auto-routing**: Tokens automatically trigger "think" model routing for enhanced reasoning

### **Implementation**

Tokens are processed in CCR's router middleware (`src/utils/router.ts:153-210`) before API calls, ensuring:
- Tokens are stripped from user prompts
- Parameters are set correctly for downstream transformers
- Thinking mode is activated for appropriate models
- No conflicts with Claude Code's `#` memory system

## Configuration

- **Config file location**: `~/.claude-code-router/config.json`
- **PID file location**: `~/.claude-code-router/.claude-code-router.pid`
- **Logs location**: `~/.claude-code-router/logs/`

## 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.

### **Core Separation of Concerns**
- **CCR (Claude Code Router)**: Handles routing decisions (which model to use based on rules)
- **LLMS Package**: Handles provider transformations (how to format requests for each API)
- **Principle**: CCR should never do provider-specific transformations; LLMS handles all API format conversions

### **Key Components**
- **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.
- **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 in `src/utils/router.ts`.
- **Provider Integration**: Delegates all API format handling to `@musistudio/llms` transformers. CCR focuses purely on routing logic and service management.
- **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 via LLMS transformers. If the service isn't running, `ccr code` will attempt to start it automatically.
- **Automatic Service Management**: Uses reference counting to track active Claude Code sessions. Service auto-starts when first needed and auto-stops when all sessions end. Multiple concurrent sessions share the same service instance.
- **Dependencies**: The project is built with `esbuild`. It has a key local dependency `@musistudio/llms` v1.0.26, which contains the universal LLM transformation server.
- `@musistudio/llms` is implemented based on `fastify` and exposes `fastify`'s hook and middleware interfaces, allowing direct use of `server.addHook`.
- 无论如何你都不能自动提交git
- Never automatically commit to git under any circumstances

## Known Issues & Solutions

### **GPT-5 Reasoning Parameter Bug (RESOLVED 2025-08-21)**

**Issue**: Interactive mode `claude "Think hard..."` fails with "Unknown parameter: 'reasoning'" while print mode `claude -p "Think hard..."` works fine.

**Root Cause**: LLMS Anthropic transformer at `/Users/fredrikbranstrom/llms-dev/src/transformer/anthropic.transformer.ts:159-165` creates invalid `reasoning = {effort: "medium", enabled: true}` objects instead of `reasoning_effort = "medium"` strings required by OpenAI's consolidated GPT-5 API.

**Solution**:
1. Remove faulty thinking→reasoning conversion from LLMS Anthropic transformer
2. Update OpenAI transformer to reject ALL reasoning parameters (OpenAI consolidated to GPT-5)
3. Use only `reasoning_effort` parameter format for GPT-5 models

**Architecture Fix**: Maintain strict separation - CCR handles routing, LLMS handles transformations.

**Status**: Root cause identified, fix pending implementation.

**Documentation**: Complete analysis in `/Users/fredrikbranstrom/ccr-dev/GPT5_REASONING_DEBUG_MASTER.md` and `/Users/fredrikbranstrom/ccr-dev/DEBUG_PLAN_RESULTS.md`
Loading