@alexeiled/claude-router 1.8.1 → 1.10.0

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/lib/route.mjs CHANGED
@@ -317,7 +317,7 @@ export function continueRoute(config, loop, { nativeModel, contextTokens, contex
317
317
  return { ...loop, decision };
318
318
  }
319
319
 
320
- export function observeResponse(loop, { usage, requestedModel, effort, stopReason, now }) {
320
+ export function observeResponse(config, loop, { usage, requestedModel, effort, stopReason, now }) {
321
321
  let next = loop;
322
322
  if (stopReason === 'model_context_window_exceeded') {
323
323
  next = { ...next, ineligible: [...new Set([...next.ineligible, requestedModel])] };
@@ -337,7 +337,7 @@ export function observeResponse(loop, { usage, requestedModel, effort, stopReaso
337
337
  if (sameModel)
338
338
  models = {
339
339
  ...models,
340
- [costs.cacheKey(usage.model, effort)]: {
340
+ [costs.cacheKey(config, usage.model, effort)]: {
341
341
  lastAt: now,
342
342
  prefixTokens: usage.cache_read_input_tokens + usage.cache_creation_input_tokens,
343
343
  },
package/lib/savings.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  // the same tokens on the session's own model and effort ("your model"). Counts and dollars only, never text. Pure:
3
3
  // the hook feeds each reply and keeps the totals in the view and, per session, in $.store under SAVINGS_PREFIX.
4
4
 
5
- import { ratesAt } from './cost.mjs';
5
+ import { effortSharesCache, ratesAt } from './cost.mjs';
6
6
  import { HISTORY_SHRINK, isSameModel } from './route.mjs';
7
7
 
8
8
  // Each session keeps its own record under this prefix and its session id: $.store has no atomic update, and Claude
@@ -59,6 +59,12 @@ export function sessionCacheTtl({ force5m, envTtl, settingTtl, enable1h, subscri
59
59
  return '5m';
60
60
  }
61
61
 
62
+ // A subagent's prompt-cache lifetime, by Claude Code's rule for requests outside the main conversation: the same order
63
+ // with CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL and `subagentPromptCacheTtl`, and five minutes on a subscription too.
64
+ // Limit: an agent's `experimental.cacheTtl` frontmatter is not visible to a Mod.
65
+ export const subagentCacheTtl = ({ force5m, envTtl, settingTtl, enable1h }) =>
66
+ sessionCacheTtl({ force5m, envTtl, settingTtl, enable1h, subscriber: false });
67
+
62
68
  const isCount = (n) => Number.isFinite(n) && n >= 0;
63
69
 
64
70
  // One main reply. `state` is your model's simulated cache: `{ total, at, onYours, model, effort }` after a reply, or
@@ -87,11 +93,13 @@ export function compareReply(config, state, { usage, served, yours, ttl, now })
87
93
  const total = counts.input + counts.cacheRead + counts.cacheWrite;
88
94
  const [servedSpec, yoursSpec] = [modelSpec(config, served.model), modelSpec(config, yours.model)];
89
95
  const sameModel = servedSpec ? servedSpec === yoursSpec : served.model === yours.model;
90
- const onYours = sameModel && (served.effort ?? null) === (yours.effort ?? null);
91
96
  const identity = { model: yoursSpec?.id ?? yours.model, effort: yours.effort ?? null };
97
+ // On a model that keeps one cache across efforts (effortSharesCache), an effort-only difference is the same cache.
98
+ const sharedEffort = effortSharesCache(config, identity.model);
99
+ const onYours = sameModel && (sharedEffort || (served.effort ?? null) === identity.effort);
92
100
  const next = { total, at: now, onYours, ...identity };
93
101
  // A cache simulated for another model or effort of yours is none of this one's: the new one starts cold.
94
- const prior = state?.model === identity.model && state.effort === identity.effort ? state : null;
102
+ const prior = state?.model === identity.model && (sharedEffort || state.effort === identity.effort) ? state : null;
95
103
  const write = config.cache.writeMultiplier[ttl];
96
104
  if (
97
105
  !servedSpec ||
@@ -0,0 +1,280 @@
1
+ // Subagent routing: one model per subagent, chosen at agent.spawn before its cache exists, and the counts that show
2
+ // what that choice saves. Pure: the hook passes the spawn input, the classifier's advice and each reply's usage, and
3
+ // keeps the totals in the view and, per session, in $.store under SUBAGENT_PREFIX.
4
+
5
+ import { CLASSIFY } from './config.mjs';
6
+ import { clip } from './facts.mjs';
7
+ import { modelSpec, requestUsd } from './savings.mjs';
8
+
9
+ export const SUBAGENT_PREFIX = 'subagents:v1:';
10
+ // The longest a spawn waits for the classifier. The wait delays the subagent's start, and the client's deadline race
11
+ // sleeps on $.clock, which counts against the hook's 10 s budget (HookBudget in the build types).
12
+ export const SPAWN_DEADLINE_MS = 3000;
13
+ // A spawn of a type its parent loop finished one of this recently counts as a respawn: a proxy for a retry.
14
+ export const RESPAWN_WINDOW_MS = 600_000;
15
+ // Why a spawn passes through unchanged, in the order they are checked.
16
+ // `unlisted`: a built-in router.json does not list, or a type it lists as null. `pinned`: the agent's definition names a
17
+ // model and does not set `modelRouting: auto`. `unknown`: its definition could not be found or read.
18
+ export const PASS_REASONS = ['fork', 'workflow', 'explicit', 'teammate', 'unlisted', 'pinned', 'unknown'];
19
+ // Built-ins that ignore CLAUDE_CODE_SUBAGENT_MODEL unless CLAUDE_CODE_SUBAGENT_MODEL_FORCE is set.
20
+ const OWN_MODEL_BUILTINS = ['Explore', 'Plan'];
21
+
22
+ // The agent definition frontmatter the router reads: `name`, `model` and `modelRouting`, from a YAML block or the
23
+ // one-line JSON object some plugin builds write. Null when the text has no frontmatter. Only top-level scalars are read.
24
+ export function agentFrontmatter(text) {
25
+ const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(typeof text === 'string' ? text : '');
26
+ if (!match) return null;
27
+ const block = match[1].trim();
28
+ const fields = {};
29
+ if (block.startsWith('{')) {
30
+ try {
31
+ Object.assign(fields, JSON.parse(block));
32
+ } catch {
33
+ return null;
34
+ }
35
+ } else
36
+ for (const line of block.split(/\r?\n/)) {
37
+ const pair = /^([A-Za-z][\w-]*):\s*(.*?)\s*$/.exec(line);
38
+ if (pair) fields[pair[1]] = pair[2].replace(/\s+#.*$/, '').replace(/^(['"])(.*)\1$/, '$2');
39
+ }
40
+ const text_ = (value) => (typeof value === 'string' && value ? value : null);
41
+ return { name: text_(fields.name), model: text_(fields.model), modelRouting: text_(fields.modelRouting) };
42
+ }
43
+
44
+ // Whether a definition lets the router choose its model: no model, `inherit` (the main conversation's model, which
45
+ // the router routes too), or `modelRouting: auto`, where `model` is only what runs without the router.
46
+ export const routableDefinition = (definition) =>
47
+ !definition.model || definition.model === 'inherit' || definition.modelRouting === 'auto';
48
+
49
+ const pluginOf = (spawn) => {
50
+ const provider = spawn.provider?.plugin;
51
+ return typeof provider === 'string' ? provider.split('@')[0] : null;
52
+ };
53
+
54
+ // What router.json lists for this spawn's type: a models key, CLASSIFY or null, or undefined when it does not list
55
+ // it. A key without a colon names a built-in, so it matches only the engine's own agent; a `plugin:name` key matches
56
+ // only that plugin's agent (provider `plugin@marketplace`).
57
+ function listedRoute(config, spawn) {
58
+ const { types } = config.subagents;
59
+ const type = spawn.subagentType;
60
+ if (typeof type !== 'string' || !Object.hasOwn(types, type)) return undefined;
61
+ const owner = type.includes(':') ? type.slice(0, type.indexOf(':')) : 'engine';
62
+ return pluginOf(spawn) === owner ? types[type] : undefined;
63
+ }
64
+
65
+ // How the router may route this spawn's type: `{ route }`, a models key or CLASSIFY, or `{ pass }`, a PASS_REASONS
66
+ // entry. router.json's `types` decide first, a null there excluding the type. An unlisted built-in passes, since its
67
+ // definition is not readable. Any other agent is classified when its `definition` (agentFrontmatter of its file) is
68
+ // routable, and passes when it pins a model or could not be read.
69
+ export function typeRoute(config, spawn, definition = null) {
70
+ const listed = listedRoute(config, spawn);
71
+ if (listed !== undefined) return listed === null ? { pass: 'unlisted' } : { route: listed };
72
+ if (pluginOf(spawn) === 'engine') return { pass: 'unlisted' };
73
+ if (!definition) return { pass: 'unknown' };
74
+ return routableDefinition(definition) ? { route: CLASSIFY } : { pass: 'pinned' };
75
+ }
76
+
77
+ // The reason a spawn keeps the model core gives it, or null when the router may choose one. A fork reads the parent's
78
+ // cache on the parent's model; `model` is the Agent call's own choice; a teammate and a workflow agent are not
79
+ // rewritable (a workflow agent's model rewrite is ignored, experiments/mod-router/results/agent-spawn-probe.json).
80
+ export function passReason(config, spawn, definition = null) {
81
+ if (spawn.fork) return 'fork';
82
+ // Before `explicit`: a workflow agent({ model }) arrives with `model` set, and counts as a workflow agent.
83
+ if (spawn.workflow) return 'workflow';
84
+ if (spawn.model) return 'explicit';
85
+ if (spawn.isTeammate) return 'teammate';
86
+ return typeRoute(config, spawn, definition).pass ?? null;
87
+ }
88
+
89
+ // The task text the classifier sees: the description and the prompt the parent wrote, clipped like a main turn's
90
+ // prompt. Never tool results or history.
91
+ export const spawnPrompt = (config, spawn) =>
92
+ clip(`${spawn.description ?? ''}\n${spawn.prompt ?? ''}`.trim(), config.context.maxTextChars);
93
+
94
+ // The models key a `classify` type runs on from the classifier's advice, or null (no advice: core's model). `heavy`
95
+ // only for a clearly hard task, `light` for exploration or the smallest tier, `standard` for the rest.
96
+ export function classifiedAlias(config, advice) {
97
+ if (!advice) return null;
98
+ const { light, standard, heavy, heavyMass } = config.subagents;
99
+ if ((advice.probabilities?.high ?? 0) >= heavyMass) return heavy;
100
+ const activity = advice.activity;
101
+ const explores =
102
+ activity?.choice === 'explore' && (activity.probabilities?.explore ?? 0) >= config.policy.activityMass;
103
+ return explores || advice.choice === 'micro' ? light : standard;
104
+ }
105
+
106
+ // The model core runs an agent on when the router sets none: its definition's model unless that is `inherit`, else
107
+ // CLAUDE_CODE_SUBAGENT_MODEL, except for the
108
+ // built-ins that ignore it without CLAUDE_CODE_SUBAGENT_MODEL_FORCE, else the parent's model. An estimate: it does not
109
+ // apply the family-alias rule or the availableModels substitution.
110
+ export function coreModelOf(config, spawn, { envModel = null, force = false, definition = null } = {}) {
111
+ const idOf = (model) => (Object.hasOwn(config.models, model) ? config.models[model].id : model);
112
+ const pinned = definition?.model && definition.model !== 'inherit' ? definition.model : null;
113
+ if (pinned && !(force && envModel)) return idOf(pinned);
114
+ const usesEnv = envModel && envModel !== 'inherit' && (force || !OWN_MODEL_BUILTINS.includes(spawn.subagentType));
115
+ return usesEnv ? idOf(envModel) : spawn.parentModel;
116
+ }
117
+
118
+ // One spawn's record while its agent runs: what was decided and the priced replies since the last flush. `pass` is a
119
+ // PASS_REASONS entry or null. `choice` is the models key decided, or 'core' when the decision kept core's model.
120
+ // `actualUsd` prices each reply on the model it ran on; `otherUsd` the same tokens on the other side of the
121
+ // comparison: the decided model in shadow, core's estimated model in on. Null for a pass-through.
122
+ export function spawnRecord({ sessionId, mode, spawn, pass, choice, routedModel, coreModel, failed, respawn }) {
123
+ return {
124
+ sessionId,
125
+ mode,
126
+ type: spawn.subagentType,
127
+ pass,
128
+ choice,
129
+ routedModel,
130
+ coreModel,
131
+ failed: Boolean(failed),
132
+ respawn: Boolean(respawn),
133
+ counted: false,
134
+ requests: 0,
135
+ pricedRequests: 0,
136
+ actualUsd: 0,
137
+ otherUsd: 0,
138
+ };
139
+ }
140
+
141
+ const isCount = (n) => Number.isFinite(n) && n >= 0;
142
+
143
+ // The record with one reply added. A reply is priced only when both its model and the comparison's have a price.
144
+ export function addAgentReply(config, agent, usage, ttl) {
145
+ const counts = {
146
+ input: usage?.input_tokens,
147
+ cacheRead: usage?.cache_read_input_tokens,
148
+ cacheWrite: usage?.cache_creation_input_tokens,
149
+ output: usage?.output_tokens,
150
+ };
151
+ const next = { ...agent, requests: agent.requests + 1 };
152
+ const write = config.cache.writeMultiplier[ttl];
153
+ const actual = modelSpec(config, usage?.model);
154
+ const other = agent.pass ? null : modelSpec(config, agent.mode === 'shadow' ? agent.routedModel : agent.coreModel);
155
+ const priced = (spec) => spec && Number.isFinite(spec.output);
156
+ if (!Object.values(counts).every(isCount) || !Number.isFinite(write) || !priced(actual)) return next;
157
+ if (!agent.pass && !priced(other)) return next;
158
+ next.pricedRequests += 1;
159
+ next.actualUsd += requestUsd(actual, counts, write);
160
+ if (other) next.otherUsd += requestUsd(other, counts, write);
161
+ return next;
162
+ }
163
+
164
+ // A record kept across sessions, one session's or their sum, since `since` (ms), the first agent after a reset.
165
+ // `routed[mode][type]` counts the routed types; `passed[reason]` the pass-throughs, priced on the model they ran on.
166
+ export function emptySubagentStore() {
167
+ return { version: 1, since: null, routed: { shadow: {}, on: {} }, passed: {} };
168
+ }
169
+
170
+ const ROUTED_SUMS = ['agents', 'differs', 'requests', 'pricedRequests', 'coreUsd', 'routedUsd', 'respawns', 'failures'];
171
+ const PASSED_SUMS = ['agents', 'requests', 'pricedRequests', 'usd'];
172
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
173
+
174
+ const emptyRouted = () => ({ ...Object.fromEntries(ROUTED_SUMS.map((sum) => [sum, 0])), choices: {} });
175
+ const emptyPassed = () => Object.fromEntries(PASSED_SUMS.map((sum) => [sum, 0]));
176
+
177
+ // The finished turn's counts of one agent added to a store at `now`: the agent once, on its first flush, then its
178
+ // requests and prices since the last flush.
179
+ export function recordAgent(store, agent, now) {
180
+ if (!agent.requests && agent.counted) return store;
181
+ const first = agent.counted ? 0 : 1;
182
+ const next = { ...store, since: store.since ?? now, routed: { ...store.routed }, passed: { ...store.passed } };
183
+ if (agent.pass) {
184
+ const counts = { ...(next.passed[agent.pass] ?? emptyPassed()) };
185
+ counts.agents += first;
186
+ counts.requests += agent.requests;
187
+ counts.pricedRequests += agent.pricedRequests;
188
+ counts.usd += agent.actualUsd;
189
+ next.passed[agent.pass] = counts;
190
+ return next;
191
+ }
192
+ const byType = { ...next.routed[agent.mode] };
193
+ const counts = { ...(byType[agent.type] ?? emptyRouted()), choices: { ...byType[agent.type]?.choices } };
194
+ const shadow = agent.mode === 'shadow';
195
+ counts.agents += first;
196
+ counts.differs += first && agent.routedModel !== agent.coreModel ? 1 : 0;
197
+ counts.respawns += first && agent.respawn ? 1 : 0;
198
+ counts.failures += first && agent.failed ? 1 : 0;
199
+ if (first) counts.choices[agent.choice] = (counts.choices[agent.choice] ?? 0) + 1;
200
+ counts.requests += agent.requests;
201
+ counts.pricedRequests += agent.pricedRequests;
202
+ counts.coreUsd += shadow ? agent.actualUsd : agent.otherUsd;
203
+ counts.routedUsd += shadow ? agent.otherUsd : agent.actualUsd;
204
+ byType[agent.type] = counts;
205
+ next.routed[agent.mode] = byType;
206
+ return next;
207
+ }
208
+
209
+ // The record after a flush: counted once, nothing pending.
210
+ export const flushedAgent = (agent) => ({
211
+ ...agent,
212
+ counted: true,
213
+ requests: 0,
214
+ pricedRequests: 0,
215
+ actualUsd: 0,
216
+ otherUsd: 0,
217
+ });
218
+
219
+ function readCounts(value, sums, withChoices) {
220
+ if (!isRecord(value) || !sums.every((sum) => isCount(value[sum]))) return null;
221
+ const out = Object.fromEntries(sums.map((sum) => [sum, value[sum]]));
222
+ if (!withChoices) return out;
223
+ const choices = isRecord(value.choices) ? value.choices : {};
224
+ out.choices = Object.fromEntries(Object.entries(choices).filter(([, n]) => Number.isSafeInteger(n) && n >= 0));
225
+ return out;
226
+ }
227
+
228
+ function readMap(value, sums, withChoices) {
229
+ const out = {};
230
+ if (!isRecord(value)) return out;
231
+ for (const [key, counts] of Object.entries(value)) {
232
+ const read = readCounts(counts, sums, withChoices);
233
+ if (read) out[key] = read;
234
+ }
235
+ return out;
236
+ }
237
+
238
+ // The stored value with its well-formed entries, else an empty store: a missing, hand-edited or unknown value must not
239
+ // break a turn or the pane.
240
+ export function readSubagentStore(value) {
241
+ if (!isRecord(value) || value.version !== 1 || !(value.since === null || Number.isFinite(value.since)))
242
+ return emptySubagentStore();
243
+ return {
244
+ version: 1,
245
+ since: value.since,
246
+ routed: {
247
+ shadow: readMap(value.routed?.shadow, ROUTED_SUMS, true),
248
+ on: readMap(value.routed?.on, ROUTED_SUMS, true),
249
+ },
250
+ passed: readMap(value.passed, PASSED_SUMS, false),
251
+ };
252
+ }
253
+
254
+ // A record whose first agent came before the last reset at `resetAt` (ms) reads as empty.
255
+ export function subagentsAfterReset(record, resetAt) {
256
+ return Number.isFinite(resetAt) && record.since !== null && record.since < resetAt ? emptySubagentStore() : record;
257
+ }
258
+
259
+ function addInto(target, source, sums, withChoices) {
260
+ for (const [key, counts] of Object.entries(source)) {
261
+ const into = target[key] ?? (withChoices ? emptyRouted() : emptyPassed());
262
+ for (const sum of sums) into[sum] += counts[sum];
263
+ if (withChoices)
264
+ for (const [choice, n] of Object.entries(counts.choices)) into.choices[choice] = (into.choices[choice] ?? 0) + n;
265
+ target[key] = into;
266
+ }
267
+ }
268
+
269
+ // Every session's record since the last reset added up, since the earliest.
270
+ export function mergeSubagentStores(values, resetAt = null) {
271
+ const merged = emptySubagentStore();
272
+ for (const one of values.map((value) => subagentsAfterReset(readSubagentStore(value), resetAt))) {
273
+ const since = [merged.since, one.since].filter(Number.isFinite);
274
+ merged.since = since.length ? Math.min(...since) : null;
275
+ addInto(merged.routed.shadow, one.routed.shadow, ROUTED_SUMS, true);
276
+ addInto(merged.routed.on, one.routed.on, ROUTED_SUMS, true);
277
+ addInto(merged.passed, one.passed, PASSED_SUMS, false);
278
+ }
279
+ return merged;
280
+ }
package/lib/view.mjs CHANGED
@@ -54,6 +54,8 @@ export function initialView(model) {
54
54
  routeDraft: null,
55
55
  lastWrite: null,
56
56
  tab: 'now',
57
+ routeCell: null,
58
+ usageDetail: false,
57
59
  help: false,
58
60
  notice: null,
59
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexeiled/claude-router",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "description": "Native Claude Code Mod: model and effort routing for the main conversation, advised by Jev, Clef, Clef Flash, OpenAI or Ollama.",
5
5
  "license": "MIT",
6
6
  "author": "Alexei Ledenev",
package/types/index.d.ts CHANGED
@@ -140,6 +140,34 @@ declare module 'claude-code' {
140
140
  version: 1;
141
141
  since: number | null;
142
142
  }
143
+ // Subagent routing counts for one agent type in one mode (lib/subagents.mjs). `differs`: agents the decision moved off
144
+ // core's model; `choices`: agents by models key decided, or 'core'. USD over the priced requests.
145
+ interface RouterSubagentCounts {
146
+ agents: number;
147
+ differs: number;
148
+ requests: number;
149
+ pricedRequests: number;
150
+ coreUsd: number;
151
+ routedUsd: number;
152
+ respawns: number;
153
+ failures: number;
154
+ choices: Record<string, number>;
155
+ }
156
+ // Spawns that passed through for one reason, priced on the model they ran on.
157
+ interface RouterSubagentPassed {
158
+ agents: number;
159
+ requests: number;
160
+ pricedRequests: number;
161
+ usd: number;
162
+ }
163
+ // Kept across sessions, one per session under store key 'subagents:v1:<session id>' or their sum in the view, since
164
+ // the first agent after the last reset (ms).
165
+ interface RouterSubagentStore {
166
+ version: 1;
167
+ since: number | null;
168
+ routed: { shadow: Record<string, RouterSubagentCounts>; on: Record<string, RouterSubagentCounts> };
169
+ passed: Partial<Record<'fork' | 'explicit' | 'teammate' | 'workflow' | 'unlisted', RouterSubagentPassed>>;
170
+ }
143
171
  interface RouterView {
144
172
  phase: 'ready' | 'choosing' | 'routed' | 'manual' | 'unavailable';
145
173
  mode: 'auto' | 'manual';
@@ -185,13 +213,18 @@ declare module 'claude-code' {
185
213
  activityMetrics?: RouterActivityMetrics | null;
186
214
  savings?: RouterSavingsSession | null;
187
215
  savingsStore?: RouterSavingsStore | null;
216
+ subagentStore?: RouterSubagentStore | null;
188
217
  configPath?: string | null;
189
218
  tuning?: Partial<RouterTuning> | null;
190
219
  tuningBase?: RouterTuning | null;
191
220
  routeDraft?: (RouterRoutes & { base: RouterRoutes }) | null;
192
221
  // The last pane write to router.json: each leaf it changed with the value the file had before, none if absent.
193
222
  lastWrite?: { label: string; leaves: { path: string[]; value?: unknown }[] } | null;
194
- tab?: 'now' | 'routing' | 'classifier' | 'usage';
223
+ tab?: 'now' | 'routes' | 'policy' | 'classifier' | 'usage';
224
+ // The Routes grid cell whose editor is open: '<activity>.<tier>', or 'tier.<tier>' for a tier's own route.
225
+ routeCell?: string | null;
226
+ // Whether the Usage tab shows Claude's readings in detail, with the estimates.
227
+ usageDetail?: boolean;
195
228
  help?: boolean;
196
229
  bandDetail?: boolean;
197
230
  notice?: string | null;
@@ -1,151 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 828 1104" role="img" aria-labelledby="title desc">
2
- <title id="title">Router pane, Routing tab</title>
3
- <desc id="desc">Model and effort per tier with prices and windows, the baseline tier, how the policy prices each step up, the activity matrix and overrides, the policy controls, and the unsaved router.json changes with Save and Discard.</desc>
4
- <style>
5
- text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; font-size: 13px; }
6
- .cap { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 12px; fill: #9a988f; }
7
- </style>
8
- <rect width="828" height="1104" rx="8" fill="#1c1c1c"/>
9
- <rect x="10" y="10" width="808" height="1084" rx="6" fill="none" stroke="#3f5f8f"/>
10
- <text x="24.0" y="34" fill="#5fafd7" font-weight="700" xml:space="preserve">ROUTING</text>
11
- <rect x="94.2" y="20" width="62.4" height="18" rx="4" fill="#87afff"/>
12
- <text x="94.2" y="34" fill="#0d1016" font-weight="700" xml:space="preserve">[ ◉ on ]</text>
13
- <rect x="164.4" y="20" width="70.2" height="18" rx="4" fill="#2e3340"/>
14
- <text x="164.4" y="34" fill="#d0d0d0" xml:space="preserve">[ ○ off ]</text>
15
- <text x="234.6" y="34" fill="#7c7c7c" xml:space="preserve"> off keeps the /model choice</text>
16
- <text x="24.0" y="53" fill="#87d787" xml:space="preserve">Jev ready · 347 ms</text>
17
- <rect x="24.0" y="58" width="54.6" height="18" rx="4" fill="#2e3340"/>
18
- <text x="24.0" y="72" fill="#d0d0d0" xml:space="preserve">[ Now ]</text>
19
- <rect x="86.4" y="58" width="101.4" height="18" rx="4" fill="#87afff"/>
20
- <text x="86.4" y="72" fill="#0d1016" font-weight="700" xml:space="preserve">[ Routing ● ]</text>
21
- <rect x="195.6" y="58" width="109.2" height="18" rx="4" fill="#2e3340"/>
22
- <text x="195.6" y="72" fill="#d0d0d0" xml:space="preserve">[ Classifier ]</text>
23
- <rect x="312.6" y="58" width="70.2" height="18" rx="4" fill="#2e3340"/>
24
- <text x="312.6" y="72" fill="#d0d0d0" xml:space="preserve">[ Usage ]</text>
25
- <rect x="390.6" y="58" width="39.0" height="18" rx="4" fill="#2e3340"/>
26
- <text x="390.6" y="72" fill="#d0d0d0" xml:space="preserve">[ ? ]</text>
27
- <text x="24.0" y="110" fill="#5fafd7" font-weight="700" xml:space="preserve">ROUTES</text>
28
- <text x="70.8" y="110" fill="#7c7c7c" xml:space="preserve"> · applies next turn · edit, then Save</text>
29
- <text x="24.0" y="129" fill="#7c7c7c" xml:space="preserve">tier model effort $/M in · out window</text>
30
- <text x="24.0" y="148" fill="#e0708a" font-weight="700" xml:space="preserve">high</text>
31
- <text x="86.4" y="148" fill="#d0d0d0" xml:space="preserve">Opus 5.5 ▾</text>
32
- <text x="195.6" y="148" fill="#d0d0d0" xml:space="preserve">xhigh ▾</text>
33
- <text x="304.8" y="148" fill="#d0d0d0" xml:space="preserve">4 · 20</text>
34
- <text x="414.0" y="148" fill="#d0d0d0" xml:space="preserve">1M</text>
35
- <text x="24.0" y="167" fill="#d7af5f" font-weight="700" xml:space="preserve">medium</text>
36
- <text x="86.4" y="167" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
37
- <text x="195.6" y="167" fill="#d0d0d0" xml:space="preserve">xhigh ▾</text>
38
- <text x="289.2" y="167" fill="#d7af5f" xml:space="preserve">●</text>
39
- <text x="304.8" y="167" fill="#d0d0d0" xml:space="preserve">2 · 10</text>
40
- <text x="414.0" y="167" fill="#d0d0d0" xml:space="preserve">1M</text>
41
- <text x="24.0" y="186" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
42
- <text x="86.4" y="186" fill="#d0d0d0" xml:space="preserve">Haiku 5.5 ▾</text>
43
- <text x="195.6" y="186" fill="#d0d0d0" xml:space="preserve">high ▾</text>
44
- <text x="304.8" y="186" fill="#d0d0d0" xml:space="preserve">0.1 · 0.5</text>
45
- <text x="414.0" y="186" fill="#d0d0d0" xml:space="preserve">1M</text>
46
- <text x="24.0" y="205" fill="#5fd7af" font-weight="700" xml:space="preserve">micro</text>
47
- <text x="86.4" y="205" fill="#d0d0d0" xml:space="preserve">Haiku 5.5 ▾</text>
48
- <text x="195.6" y="205" fill="#d0d0d0" xml:space="preserve">medium ▾</text>
49
- <text x="304.8" y="205" fill="#d0d0d0" xml:space="preserve">0.1 · 0.5</text>
50
- <text x="414.0" y="205" fill="#d0d0d0" xml:space="preserve">1M</text>
51
- <text x="24.0" y="224" fill="#d0d0d0" xml:space="preserve">Baseline tier: low ▾</text>
52
- <text x="304.8" y="224" fill="#7c7c7c" xml:space="preserve">start here, fall back here</text>
53
- <text x="24.0" y="262" fill="#5fafd7" font-weight="700" xml:space="preserve">SWITCH COST · from these routes</text>
54
- <text x="24.0" y="281" fill="#7c7c7c" xml:space="preserve">· </text>
55
- <text x="39.6" y="281" fill="#d0d0d0" xml:space="preserve">medium → high </text>
56
- <text x="164.4" y="281" fill="#d0d0d0" xml:space="preserve">model change: priced as a cold cache write</text>
57
- <text x="24.0" y="300" fill="#7c7c7c" xml:space="preserve">· </text>
58
- <text x="39.6" y="300" fill="#d0d0d0" xml:space="preserve">low → medium </text>
59
- <text x="164.4" y="300" fill="#d0d0d0" xml:space="preserve">model change: priced as a cold cache write</text>
60
- <text x="24.0" y="319" fill="#7c7c7c" xml:space="preserve">· </text>
61
- <text x="39.6" y="319" fill="#d0d0d0" xml:space="preserve">micro → low </text>
62
- <text x="164.4" y="319" fill="#d0d0d0" xml:space="preserve">same model, new effort: priced as a new cache</text>
63
- <rect x="24.0" y="324" width="218.4" height="18" rx="4" fill="#2e3340"/>
64
- <text x="24.0" y="338" fill="#d0d0d0" xml:space="preserve">[ Reset routes to defaults ]</text>
65
- <text x="24.0" y="357" fill="#7c7c7c" xml:space="preserve">A new model ID needs router.json → models: price, window, efforts.</text>
66
- <text x="24.0" y="395" fill="#5fafd7" font-weight="700" xml:space="preserve">ACTIVITIES</text>
67
- <text x="102.0" y="395" fill="#7c7c7c" xml:space="preserve"> · applies next turn · edit, then Save</text>
68
- <text x="24.0" y="414" fill="#d0d0d0" xml:space="preserve">Activity routing: on ▾</text>
69
- <text x="242.4" y="414" fill="#7c7c7c" xml:space="preserve">an override runs when the activity has one</text>
70
- <text x="273.6" y="433" fill="#7c7c7c" xml:space="preserve">micro low medium high </text>
71
- <text x="24.0" y="452" fill="#d0d0d0" xml:space="preserve"> base H·med H·high S·xh O·xh </text>
72
- <text x="24.0" y="471" fill="#d0d0d0" xml:space="preserve"> code · S·high · O·max </text>
73
- <text x="24.0" y="490" fill="#d0d0d0" xml:space="preserve"> debug plan review · S·high · · </text>
74
- <text x="24.0" y="509" fill="#d0d0d0" xml:space="preserve"> explore docs · · · · </text>
75
- <text x="24.0" y="528" fill="#d0d0d0" xml:space="preserve"> ops · · H·high · </text>
76
- <text x="24.0" y="547" fill="#7c7c7c" xml:space="preserve"> 6 distinct routes = 6 caches</text>
77
- <text x="24.0" y="585" fill="#5fafd7" font-weight="700" xml:space="preserve">OVERRIDES</text>
78
- <text x="94.2" y="585" fill="#7c7c7c" xml:space="preserve"> · in use</text>
79
- <text x="24.0" y="604" fill="#d0d0d0" xml:space="preserve">code</text>
80
- <text x="102.0" y="604" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
81
- <text x="164.4" y="604" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
82
- <text x="273.6" y="604" fill="#d0d0d0" xml:space="preserve">high ▾</text>
83
- <rect x="382.8" y="590" width="78.0" height="18" rx="4" fill="#2e3340"/>
84
- <text x="382.8" y="604" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
85
- <text x="24.0" y="623" fill="#d0d0d0" xml:space="preserve">code</text>
86
- <text x="102.0" y="623" fill="#e0708a" font-weight="700" xml:space="preserve">high</text>
87
- <text x="164.4" y="623" fill="#d0d0d0" xml:space="preserve">Opus 5.5 ▾</text>
88
- <text x="273.6" y="623" fill="#d0d0d0" xml:space="preserve">max ▾</text>
89
- <text x="367.2" y="623" fill="#d7af5f" xml:space="preserve">●</text>
90
- <rect x="382.8" y="609" width="78.0" height="18" rx="4" fill="#2e3340"/>
91
- <text x="382.8" y="623" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
92
- <text x="460.8" y="623" fill="#d7af5f" xml:space="preserve"> new (model, effort) pair: one more cache</text>
93
- <text x="24.0" y="642" fill="#d0d0d0" xml:space="preserve">debug</text>
94
- <text x="102.0" y="642" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
95
- <text x="164.4" y="642" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
96
- <text x="273.6" y="642" fill="#d0d0d0" xml:space="preserve">high ▾</text>
97
- <rect x="382.8" y="628" width="78.0" height="18" rx="4" fill="#2e3340"/>
98
- <text x="382.8" y="642" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
99
- <text x="24.0" y="661" fill="#d0d0d0" xml:space="preserve">plan</text>
100
- <text x="102.0" y="661" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
101
- <text x="164.4" y="661" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
102
- <text x="273.6" y="661" fill="#d0d0d0" xml:space="preserve">high ▾</text>
103
- <rect x="382.8" y="647" width="78.0" height="18" rx="4" fill="#2e3340"/>
104
- <text x="382.8" y="661" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
105
- <text x="24.0" y="680" fill="#d0d0d0" xml:space="preserve">review</text>
106
- <text x="102.0" y="680" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
107
- <text x="164.4" y="680" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
108
- <text x="273.6" y="680" fill="#d0d0d0" xml:space="preserve">high ▾</text>
109
- <rect x="382.8" y="666" width="78.0" height="18" rx="4" fill="#2e3340"/>
110
- <text x="382.8" y="680" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
111
- <text x="24.0" y="699" fill="#d0d0d0" xml:space="preserve">ops</text>
112
- <text x="102.0" y="699" fill="#d7af5f" font-weight="700" xml:space="preserve">medium</text>
113
- <text x="164.4" y="699" fill="#d0d0d0" xml:space="preserve">Haiku 5.5 ▾</text>
114
- <text x="273.6" y="699" fill="#d0d0d0" xml:space="preserve">high ▾</text>
115
- <rect x="382.8" y="685" width="78.0" height="18" rx="4" fill="#2e3340"/>
116
- <text x="382.8" y="699" fill="#d0d0d0" xml:space="preserve">[ remove ]</text>
117
- <text x="24.0" y="718" fill="#d0d0d0" xml:space="preserve">add an override… ▾</text>
118
- <text x="24.0" y="756" fill="#5fafd7" font-weight="700" xml:space="preserve">POLICY</text>
119
- <text x="70.8" y="756" fill="#7c7c7c" xml:space="preserve"> · applies next turn · edit, then Save</text>
120
- <text x="24.0" y="775" fill="#d0d0d0" xml:space="preserve">Votes to go down</text>
121
- <text x="180.0" y="775" fill="#d0d0d0" xml:space="preserve">2 ▾</text>
122
- <text x="289.2" y="775" fill="#7c7c7c" xml:space="preserve">agreeing turns before cheaper</text>
123
- <text x="24.0" y="794" fill="#d0d0d0" xml:space="preserve">Payback horizon</text>
124
- <text x="180.0" y="794" fill="#d0d0d0" xml:space="preserve">5 turns ▾</text>
125
- <text x="289.2" y="794" fill="#7c7c7c" xml:space="preserve">a switch repays its cache</text>
126
- <text x="24.0" y="813" fill="#d0d0d0" xml:space="preserve">Credits cap</text>
127
- <text x="180.0" y="813" fill="#d0d0d0" xml:space="preserve">$2.00 ▾</text>
128
- <text x="289.2" y="813" fill="#7c7c7c" xml:space="preserve">max cold write on credits</text>
129
- <text x="24.0" y="832" fill="#d0d0d0" xml:space="preserve">Activity threshold</text>
130
- <text x="180.0" y="832" fill="#d0d0d0" xml:space="preserve">60% ▾</text>
131
- <text x="289.2" y="832" fill="#7c7c7c" xml:space="preserve">a weaker reading keeps the running activity or uses the base route</text>
132
- <rect x="24.0" y="837" width="218.4" height="18" rx="4" fill="#2e3340"/>
133
- <text x="24.0" y="851" fill="#d0d0d0" xml:space="preserve">[ Reset policy to defaults ]</text>
134
- <text x="24.0" y="889" fill="#5fafd7" font-weight="700" xml:space="preserve">CONFIG</text>
135
- <text x="24.0" y="908" fill="#d0d0d0" xml:space="preserve">File ~/.claude/router.json </text>
136
- <rect x="273.6" y="894" width="62.4" height="18" rx="4" fill="#2e3340"/>
137
- <text x="273.6" y="908" fill="#d0d0d0" xml:space="preserve">[ copy ]</text>
138
- <text x="24.0" y="927" fill="#7c7c7c" xml:space="preserve">Main conversation only. Subagents keep their own model.</text>
139
- <text x="24.0" y="965" fill="#7c7c7c" xml:space="preserve">router.json changes:</text>
140
- <text x="24.0" y="984" fill="#e06c6c" xml:space="preserve">- routes.medium Opus 5.5 · medium</text>
141
- <text x="24.0" y="1003" fill="#87d787" xml:space="preserve">+ routes.medium Sonnet 5.5 · xhigh</text>
142
- <text x="24.0" y="1022" fill="#e06c6c" xml:space="preserve">- activities.code.high no override</text>
143
- <text x="24.0" y="1041" fill="#87d787" xml:space="preserve">+ activities.code.high Opus 5.5 · max</text>
144
- <text x="24.0" y="1060" fill="#d7af5f" xml:space="preserve">● 2 unsaved routing changes </text>
145
- <rect x="250.2" y="1046" width="62.4" height="18" rx="4" fill="#87afff"/>
146
- <text x="250.2" y="1060" fill="#0d1016" font-weight="700" xml:space="preserve">[ Save ]</text>
147
- <rect x="320.4" y="1046" width="85.8" height="18" rx="4" fill="#2e3340"/>
148
- <text x="320.4" y="1060" fill="#d0d0d0" xml:space="preserve">[ Discard ]</text>
149
- <rect x="24.0" y="1065" width="70.2" height="18" rx="4" fill="#2e3340"/>
150
- <text x="24.0" y="1079" fill="#d0d0d0" xml:space="preserve">[ Close ]</text>
151
- </svg>