@alexeiled/claude-router 1.23.0 → 1.23.1

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": "1.23.0",
4
+ "version": "1.23.1",
5
5
  "description": "Native model and effort routing within your provider. Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, classifier advice and one model per subagent.",
6
6
  "author": {
7
7
  "name": "Alexei Ledenev",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.1 (2026-11-15)
4
+
5
+ ### Fixed
6
+
7
+ - `cost` mode takes the tier below only when its model is cheaper per turn: a lower cache-read price, or an equal one and a lower input price. It compared input prices only, so in a mixed profile it could move to a model with a cheaper input but a dearer cache read (for example GLM-5.3-Flash below DeepSeek V4.1 Flash), which costs more on long sessions where almost all input is cache reads.
8
+ - A same-task move inside a tier waits for the dwell and a checkpoint by the same order, so the hold and `cost` mode agree on which model is cheaper.
9
+
10
+ ### Upgrade
11
+
12
+ Restart Claude Code after updating. In a mixed profile, a mid-task move to a model that is cheaper per turn now waits for the dwell and a checkpoint, as a tier downgrade does. No configuration is changed automatically.
13
+
3
14
  ## 1.23.0 (2026-11-15)
4
15
 
5
16
  ### Changed
@@ -115,7 +115,7 @@ At session start the incumbent is the session's model. `cellForModel` looks for
115
115
 
116
116
  ## Routing modes
117
117
 
118
- The routing mode (`lib/modes.mjs`) is a fixed transform of the configured routes, applied before policy. At `turn.start` the hook resolves the mode (session override in `$.store` `routing-mode:<session id>`, then the project's `.claude/router.json`, then `mode` in the profile `router.json`, then `balanced`) and stores `applyMode(router.config, mode)` as the turn's config: every tier's and activity's route as `modeRoute` gives it, and `modes[mode].policy` over `policy`. Every later read of the turn (policy, escalation, cache keys, activity order, the request) uses that one table. `modeRoute` always starts from the configured routes, so a turn never steps from a route a mode already moved. `cost` takes the route of the tier below (at `low`, the `low` route without its activity override; never `micro`) when its model has a lower input price, else one listed effort level less, and `high` always keeps its model; `quality` one listed effort level more, else the tier above's route. `micro` and pins keep the configured route.
118
+ The routing mode (`lib/modes.mjs`) is a fixed transform of the configured routes, applied before policy. At `turn.start` the hook resolves the mode (session override in `$.store` `routing-mode:<session id>`, then the project's `.claude/router.json`, then `mode` in the profile `router.json`, then `balanced`) and stores `applyMode(router.config, mode)` as the turn's config: every tier's and activity's route as `modeRoute` gives it, and `modes[mode].policy` over `policy`. Every later read of the turn (policy, escalation, cache keys, activity order, the request) uses that one table. `modeRoute` always starts from the configured routes, so a turn never steps from a route a mode already moved. `cost` takes the route of the tier below (at `low`, the `low` route without its activity override; never `micro`) when its model is cheaper per turn (`cheaperPerTurn` in `lib/cost.mjs`: the cache-read price, then the input price; the same order holds a same-task lateral move in `lib/activity.mjs`), else one listed effort level less, and `high` always keeps its model; `quality` one listed effort level more, else the tier above's route. `micro` and pins keep the configured route.
119
119
 
120
120
  **Route in use.** The loop keeps the route the last decision ran (`loop.route`, models key and effort) instead of rebuilding it from config. The incumbent's price, cache key and order come from it, and a decision that stays on the incumbent's cell keeps running it. So a mode change, or a route edit, reaches the request only through a gate: a tier switch, a taken lateral move, or a pin. A loop saved before 1.15 has no `loop.route` and rebuilds it once.
121
121
 
@@ -5,7 +5,7 @@ your routes stay as they are. The mode moves the route each tier runs by one fix
5
5
 
6
6
  | Mode | What changes |
7
7
  | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8
- | `cost` | A cheaper route where the turn allows it: the tier below when that tier runs a model with a lower input price (at `low`, the `low` route without its activity override), else one effort level less on the same model. `high` keeps its model and drops one effort level. Never below `low`. |
8
+ | `cost` | A cheaper route where the turn allows it: the tier below when that tier runs a model that is cheaper per turn: a lower cache-read price, or an equal one and a lower input price (at `low`, the `low` route without its activity override), else one effort level less on the same model. `high` keeps its model and drops one effort level. Never below `low`. |
9
9
  | `balanced` | Nothing: every tier runs its route as configured. |
10
10
  | `quality` | One effort level more on the same model, else the route of the tier above. Haiku 5.5 automatically prefers High, except medium bounded ops may use Xhigh. Explicit higher efforts stay supported. |
11
11
 
package/lib/activity.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { PHASE_VALUES } from './classifier-contract.mjs';
5
5
  import { ACTIVITIES, EFFORTS, resolveRoute, routeSpec } from './config.mjs';
6
- import { routeEffort } from './cost.mjs';
6
+ import { cheaperPerTurn, routeEffort } from './cost.mjs';
7
7
  import { cashGate, sameTaskOf } from './policy.mjs';
8
8
 
9
9
  // The classifier's activity when it names one with at least `policy.activityMass`, else null: uncertain, a weak
@@ -104,15 +104,15 @@ export function chooseActivity(config, advice, incumbent, sentEffort, facts = {}
104
104
  // counts as up: it needs evidence, and the base route is always reachable. Labels alone never
105
105
  // switch, so one vote is enough. During an escalation hold only a stronger route may be taken. A cheaper route on the
106
106
  // same task (`sameTask`) waits for facts.downAllowed, as a tier downgrade does: a routing mode changes the route
107
- // without a new label, and a free switch must still wait out the dwell. A model with a lower input price also counts
108
- // as cheaper there, whatever its output price: that is the order the cost mode picks by. Returns
107
+ // without a new label, and a free switch must still wait out the dwell. A model cheaper per turn (cheaperPerTurn) also
108
+ // counts as cheaper there, whatever its output price: that is the order the cost mode picks by. Returns
109
109
  // { move, reason, estimate }.
110
110
  export function lateralMove({ config, from, to, mass, hold, sameTask = false, facts, now, costs }) {
111
111
  const order = compareRoutes(config, to, from, facts.effort);
112
112
  if (hold && !(order > 0)) return { move: false, reason: 'hold', estimate: null };
113
113
  const p = config.policy;
114
114
  let estimate;
115
- if (order !== -1 && sameTask && !facts.downAllowed && routeSpec(config, to).input < routeSpec(config, from).input)
115
+ if (order !== -1 && sameTask && !facts.downAllowed && cheaperPerTurn(routeSpec(config, to), routeSpec(config, from)))
116
116
  return { move: false, reason: 'downgrade-held', estimate: null };
117
117
  if (order === -1) {
118
118
  estimate = { taxUsd: costs.downgradeTaxUsd(config, to, from, facts, now, p.downgradeHorizonTurns) };
package/lib/cost.mjs CHANGED
@@ -32,6 +32,13 @@ export function clampEffort(wanted, supported) {
32
32
  return supported[0];
33
33
  }
34
34
 
35
+ // Whether model `a` costs less per turn than model `b`. Almost every input token of a session is a cache read, so the
36
+ // cache-read price decides and the input price breaks a tie. Limit: list rates only; a long-context or off-peak
37
+ // multiplier can reverse the order at a given context size or hour. Price through ratesAt if a caller needs that.
38
+ export function cheaperPerTurn(a, b) {
39
+ return a.cacheRead !== b.cacheRead ? a.cacheRead < b.cacheRead : a.input < b.input;
40
+ }
41
+
35
42
  // The one place a model's list prices become rates: per million tokens for a request whose prompt (input, cache read
36
43
  // and cache write) is `promptTokens` at time `at`, with the model's long-context multiplier above its threshold and
37
44
  // its off-peak multiplier outside peak hours. Every estimate prices through here.
package/lib/modes.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // Routing modes (docs/plans/2026-10-21-routing-modes.md): one setting that trades cost against answer quality. The
2
2
  // classifier and the configured routes stay as they are; the mode moves each tier's route by one fixed step. Pure.
3
3
  import { ACTIVITIES, DEFAULTS, EFFORTS, ROUTING_MODES, rank, resolveRoute, sameRoute, TIERS } from './config.mjs';
4
- import { clampEffort } from './cost.mjs';
4
+ import { cheaperPerTurn, clampEffort } from './cost.mjs';
5
5
  import { canonicalModel } from './providers.mjs';
6
6
 
7
7
  // The route's effort one level up (`step` 1) or down (-1), on what the model lists; null when it cannot move that
@@ -16,9 +16,9 @@ function steppedEffort(config, route, step) {
16
16
  return choices.find((effort) => supported.includes(effort)) ?? null;
17
17
  }
18
18
 
19
- // The route `mode` runs for tier and activity, always from the configured routes. `cost` takes a model with a lower
20
- // input price where one is below: the tier below, or at `low` the tier's route without its activity override (never
21
- // `micro`); else one effort level less. `high` keeps its model, so a turn that clears the upgrade bar runs on the
19
+ // The route `mode` runs for tier and activity, always from the configured routes. `cost` takes a model that is cheaper
20
+ // per turn (cheaperPerTurn: cache-read price, then input price) where one is below: the tier below, or at `low` the
21
+ // tier's route without its activity override (never `micro`); else one effort level less. `high` keeps its model, so a turn that clears the upgrade bar runs on the
22
22
  // strongest one. `quality` one effort level more, else the tier above. One lever per decision; quality keeps the
23
23
  // model and its cache. `micro` and `balanced` keep the configured route.
24
24
  export function modeRoute(config, mode, tier, activity = null) {
@@ -27,7 +27,7 @@ export function modeRoute(config, mode, tier, activity = null) {
27
27
  if (mode === 'balanced' || tier === 'micro') return route;
28
28
  if (mode === 'cost') {
29
29
  const below = tier === 'low' ? resolveRoute(config, 'low') : routeAt(TIERS[rank(tier) - 1]);
30
- const cheaper = config.models[below.model].input < config.models[route.model].input;
30
+ const cheaper = cheaperPerTurn(config.models[below.model], config.models[route.model]);
31
31
  if (tier !== 'high' && below.model !== route.model && cheaper) return below;
32
32
  const effort = steppedEffort(config, route, -1);
33
33
  return effort ? { model: route.model, effort } : route;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexeiled/claude-router",
3
- "version": "1.23.0",
3
+ "version": "1.23.1",
4
4
  "description": "Native Claude Code model and effort routing with Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, and classifier advice.",
5
5
  "license": "MIT",
6
6
  "author": "Alexei Ledenev",