subagent-router
subagent-router is a project for a small, independent package that does explicit model routing for native subagents of Claude Code, OpenCode, and Codex.
Status: 0.1.0. The packaged serve command routes native Claude Code subagents to explicitly
chosen upstream models while the parent keeps its own model. An external gateway, e.g. 9router or
OmniRoute, handles the conversation with the provider, without a dependency on
@the-next-ai/ai-gateway. OpenCode and Codex adapters exist in the source tree but are not part of
what 0.1.0 claims.
Quickstart from a clean checkout
bun install --frozen-lockfile
bun run build
export ROUTER_GATEWAY_URL="https://YOUR-GATEWAY/v1"
export ROUTER_MODELS_AUTH="<model-discovery-token>"
export ROUTER_GATEWAY_HEADERS='{"Authorization":"Bearer <gateway-token>"}'
bun dist/cli.js web
Open http://127.0.0.1:8788 and work down the left side: Setup detects your installed clients
and writes the first config, Gateway names the environment variables the credentials come from,
Models runs the catalog sync, Routing picks the child models, Install generates the
Claude Code bundle and starts the router. Status and Logs show what the router is doing.
Export the gateway variables in the shell that starts the console. The config holds variable NAMES;
the values stay in the process environment and never enter a config file, a bundle or an API
response. The console tells you which named variable is still missing.
Full description of the console.
The same thing from the CLI
cp examples/minimal-router/subagent-router.json ./subagent-router.json
bun dist/cli.js models sync --config ./subagent-router.json
bun dist/cli.js config check --config ./subagent-router.json
bun dist/cli.js serve --config ./subagent-router.json --claude-version "$(claude --version)" --host 127.0.0.1 --port 8787
models sync is required before serve. The snapshot shipped in the example is a placeholder and
config check reports snapshot-source-mismatch until you replace it with your own gateway's
catalog. Pass the version number only to --claude-version, for example 2.1.270.
Connect your Claude Code
The console's Install view generates the integration files into a directory you name. So does
install on the command line. Neither edits your installed Claude Code configuration.
bun dist/cli.js install --output ./router-bundle --config ./subagent-router.json --claude-version 2.1.270
./router-bundle/claude-router
The launcher checks the router, then runs claude --settings ./router-bundle/settings.json and
passes your arguments through. The bundle also carries an optional plugin with a session-start
check and a /subagent-router:status command. Details and the measured results are in
docs/cli/INSTALL.md.
Without the bundle, one process at a time:
ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
Install from a marketplace
The repository is also a Claude Code plugin and its own marketplace. In Claude Code:
/plugin marketplace add kolezka/marketplace
/plugin install subagent-router@kolezka
kolezka/subagent-router works as a marketplace too, if you prefer the single-repository catalog.
The plugin adds a session-start check, /subagent-router:status, /subagent-router:setup, and the
router CLI on the Bash tool's PATH. It does not route by itself: a plugin cannot set
ANTHROPIC_BASE_URL for the session, so the connection still comes from the bundle above or from
the variable. Details in docs/plugin/README.md.
Select a child model with a marker on the first line of the Agent prompt:
<subagent-router v="1" model="terra"/>
Implement the requested change.
Full example with both aliases.
What 0.1.0 does not cover
- OpenCode and Codex clients. The adapters are present but unmeasured, so no support is claimed.
- Authentication on the web console. Keep it on loopback; off loopback it forces itself read-only.
- Survival of routing across client-side compaction. The decision fires on Claude Code 2.1.270 but
the client's reactive compactor bailed in every local run, so the phase is unproven here.
- Publishing to a registry. The package stays
private: true.
Running the PoC
bun install --frozen-lockfile
bun run poc:demo
PoC instructions and limitations. The demo uses a local test gateway and a synthetic client profile.
CLI (local)