router
Model and effort routing for the main conversation, advised by a prompt classifier (Jev, Clef or Clef Flash). Preserves subagent model choices.
What it does
- Draws a band above the prompt
- Adds /model, /router
- Hooks config.set, session.compact, session.end, session.start and 3 more
- Keeps its own state between turns
- Calls the network
Good points
- Starts no processes
- Handles errors
Code to start from
Two kinds: a starter modscode writes from the design above, and the lines of the mod's own code that draw it.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like router by Alexei Ledenev (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/alexei-led-router/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
// the band above the prompt; what else goes there is drawn under it
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const { Box, Text, Button } = $.ui.resolve(e)
const tier = '…'
return (
<Box flexDirection="column">
<Box flexDirection="column">
<Box />
<Box />
<Box display="none">
<Text dimColor>
{"pin next turn "}
</Text>
<Button label={`${tier}`} />
<Text>
{" "}
</Text>
<Button label={`${tier}`} />
<Text>
{" "}
</Text>
<Button label={`${tier}`} />
<Text>
{" "}
</Text>
<Text>
{" "}
</Text>
<Button label="Manual" />
<Text>
{" "}
</Text>
<Button label="1 row" />
</Box>
</Box>
{await next(e)}
</Box>
)
})
}
The mod's own code
Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.
hooks/native-router.mjs lines 701–860 · Band
on('ui.render', { component: ['AbovePrompt', 'Pane'] }, async ($, e, next) => {
if (e.component === 'Pane' && e.requestId !== PANE) return next(e);
const storedView = await readView($, runtime);
const view = { ...storedView, mode: await modeOf($, runtime, storedView.mode) };
const elements = $.ui.resolve(e);
const { Box } = elements;
const usage = await $.session.usage().catch(() => null);
if (e.component === 'AbovePrompt') {
if (e.props.hasSurvey) return next(e);
return Box({
flexDirection: 'column',
children: [
await next(e),
renderBand(
elements,
config,
view,
usage,
{ columns: e.props.bodyColumns, agentId: e.props.view?.agentId },
{
open: () => openPane($, runtime),
mode: (mode) => changeMode($, runtime, mode),
pin: async (tier) => $.ui.toast(await setPin($, runtime, tier)),
unpin: () => updateView($, runtime, { pendingPin: null }),
key: () => openKeySettings($),
toggleDetail: async () => {
const bandDetail = !view.bandDetail;
await $.store.set(BAND_DETAIL, bandDetail).catch(() => {});
await updateView($, runtime, { bandDetail });
},
},
),
],
});
}
const settings = await $.settings.read().catch(() => ({}));
const modelOptions = Object.keys(config.models).filter((alias) =>
isModelAllowed(config.models[alias].id, settings.availableModels, view.nativeModel),
);
const editRoute = (tier, change) => {
const draft = routeDraftOf(config, runtime.view ?? view);
const current = effectiveRoutes(draft, config).routes[tier];
return updateView($, runtime, {
routeDraft: { ...draft, routes: { ...draft.routes, [tier]: change(current) } },
notice: null,
});
};
// Every pane save adopts the file as written, which may name another classifier than before: a hand edit
// meanwhile, or a row press. Then the new classifier starts clean and the old one's readings leave the view;
// an unavailable reason stays.
const adopt = async (loaded) => {
const switched = loaded.classifier !== config.classifier;
config = loaded;
if (!switched) return {};
clientOf(config.classifier).restore(null);
const current = runtime.view ?? view;
return {
...CLEARED_READINGS,
error: current.phase === 'unavailable' ? current.error : null,
credentials: await credentialsOf($, options, config),
health: healthOf(clientOf(config.classifier), config.classifier),
};
};
// Pending drafts re-pointed at the config a write just adopted. An edit that still differs stays; everything else
// follows the file, and the file becomes what the draft compares against, so picking a value the write replaced
// counts as a change again.
const rebased = ({ routeDraft, tuning, tuningBase }) => {
const routes = routeDraft && effectiveRoutes(routeDraft, config);
const edited = Object.entries(tuning ?? {}).filter(([key, value]) => value !== tuningBase?.[key]);
return {
routeDraft: routes ? { ...routes, base: routeDraftOf(config, {}).base } : null,
tuning: edited.length ? Object.fromEntries(edited) : null,
tuningBase: edited.length ? tuningOf(config) : null,
};
};
const save = async (change, saved) => {
const result = await saveConfig($, config.nativePath, change);
if (result.error) return updateView($, runtime, { notice: result.error });
const drafts = runtime.view ?? view;
const reset = await adopt(result.config);
return updateView($, runtime, { ...reset, ...rebased(drafts), ...saved(config) });
};
// Defaults go into the routing draft like any edit; the notice says whether Save has anything of that section left
// to write.
const loadDefaults = (patch, what) => {
const changes = routingChanges(config, { ...(runtime.view ?? view), ...patch });
const pending = what === 'route' ? changes.tiers.length + Number(changes.baseline) : changes.policy.length;
return updateView($, runtime, {
...patch,
notice: pending
? `${what === 'route' ? 'Route' : 'Policy'} defaults loaded. Save removes your ${what} overrides from router.json.`
: `${what === 'route' ? 'Routes' : 'Policy'} already at defaults.`,
});
};
// A pane write keeps the leaves it changed as router.json had them, read from the file it rewrites rather than from
// the loaded config, so Undo restores them verbatim. A later write replaces them, and Undo clears them.
const write = (label, change, patch = {}) => {
let leaves = [];
return save(
(file) => {
const written = change(file);
leaves = changedLeaves(file, written);
return written;
},
() => ({ ...patch, lastWrite: { label, leaves }, notice: `Saved: ${label}. Applies from the next turn.` }),
);
};
return renderPanel(
elements,
config,
view,
usage,
{
mode: (mode) => changeMode($, runtime, mode),
tab: (tab) => updateView($, runtime, { tab, notice: null }),
help: () => updateView($, runtime, { help: !view.help }),
pin: async (tier) => {
await updateView($, runtime, { notice: await setPin($, runtime, tier) });
},
unpin: () => updateView($, runtime, { pendingPin: null, notice: null }),
key: async () => {
openKeySettings($);
await $.ui.close({ id: PANE });
},
copyPath: async (press) => {
await $.ui.copy({ text: config.nativePath, surface: press?.surface });
await updateView($, runtime, { notice: 'Path copied.' });
},
close: () => $.ui.close({ id: PANE }),
routeModel: (tier, alias) =>
editRoute(tier, (route) => ({
model: alias,
effort: config.models[alias]?.efforts.includes(route.effort) ? route.effort : null,
})),
routeEffort: (tier, effort) => editRoute(tier, (route) => ({ model: route.model, effort })),
baseline: async (tier) => {
const draft = routeDraftOf(config, runtime.view ?? view);
await updateView($, runtime, { routeDraft: { ...draft, baselineTier: tier }, notice: null });
},
saveRouting: async () => {
const current = runtime.view ?? view;
const routeDraft = current.routeDraft;
const saved = tuningOf(config);
const base = current.tuningBase ?? saved;
const edited = Object.keys(current.tuning ?? {}).filter((key) => current.tuning[key] !== base[key]);
const changes = routingChanges(config, current).count;
if (!changes) return updateView($, runtime, { notice: 'No routing changes to save.' });
const after = Object.fromEntries(edited.map((key) => [key, current.tuning[key]]));
return write(
`${changes} routing change${changes === 1 ? '' : 's'}`,
(file) => {
const routed = routeDraft ? withRoutes(file, routeDraft) : file;
return edited.length ? withTuning(routed, { ...base, ...after }, base) : routed;
},
{ routeDraft: null, tuning: null, tuningBase: null },
);
},
discardRouting: () =>
updateView($, runtime, { routeDraft: null, tuning: null, tuningBase: null, notice: null }),
resetRoutes: () =>lib/native-band.mjs lines 175–216 · Band
export function renderBand({ Box, Text, Button }, config, view, usage, { columns, agentId }, actions) {
const draw = (p) => (p.button ? Button(p.button) : Text({ ...p.style, children: p.text }));
const row = (parts) => Box({ children: parts.map(draw) });
if (agentId) return row([part('○ Router · subagents keep their own model', { dimColor: true })]);
const kept = fitSegments(bandSegments(config, view, usage, actions), Math.max(0, columns - ROUTER_BUTTON));
const line = kept.flatMap((s, i) => (i ? [part(SEPARATOR, { dimColor: true }), ...s.parts] : s.parts));
line.push(part(' '), button({ key: 'details', label: 'Router', plain: true, onPress: actions.open }));
const routing = view.mode === 'auto' && view.phase !== 'unavailable';
return Box({
key: 'router-band',
flexDirection: 'column',
children: [
row(line),
view.bandDetail && routing ? row(detailRow(config, view, usage)) : null,
// Revealed while the pointer is over the band; no digit hotkeys, since a bare digit in an
// empty prompt would press them.
Box({
display: 'none',
hover: { display: 'flex' },
children: [
Text({ dimColor: true, children: routing ? 'pin next turn ' : '' }),
...(routing
? TIERS.flatMap((tier) => [
Button({ key: `band-pin-${tier}`, label: tier, onPress: () => actions.pin(tier) }),
Text({ children: ' ' }),
])
: []),
Text({ children: routing ? ' ' : '' }),
routing
? Button({ key: 'band-manual', label: 'Manual', onPress: () => actions.mode('manual') })
: Button({ key: 'band-auto-row', label: 'Auto', onPress: () => actions.mode('auto') }),
Text({ children: ' ' }),
Button({
key: 'band-detail',
label: view.bandDetail ? '1 row' : '2 rows',
onPress: actions.toggleDetail,
}),
],
}),
],
});
}Licence text (MIT)
MIT License Copyright (c) 2026 Alexei Ledenev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
What its code calls
networkwrites filesenv varsremembers
The design, read from code
Drawn from the mod's source at the commit read, not from a run: a list is drawn three times, a condition takes its first branch that draws in the desktop app, and a value only the run time knows is shown as a made-up sample (dotted underline) or left out. Colours and type are this site's.
What its code shows
Read from the source at commit 7599fb515e29 on 2026-10-06. The first group decides whether a mod is listed; the rest is for you to weigh. A later commit is not read until the next crawl.
| Decides the listing: code you can check | |
|---|---|
| Entry read | Every module hooks/hooks.json names was read.hooks/native-router.mjs |
| Parses | Every file parses as TypeScript or JavaScript.11 files parsed |
| All its code is in the mod | Every import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod |
| Readable | No minified lines, no eval or new Function, no import of a computed path, no encoded blobs.no minified code, no eval, no encoded blobs |
| Calls in the open | Network and programs are reached as $.http.fetch and $.process.run in place, never passed around.every call outside goes through $ in the open |
| For you to weigh before installing | |
| Where it draws | The terminal, the desktop app, both, or nothing (hooks only: a guard or a prompt rewriter), as its code says. Shown, never a reason to leave a mod out.draws in the terminal and the desktop app, the same in both |
| Install line | Whether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.listed in its repository's .claude-plugin/marketplace.json: installs from there |
| Programs on Windows | Whether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks |
| Network | Whether every fetch names its https host in the code.hooks/native-router.mjs:524 fetch(url) |
| Programs | Whether every program it starts is named in the code and is not a shell, an interpreter or a network tool.starts no programs |
| Reads and sends | Whether it both reads files or environment variables and reaches the network.reads environment variables and files and reaches the network |
| Keys in the source | Whether the source holds what looks like an API key or a private key.no keys in the source |
| Licence | An open licence (MIT, Apache-2.0, BSD, ISC, Unlicense, 0BSD, CC0) with its text lets modscode show its code; otherwise the code is linked.MIT |
This is a reading of the code text, not a security review: it does not run the mod, and it cannot see what a program the mod starts does. The check before installing is yours. How mods are chosen
Install it
Check it yourself before you install it. Mods run unsandboxed, with your permissions, and modscode does not vouch for what this code does. Read the code below (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
Its repository is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:
/plugin marketplace add alexei-led/claude-router/plugin install router@alexei-led-claude-routerThis installs the marketplace's latest commit, which may not be the one read here (7599fb515e29). Compare them before you install.
Ask Claude about it
With the modscode connector added, Claude can read this design, what its code reaches and its code, and build on them. Ask it like this:
Read the modscode design "alexei-led-router" with its code and make me a pane like itSearch them from Claude: the MCP connector
Similar designs
-
Ask Claude…2h 10m · █████░░░✓ build ✓ build ✓ buildJavaKotlin3 Python■ ok 3 ■ ok 3 ■ ok 3 Razor proven 3 Razor proven 3 Razor proven 3Phases ──────── 3/3build Pythonbuild Pythonbuild Python… 3 more phasesLua ──────── 3/Kotlin■ the whole upgrade Ruby■ build build Ruby■ build build Ruby■ build build Ruby … 3 moreNext ──────── PythonRuby (by hand)Podsclick a button, or ctrl+x tab then Tab, EnterAttention ──────── 3! Scala ! Scala ! Scala … 3 moreSession ──────── okJava
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Ask Claude…
-
Ask Claude…TodayOct 63 left · Mar overdueRemCTL: Sep✓ All done for today.● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓Updated 14:32UndoRefresh
-
Ask Claude…TO graph› Fix login › Fix login › Fix loginScopeThis featureWhole projectHide done stepsReconnect
-
Ask Claude…Blast Radius⚠ Blast Radius · buildCommand npm testWould CancelProceed Proceed ProceedBash1 Proceed2 CancelClaude is waiting on your answer
-
Ask Claude…Agent Radar● Edit note · 2h 10m · 0 toolsnow: starting────────No messages yet.agent: (tool calls)agent: (tool calls)agent: (tool calls)Back bClose q