@alexeiled/claude-router 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +8 -8
- package/docs/configuration.md +13 -12
- package/docs/design.md +1 -1
- package/docs/user-guide.md +4 -4
- package/lib/config.mjs +4 -1
- package/lib/router.mjs +2 -1
- package/lib/status.mjs +1 -1
- package/package.json +1 -1
- package/scripts/statusline.mjs +2 -1
- package/skills/setup/SKILL.md +8 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "router",
|
|
3
3
|
"displayName": "Router",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"description": "Auto-picks the right Claude model for each turn — small models for quick edits, mid-tier for code, frontier for hard problems. Uses Jev to classify each request.",
|
|
6
6
|
"author": { "name": "Alexei Ledenev", "url": "https://github.com/alexei-led" },
|
|
7
7
|
"repository": "https://github.com/alexei-led/claude-router",
|
package/README.md
CHANGED
|
@@ -16,13 +16,13 @@ runtime dependencies and needs Node 22 or later.
|
|
|
16
16
|
## How it works
|
|
17
17
|
|
|
18
18
|
```
|
|
19
|
-
Claude Code --model router ──▶ gateway 127.0.0.1:43170 ──▶ api.anthropic.com
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
Claude Code --model jev-router ──▶ gateway 127.0.0.1:43170 ──▶ api.anthropic.com
|
|
20
|
+
│
|
|
21
|
+
only requests for `jev-router`: ├─ facts.mjs prompt, continuation, failures
|
|
22
|
+
├─ jev.mjs one Choice (tier) + one Noul (continuation?)
|
|
23
|
+
├─ policy.mjs stickiness, escalation, cost-gated votes
|
|
24
|
+
├─ rewrite.mjs model, effort, thinking per model family
|
|
25
|
+
└─ store.mjs session memory, decisions.jsonl
|
|
26
26
|
responses go through unchanged; the gateway reads `usage` (context size, cache TTL)
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -95,7 +95,7 @@ git config --local core.hooksPath scripts/git-hooks # pre-commit: biome + gitl
|
|
|
95
95
|
npm test # node:test
|
|
96
96
|
npm run check # biome lint and format
|
|
97
97
|
npm run validate # claude plugin validate
|
|
98
|
-
claude --plugin-dir . --model router # with ANTHROPIC_BASE_URL and TYPESAFE_API_KEY set
|
|
98
|
+
claude --plugin-dir . --model jev-router # with ANTHROPIC_BASE_URL and TYPESAFE_API_KEY set
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
Releases: push a signed tag `v<version>` that matches `package.json`. The
|
package/docs/configuration.md
CHANGED
|
@@ -20,7 +20,7 @@ starts it again.
|
|
|
20
20
|
|
|
21
21
|
```json
|
|
22
22
|
{
|
|
23
|
-
"model": "router",
|
|
23
|
+
"model": "jev-router",
|
|
24
24
|
"env": {
|
|
25
25
|
"ANTHROPIC_BASE_URL": "http://127.0.0.1:43170",
|
|
26
26
|
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000"
|
|
@@ -28,8 +28,8 @@ starts it again.
|
|
|
28
28
|
"modelPicker": {
|
|
29
29
|
"options": [
|
|
30
30
|
{
|
|
31
|
-
"model": "router",
|
|
32
|
-
"label": "Router (auto)",
|
|
31
|
+
"model": "jev-router",
|
|
32
|
+
"label": "Jev Router (auto)",
|
|
33
33
|
"description": "Auto-selects the model and effort for each turn",
|
|
34
34
|
"behavesAs": "claude-opus-5-5"
|
|
35
35
|
}
|
|
@@ -38,17 +38,18 @@ starts it again.
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
The `modelPicker` row adds `Router (auto)` to the `/model` picker, next to the
|
|
42
|
-
built-in rows. `behavesAs` maps `router` to a model that Claude Code knows.
|
|
43
|
-
Without it, Claude Code rejects `router` because the model is not in its
|
|
41
|
+
The `modelPicker` row adds `Jev Router (auto)` to the `/model` picker, next to the
|
|
42
|
+
built-in rows. `behavesAs` maps `jev-router` to a model that Claude Code knows.
|
|
43
|
+
Without it, Claude Code rejects `jev-router` because the model is not in its
|
|
44
44
|
catalog. Setup also removes the `ANTHROPIC_CUSTOM_MODEL_OPTION*` keys that
|
|
45
|
-
older versions wrote.
|
|
45
|
+
older versions wrote. Before 0.4.2 the alias was `router`; the gateway still
|
|
46
|
+
routes it, and setup replaces that row.
|
|
46
47
|
|
|
47
48
|
Setup writes the file as its last step. Restart Claude Code after it. Until
|
|
48
|
-
the restart, the session sends `router` to Anthropic and shows "There's an
|
|
49
|
-
issue with the selected model (router)".
|
|
49
|
+
the restart, the session sends `jev-router` to Anthropic and shows "There's an
|
|
50
|
+
issue with the selected model (jev-router)".
|
|
50
51
|
|
|
51
|
-
Claude Code does not know the model `router`, so it assumes a 200K window.
|
|
52
|
+
Claude Code does not know the model `jev-router`, so it assumes a 200K window.
|
|
52
53
|
`CLAUDE_CODE_MAX_CONTEXT_TOKENS` declares the real window: the largest
|
|
53
54
|
`contextWindow` of the routed models, 1M by default. The gateway sends a turn
|
|
54
55
|
only to a model whose window holds the context with room to spare (80%). A
|
|
@@ -67,7 +68,7 @@ If you agree, it also wraps the status line command:
|
|
|
67
68
|
```
|
|
68
69
|
|
|
69
70
|
The wrapper runs the command after it, then adds one line for a routed
|
|
70
|
-
session, for example `router ▸ opus-5-5 · xhigh`. Without a command
|
|
71
|
+
session, for example `jev-router ▸ opus-5-5 · xhigh`. Without a command
|
|
71
72
|
after it, it prints only that line. The path contains the plugin version, so
|
|
72
73
|
run `/router:setup` again after a plugin update.
|
|
73
74
|
|
|
@@ -89,7 +90,7 @@ path. Nested objects merge.
|
|
|
89
90
|
{
|
|
90
91
|
"gateway": {
|
|
91
92
|
"port": 43170,
|
|
92
|
-
"alias": "router",
|
|
93
|
+
"alias": "jev-router",
|
|
93
94
|
"baselineTier": "low",
|
|
94
95
|
"auxiliaryTier": "low",
|
|
95
96
|
"idleShutdownMs": 7200000
|
package/docs/design.md
CHANGED
|
@@ -10,7 +10,7 @@ terminal interface.
|
|
|
10
10
|
|
|
11
11
|
## Mechanism: local gateway (2026-09-22)
|
|
12
12
|
|
|
13
|
-
Claude Code runs with `--model router`. `ANTHROPIC_BASE_URL` points at a
|
|
13
|
+
Claude Code runs with `--model jev-router`. `ANTHROPIC_BASE_URL` points at a
|
|
14
14
|
gateway on `127.0.0.1`. The gateway sends each request to `api.anthropic.com`
|
|
15
15
|
unchanged, except a request whose `model` is the alias. For that request, the
|
|
16
16
|
gateway reads facts from the body, asks Jev once for each new user turn, runs
|
package/docs/user-guide.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Start a session
|
|
4
4
|
|
|
5
5
|
After the install steps in the README, run `claude` as usual. Claude Code shows
|
|
6
|
-
`Router (auto)` as the model. The transcript records the model that answered
|
|
6
|
+
`Jev Router (auto)` as the model. The transcript records the model that answered
|
|
7
7
|
each message. The first session starts the gateway, and all sessions share it.
|
|
8
8
|
The gateway continues to run after a session ends. After two hours without
|
|
9
9
|
requests it exits, unless a turn waits for a tool result, for example a
|
|
@@ -14,7 +14,7 @@ To try the gateway in one session without a change to the configuration:
|
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
TYPESAFE_API_KEY=… node scripts/gateway.mjs &
|
|
17
|
-
ANTHROPIC_BASE_URL=http://127.0.0.1:43170 claude --plugin-dir . --model router
|
|
17
|
+
ANTHROPIC_BASE_URL=http://127.0.0.1:43170 claude --plugin-dir . --model jev-router
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## What happens at each prompt
|
|
@@ -69,7 +69,7 @@ reason of the last turn in this session.
|
|
|
69
69
|
The status line wrapper from `/router:setup` adds one line to your status line
|
|
70
70
|
while the session uses the router:
|
|
71
71
|
|
|
72
|
-
- `router ▸ opus-5-5 · xhigh`: the model and the effort of the last turn.
|
|
72
|
+
- `jev-router ▸ opus-5-5 · xhigh`: the model and the effort of the last turn.
|
|
73
73
|
- `router: no turn yet`: the session has no routed turn.
|
|
74
74
|
- `router: gateway off, the next prompt starts it`: the gateway stopped after
|
|
75
75
|
idle time, or it crashed. Either way the next prompt starts it.
|
|
@@ -97,7 +97,7 @@ assistant message in a Claude Code transcript.
|
|
|
97
97
|
|
|
98
98
|
## Troubleshooting
|
|
99
99
|
|
|
100
|
-
- If Claude Code does not accept `router` as a model, make sure that the
|
|
100
|
+
- If Claude Code does not accept `jev-router` as a model, make sure that the
|
|
101
101
|
gateway runs and that `ANTHROPIC_BASE_URL` is set. The command
|
|
102
102
|
`curl http://127.0.0.1:43170/v1/models` lists the alias.
|
|
103
103
|
- If Claude Code reports that it does not use the gateway, run
|
package/lib/config.mjs
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
export const TIERS = ['micro', 'low', 'medium', 'high'];
|
|
4
4
|
export const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
5
5
|
|
|
6
|
+
// The alias before 0.4.2. Settings written by an older /router:setup still send it; drop it once they are rare.
|
|
7
|
+
export const LEGACY_ALIAS = 'router';
|
|
8
|
+
|
|
6
9
|
export const DEFAULTS = {
|
|
7
10
|
// `idleShutdownMs`: the gateway exits after this long without requests while no turn waits for a tool result;
|
|
8
11
|
// the hooks start it again before the next prompt. Two hours outlast /loop wakeups and Monitor waits (up to one
|
|
9
12
|
// hour), which reach the gateway without a prompt. 0 keeps it running.
|
|
10
|
-
gateway: { port: 43170, alias: 'router', baselineTier: 'low', auxiliaryTier: 'low', idleShutdownMs: 7_200_000 },
|
|
13
|
+
gateway: { port: 43170, alias: 'jev-router', baselineTier: 'low', auxiliaryTier: 'low', idleShutdownMs: 7_200_000 },
|
|
11
14
|
// `high` and `medium` share one model and differ by effort: Opus 5.5 at xhigh is the strongest
|
|
12
15
|
// setting this router can ask for, and the tier ladder stays four wide for the policy.
|
|
13
16
|
routes: {
|
package/lib/router.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Per-request orchestration: facts -> advice -> policy -> rewritten body. Knows nothing about HTTP.
|
|
2
|
+
import { LEGACY_ALIAS } from './config.mjs';
|
|
2
3
|
import { nextContextTokens } from './cost.mjs';
|
|
3
4
|
import { factsFromRequest } from './facts.mjs';
|
|
4
5
|
import { askJev } from './jev.mjs';
|
|
@@ -38,7 +39,7 @@ export class Router {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
isRouted(body) {
|
|
41
|
-
return body?.model === this.config.gateway.alias;
|
|
42
|
+
return body?.model === this.config.gateway.alias || body?.model === LEGACY_ALIAS;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
// Returns { body, tier, reason, auxiliary }. The caller forwards `body` and records the response
|
package/lib/status.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export function isOlderVersion(running, current) {
|
|
|
17
17
|
|
|
18
18
|
export const STATUS_PATH = '/router/status';
|
|
19
19
|
// The name of the alias in the /model picker and in discovery.
|
|
20
|
-
export const ROUTER_DISPLAY_NAME = 'Router (auto)';
|
|
20
|
+
export const ROUTER_DISPLAY_NAME = 'Jev Router (auto)';
|
|
21
21
|
const FETCH_TIMEOUT_MS = 300;
|
|
22
22
|
|
|
23
23
|
export function statusSnapshot(config, memory) {
|
package/package.json
CHANGED
package/scripts/statusline.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// A wrapped command (for example claude-powerline) gets the same stdin; its output comes first.
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { text } from 'node:stream/consumers';
|
|
7
|
+
import { LEGACY_ALIAS } from '../lib/config.mjs';
|
|
7
8
|
import { loadRuntime } from '../lib/runtime.mjs';
|
|
8
9
|
import { fetchStatus, ROUTER_DISPLAY_NAME, statusSegment } from '../lib/status.mjs';
|
|
9
10
|
|
|
@@ -15,7 +16,7 @@ try {
|
|
|
15
16
|
payload = JSON.parse(input);
|
|
16
17
|
} catch {}
|
|
17
18
|
|
|
18
|
-
const names = [config.gateway.alias, ROUTER_DISPLAY_NAME];
|
|
19
|
+
const names = [config.gateway.alias, LEGACY_ALIAS, ROUTER_DISPLAY_NAME];
|
|
19
20
|
const routed = [payload.model?.id, payload.model?.display_name].some((name) => names.includes(name));
|
|
20
21
|
const [status] = await Promise.all([
|
|
21
22
|
routed ? fetchStatus(config.gateway.port, payload.session_id) : null,
|
package/skills/setup/SKILL.md
CHANGED
|
@@ -5,25 +5,25 @@ disable-model-invocation: true
|
|
|
5
5
|
allowed-tools: Read, Edit, Write
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Configure Claude Code for the router gateway. This session does not use the gateway until Claude Code restarts. When the file has `model: "router"`, this session can fail its next request. So ask all questions first, write the file once, and write it last.
|
|
8
|
+
Configure Claude Code for the router gateway. This session does not use the gateway until Claude Code restarts. When the file has `model: "jev-router"`, this session can fail its next request. So ask all questions first, write the file once, and write it last.
|
|
9
9
|
|
|
10
10
|
1. Read `~/.claude/settings.json`. If the file does not exist, start from `{}`. Read `~/.claude/router.json` if it exists.
|
|
11
11
|
2. The status line can show the model and effort of the last routed turn. The command is `node ${CLAUDE_PLUGIN_ROOT}/scripts/statusline.mjs`, followed by the current status line command if there is one (for example `node ${CLAUDE_PLUGIN_ROOT}/scripts/statusline.mjs claude-powerline`). Show the user the current `statusLine` value and the new one, and ask. Change `statusLine.command` only if the user agrees. Keep the other `statusLine` keys.
|
|
12
12
|
3. Prepare the new settings object in memory:
|
|
13
|
-
- `model`: `"router"`.
|
|
13
|
+
- `model`: `"jev-router"`.
|
|
14
14
|
- `env.ANTHROPIC_BASE_URL`: `"http://127.0.0.1:43170"`. If `router.json` sets `gateway.port`, use that port.
|
|
15
|
-
- `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS`: `"1000000"`. Claude Code does not know the model `router` and assumes a 200K window without this key. If `router.json` changes `routes` or `models`, use the largest `contextWindow` of the models that the routes use. The gateway sends a turn only to a model whose window holds the context.
|
|
16
|
-
- The `/model` picker row. In `modelPicker.options`, replace the row whose `model` is `"router"
|
|
17
|
-
`{ "model": "router", "label": "Router (auto)", "description": "Auto-selects the model and effort for each turn", "behavesAs": "claude-opus-5-5" }`.
|
|
18
|
-
If `modelPicker` does not exist, set it to `{ "options": [<the row>] }`. Keep the other rows and `replaceBuiltInOptions`. `behavesAs` names a model that Claude Code knows; without it, Claude Code rejects `router` as a model that is not in its catalog. If `router.json` changes the `high` route, use the `id` of its model.
|
|
15
|
+
- `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS`: `"1000000"`. Claude Code does not know the model `jev-router` and assumes a 200K window without this key. If `router.json` changes `routes` or `models`, use the largest `contextWindow` of the models that the routes use. The gateway sends a turn only to a model whose window holds the context.
|
|
16
|
+
- The `/model` picker row. In `modelPicker.options`, replace the row whose `model` is `"jev-router"` or `"router"` (the name before 0.4.2), or append it if there is none:
|
|
17
|
+
`{ "model": "jev-router", "label": "Jev Router (auto)", "description": "Auto-selects the model and effort for each turn", "behavesAs": "claude-opus-5-5" }`.
|
|
18
|
+
If `modelPicker` does not exist, set it to `{ "options": [<the row>] }`. Keep the other rows and `replaceBuiltInOptions`. `behavesAs` names a model that Claude Code knows; without it, Claude Code rejects `jev-router` as a model that is not in its catalog. If `router.json` changes the `high` route, use the `id` of its model.
|
|
19
19
|
- Remove `env.ANTHROPIC_CUSTOM_MODEL_OPTION`, `env.ANTHROPIC_CUSTOM_MODEL_OPTION_NAME` and `env.ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION`. Older versions of this setup wrote them; the `modelPicker` row replaces them.
|
|
20
20
|
- The `statusLine` change from step 2, if the user agreed.
|
|
21
21
|
- Keep every other key unchanged.
|
|
22
22
|
4. Tell the user, before you write the file:
|
|
23
|
-
- Restart Claude Code now. Until the restart, this session can show "There's an issue with the selected model (router)", because it still sends requests to Anthropic and not to the gateway.
|
|
23
|
+
- Restart Claude Code now. Until the restart, this session can show "There's an issue with the selected model (jev-router)", because it still sends requests to Anthropic and not to the gateway.
|
|
24
24
|
- After the restart, the router serves each turn, and `/router:status` shows the routes and the last turn.
|
|
25
25
|
- The status line path contains the plugin version. After a plugin update, run `/router:setup` again.
|
|
26
|
-
- To stop the routing, remove `model`, `env.ANTHROPIC_BASE_URL`, `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS` and the `router` row of `modelPicker.options`, and restore the status line command.
|
|
26
|
+
- To stop the routing, remove `model`, `env.ANTHROPIC_BASE_URL`, `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS` and the `jev-router` row of `modelPicker.options`, and restore the status line command.
|
|
27
27
|
5. Write the whole object to `~/.claude/settings.json` with one Write call. Do not use a sequence of edits. Do nothing after this step.
|
|
28
28
|
|
|
29
29
|
Do not change any other file.
|