fix not working without router

This commit is contained in:
musi
2025-06-15 20:45:32 +08:00
parent ee8b82947d
commit a3ec2c223d
4 changed files with 15 additions and 9 deletions

View File

@@ -25,7 +25,7 @@ npm install -g @musistudio/claude-code-router
ccr code ccr code
``` ```
4. Configure routing[optional] 4. Configure routing[optional]
Set up your `~/claude-code-router/config.json` file like this: Set up your `~/claude-code-router/config.json` file like this:
```json ```json
{ {

View File

@@ -1,6 +1,6 @@
{ {
"name": "@musistudio/claude-code-router", "name": "@musistudio/claude-code-router",
"version": "1.0.4", "version": "1.0.5",
"description": "Use Claude Code without an Anthropics account and route it to another LLM provider", "description": "Use Claude Code without an Anthropics account and route it to another LLM provider",
"bin": { "bin": {
"ccr": "./dist/cli.js" "ccr": "./dist/cli.js"

View File

@@ -138,6 +138,12 @@ async function run(options: RunOptions = {}) {
config?.Router?.longContext config?.Router?.longContext
) { ) {
server.useMiddleware(router); server.useMiddleware(router);
} else {
server.useMiddleware((req, res, next) => {
req.provider = "default";
req.body.model = config.OPENAI_MODEL;
next();
});
} }
server.useMiddleware(formatRequest); server.useMiddleware(formatRequest);

View File

@@ -18,13 +18,13 @@ export async function executeCodeCommand(args: string[] = []) {
// Increment reference count when command starts // Increment reference count when command starts
incrementReferenceCount(); incrementReferenceCount();
// Execute claude command // Execute claude command
const claudePath = process.env.CLAUDE_PATH || "claude"; const claudePath = process.env.CLAUDE_PATH || "claude";
const claudeProcess = spawn(claudePath, args, { const claudeProcess = spawn(claudePath, args, {
env, env,
stdio: "inherit", stdio: "inherit",
shell: true shell: true
}); });
claudeProcess.on("error", (error) => { claudeProcess.on("error", (error) => {
console.error("Failed to start claude command:", error.message); console.error("Failed to start claude command:", error.message);