add plugins

This commit is contained in:
jinhui.li
2025-06-18 12:20:07 +08:00
parent 84cb9a2009
commit 57a7da14a3
6 changed files with 77 additions and 22 deletions

View File

@@ -2,7 +2,6 @@
> This is a tool for routing Claude Code requests to different models, and you can customize any request. > This is a tool for routing Claude Code requests to different models, and you can customize any request.
![](screenshoots/claude-code.png) ![](screenshoots/claude-code.png)
## Usage ## Usage
@@ -26,7 +25,8 @@ 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
{ {
"OPENAI_API_KEY": "sk-xxx", "OPENAI_API_KEY": "sk-xxx",
@@ -64,33 +64,61 @@ Set up your `~/.claude-code-router/config.json` file like this:
} }
} }
``` ```
- `background`
This model will be used to handle some background tasks([background-token-usage](https://docs.anthropic.com/en/docs/claude-code/costs#background-token-usage)). Based on my tests, it doesnt require high intelligence. Im using the qwen-coder-2.5:7b model running locally on my MacBook Pro M1 (32GB) via Ollama.
If your computer cant run Ollama, you can also use some free models, such as qwen-coder-2.5:3b.
- `background`
This model will be used to handle some background tasks([background-token-usage](https://docs.anthropic.com/en/docs/claude-code/costs#background-token-usage)). Based on my tests, it doesnt require high intelligence. Im using the qwen-coder-2.5:7b model running locally on my MacBook Pro M1 (32GB) via Ollama.
If your computer cant run Ollama, you can also use some free models, such as qwen-coder-2.5:3b.
- `think` - `think`
This model will be used when enabling Claude Code to perform reasoning. However, reasoning budget control has not yet been implemented (since the DeepSeek-R1 model does not support it), so there is currently no difference between using UltraThink and Think modes. This model will be used when enabling Claude Code to perform reasoning. However, reasoning budget control has not yet been implemented (since the DeepSeek-R1 model does not support it), so there is currently no difference between using UltraThink and Think modes.
It is worth noting that Plan Mode also use this model to achieve better planning results. It is worth noting that Plan Mode also use this model to achieve better planning results.
Note: The reasoning process via the official DeepSeek API may be very slow, so you may need to wait for an extended period of time. Note: The reasoning process via the official DeepSeek API may be very slow, so you may need to wait for an extended period of time.
- `longContext` - `longContext`
This model will be used when the context length exceeds 32K (this value may be modified in the future). You can route the request to a model that performs well with long contexts (Ive chosen google/gemini-2.5-pro-preview). This scenario has not been thoroughly tested yet, so if you encounter any issues, please submit an issue. This model will be used when the context length exceeds 32K (this value may be modified in the future). You can route the request to a model that performs well with long contexts (Ive chosen google/gemini-2.5-pro-preview). This scenario has not been thoroughly tested yet, so if you encounter any issues, please submit an issue.
- model command - model command
You can also switch models within Claude Code by using the `/model` command. The format is: `provider,model`, like this: You can also switch models within Claude Code by using the `/model` command. The format is: `provider,model`, like this:
`/model openrouter,anthropic/claude-3.5-sonnet` `/model openrouter,anthropic/claude-3.5-sonnet`
This will use the anthropic/claude-3.5-sonnet model provided by OpenRouter to handle all subsequent tasks. This will use the anthropic/claude-3.5-sonnet model provided by OpenRouter to handle all subsequent tasks.
## Features ## Features
- [x] Plugins - [x] Plugins
- [x] Support change models - [x] Support change models
- [ ] Support scheduled tasks - [ ] Support scheduled tasks
## Plugins
You can modify or enhance Claude Codes functionality by installing plugins. The mechanism works by using middleware to modify request parameters — this allows you to rewrite prompts or add/remove tools.
To use a plugin, place it in the ~/.claude-code-router/plugins/ directory and specify the plugin name in config.js using the `usePlugins` option.like this
```json
// ~/.claud-code-router/config.json
{
...,
"usePlugins": ["notebook-tools-filter", "toolcall-improvement*"]
}
```
Currently, the following plugins are available:
- **notebook-tools-filter**
This plugin filters out tool calls related to Jupyter notebooks (.ipynb files). You can use it if your work does not involve Jupyter.
- **toolcall-improvement**
If your LLM doesnt handle tool usage well (for example, always returning code as plain text instead of modifying files — such as with deepseek-v3), you can use this plugin.
This plugin simply adds the following system prompt. If you have a better prompt, you can modify it.
```markdown
## **Important Instruction:**
You must use tools as frequently and accurately as possible to help the user solve their problem.
Prioritize tool usage whenever it can enhance accuracy, efficiency, or the quality of the response.
```
## Some tips: ## Some tips:
Now you can use deepseek-v3 models directly without using any plugins. Now you can use deepseek-v3 models directly without using any plugins.
If youre using the DeepSeek API provided by the official website, you might encounter an “exceeding context” error after several rounds of conversation (since the official API only supports a 64K context window). In this case, youll need to discard the previous context and start fresh. Alternatively, you can use ByteDances DeepSeek API, which offers a 128K context window and supports KV cache. If youre using the DeepSeek API provided by the official website, you might encounter an “exceeding context” error after several rounds of conversation (since the official API only supports a 64K context window). In this case, youll need to discard the previous context and start fresh. Alternatively, you can use ByteDances DeepSeek API, which offers a 128K context window and supports KV cache.
@@ -102,13 +130,21 @@ Note: claude code consumes a huge amount of tokens, but thanks to DeepSeeks l
Some interesting points: Based on my testing, including a lot of context information can help narrow the performance gap between these LLM models. For instance, when I used Claude-4 in VSCode Copilot to handle a Flutter issue, it messed up the files in three rounds of conversation, and I had to roll everything back. However, when I used claude code with DeepSeek, after three or four rounds of conversation, I finally managed to complete my task—and the cost was less than 1 RMB! Some interesting points: Based on my testing, including a lot of context information can help narrow the performance gap between these LLM models. For instance, when I used Claude-4 in VSCode Copilot to handle a Flutter issue, it messed up the files in three rounds of conversation, and I had to roll everything back. However, when I used claude code with DeepSeek, after three or four rounds of conversation, I finally managed to complete my task—and the cost was less than 1 RMB!
## Some articles: ## Some articles:
1. [Project Motivation and Principles](blog/en/project-motivation-and-how-it-works.md) ([中文版看这里](blog/zh/项目初衷及原理.md))
1. [Project Motivation and Principles](blog/en/project-motivation-and-how-it-works.md) ([中文版看这里](blog/zh/项目初衷及原理.md))
## Buy me a coffee ## Buy me a coffee
If you find this project helpful, you can choose to sponsor the author with a cup of coffee. If you find this project helpful, you can choose to sponsor the author with a cup of coffee.
[Buy me a coffee](http://paypal.me/musistudio1999) [Buy me a coffee](https://ko-fi.com/musistudio)
<div style="display: flex; justify-content: space-between;gap:10px;">
<img src="blog/images/alipay.jpg" alt="alipay" style="width:48%" />
<img src="blog/images/wechat.jpg" alt="wechat" style="width:48%"/>
</div>
## Sponsors ## Sponsors
Thanks to the following sponsors: Thanks to the following sponsors:
@Simon Leischnig (If you see this, feel free to contact me and I can update it with your GitHub information) @Simon Leischnig (If you see this, feel free to contact me and I can update it with your GitHub information)

BIN
blog/images/alipay.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

BIN
blog/images/wechat.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

@@ -0,0 +1,7 @@
module.exports = async function handle(req, res) {
if (req?.body?.tools?.length) {
req.body.tools = req.body.tools.filter(
(tool) => !["NotebookRead", "NotebookEdit", "mcp__ide__executeCode"].includes(tool.name)
);
}
};

View File

@@ -0,0 +1,8 @@
module.exports = async function handle(req, res) {
if (req?.body?.tools?.length) {
req.body.system.push({
type: "text",
text: `## **Important Instruction:** \nYou must use tools as frequently and accurately as possible to help the user solve their problem.\nPrioritize tool usage whenever it can enhance accuracy, efficiency, or the quality of the response.`
})
}
};

View File

@@ -68,7 +68,11 @@ export const router = async (
JSON.stringify(contentPart.input) JSON.stringify(contentPart.input)
).length; ).length;
} else if (contentPart.type === "tool_result") { } else if (contentPart.type === "tool_result") {
tokenCount += enc.encode(contentPart.content || "").length; tokenCount += enc.encode(
typeof contentPart.content === "string"
? contentPart.content
: JSON.stringify(contentPart.content)
).length;
} }
}); });
} }