@alexeiled/claude-router 0.4.0 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "router",
3
3
  "displayName": "Router",
4
- "version": "0.4.0",
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
- only requests for `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
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
@@ -6,7 +6,7 @@
6
6
  | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
7
7
  | TypeSafe API key | `TYPESAFE_API_KEY` in the environment of the gateway | One name in all places. The key is never in a file. |
8
8
  | The key for an installed plugin | The plugin option `typesafe_api_key`. Claude Code asks for it when you enable the plugin and stores it in the macOS Keychain. The `SessionStart` hook gives it to the gateway as `TYPESAFE_API_KEY`. | Claude Code exports plugin options as `CLAUDE_PLUGIN_OPTION_<KEY>`. The gateway does not read that name. |
9
- | Claude Code settings | `~/.claude/settings.json`: `model`, `env.ANTHROPIC_BASE_URL`, the picker row, the status line. `/router:setup` writes them. | Claude Code reads the base URL at start. A plugin cannot set it. |
9
+ | Claude Code settings | `~/.claude/settings.json`: `model`, `env.ANTHROPIC_BASE_URL`, the `modelPicker` row, the status line. `/router:setup` writes them. | Claude Code reads the base URL at start. A plugin cannot set it. |
10
10
  | Routing configuration | `~/.claude/router.json`, user scope only | A cloned repository must not change your routing or your spend. |
11
11
 
12
12
  The gateway ignores project files. To use another file, set
@@ -20,21 +20,36 @@ 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
- "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000",
27
- "ANTHROPIC_CUSTOM_MODEL_OPTION": "router",
28
- "ANTHROPIC_CUSTOM_MODEL_OPTION_NAME": "Router (auto)",
29
- "ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION": "Picks Opus 5.5 / Sonnet 5 / Haiku 4.5 and the effort for each turn"
26
+ "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000"
27
+ },
28
+ "modelPicker": {
29
+ "options": [
30
+ {
31
+ "model": "jev-router",
32
+ "label": "Jev Router (auto)",
33
+ "description": "Auto-selects the model and effort for each turn",
34
+ "behavesAs": "claude-opus-5-5"
35
+ }
36
+ ]
30
37
  }
31
38
  }
32
39
  ```
33
40
 
34
- The three `ANTHROPIC_CUSTOM_MODEL_OPTION*` keys add a `Router (auto)` row to
35
- the `/model` picker.
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
+ catalog. Setup also removes the `ANTHROPIC_CUSTOM_MODEL_OPTION*` keys that
45
+ older versions wrote. Before 0.4.2 the alias was `router`; the gateway still
46
+ routes it, and setup replaces that row.
47
+
48
+ Setup writes the file as its last step. Restart Claude Code after it. Until
49
+ the restart, the session sends `jev-router` to Anthropic and shows "There's an
50
+ issue with the selected model (jev-router)".
36
51
 
37
- 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.
38
53
  `CLAUDE_CODE_MAX_CONTEXT_TOKENS` declares the real window: the largest
39
54
  `contextWindow` of the routed models, 1M by default. The gateway sends a turn
40
55
  only to a model whose window holds the context with room to spare (80%). A
@@ -53,7 +68,7 @@ If you agree, it also wraps the status line command:
53
68
  ```
54
69
 
55
70
  The wrapper runs the command after it, then adds one line for a routed
56
- session, for example `router ▸ opus-5-5 · xhigh`. Without a command
71
+ session, for example `jev-router ▸ opus-5-5 · xhigh`. Without a command
57
72
  after it, it prints only that line. The path contains the plugin version, so
58
73
  run `/router:setup` again after a plugin update.
59
74
 
@@ -75,7 +90,7 @@ path. Nested objects merge.
75
90
  {
76
91
  "gateway": {
77
92
  "port": 43170,
78
- "alias": "router",
93
+ "alias": "jev-router",
79
94
  "baselineTier": "low",
80
95
  "auxiliaryTier": "low",
81
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexeiled/claude-router",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Claude Code plugin: auto-picks the right model and effort for each turn using Jev routing.",
5
5
  "license": "MIT",
6
6
  "author": "Alexei Ledenev",
@@ -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,
@@ -5,21 +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. Do these steps:
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
- 1. Read `~/.claude/settings.json`. If the file does not exist, start from `{}`.
11
- 2. Set the key `model` to `"router"`.
12
- 3. Set the key `env.ANTHROPIC_BASE_URL` to `"http://127.0.0.1:43170"`. If `~/.claude/router.json` sets `gateway.port`, use that port.
13
- 4. Set these keys in `env`, for the `/model` picker row:
14
- - `ANTHROPIC_CUSTOM_MODEL_OPTION`: `"router"`
15
- - `ANTHROPIC_CUSTOM_MODEL_OPTION_NAME`: `"Router (auto)"`
16
- - `ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION`: `"Auto-selects the model and effort for each turn"`
17
- 5. Set the key `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS` to `"1000000"`. Claude Code does not know the model `router` and assumes a 200K window without this key. If `~/.claude/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.
18
- 6. Keep every other key unchanged. Write the file.
19
- 7. 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.
20
- 8. Tell the user:
21
- - Restart Claude Code. Then the router serves each turn, and `/router:status` shows the routes and the last turn.
10
+ 1. Read `~/.claude/settings.json`. If the file does not exist, start from `{}`. Read `~/.claude/router.json` if it exists.
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
+ 3. Prepare the new settings object in memory:
13
+ - `model`: `"jev-router"`.
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 `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
+ - 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
+ - The `statusLine` change from step 2, if the user agreed.
21
+ - Keep every other key unchanged.
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 (jev-router)", because it still sends requests to Anthropic and not to the gateway.
24
+ - After the restart, the router serves each turn, and `/router:status` shows the routes and the last turn.
22
25
  - The status line path contains the plugin version. After a plugin update, run `/router:setup` again.
23
- - To stop the routing, remove `model`, `env.ANTHROPIC_BASE_URL`, `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS` and the three `ANTHROPIC_CUSTOM_MODEL_OPTION*` keys, 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
+ 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.
24
28
 
25
29
  Do not change any other file.