jev-router README

The project's README from github.com/gargpratyush/jev-router. As one markdown file: README.md.

jev-router

Automatic per-turn model routing for Claude Code and OpenAI Codex. Jev sends simple work to the fast tier and difficult work to the strong tier, while preserving each CLI's native interface, tools, sessions, permissions, and authentication.

Command Interface Authentication Routing decision
jev-claude Claude Code Existing claude login Status line
jev-codex OpenAI Codex Existing codex login Commentary line

Both commands launch the real upstream CLI. Jev only chooses the model for a fresh user turn.

Quick start

Requires Node.js 20.12+ and at least one supported CLI: Claude Code or OpenAI Codex.

1. npm package

npm install -g jev-router
echo "JEV_API_KEY=..." > ~/.jev-router.env

2. Local repository

git clone https://github.com/gargpratyush/jev-router.git
cd jev-router
npm install
npm link
echo "JEV_API_KEY=..." > ~/.jev-router.env

On Windows PowerShell:

Set-Content "$HOME\.jev-router.env" "JEV_API_KEY=..."

Get a key from TypeSafe. Then launch either interface from any repository:

jev-claude
jev-codex

No Anthropic or OpenAI API key is required when the corresponding CLI is already logged in with a subscription. Every CLI argument is forwarded:

jev-claude --resume
jev-claude -p "fix the failing test"
jev-codex resume --last
jev-codex exec "fix the failing test"

For a local checkout, npm link installs both commands. Without it, run node bin/jev-claude.mjs or node bin/jev-codex.mjs.

Claude Code interface

Jev Router in the Claude Code model picker

jev-claude launches Claude Code with Jev Router selected in /model. Selecting another model pauses routing; selecting Jev Router resumes it.

The injected status line shows the model used for the last turn:

⚡ haiku p=0.98 · my-project · 8% context
⏸ manual Opus 4.6 · my-project · 21% context

Claude Code otherwise remains unchanged, including its keybindings, tools, permission prompts, /compact, /resume, and session handling. An existing custom statusLine is preserved; set JEV_NO_STATUSLINE=1 to disable Jev's status line.

The explanation skill is bundled with the npm package and loaded automatically: run /jev-explain in jev-claude, or $jev-explain in jev-codex, to see the factors behind the last routing decision:

┌─────────────────────────────────┐
│ Jev Router                      │
│                                 │
│ Jev request                     │
│ Prompt: explain the router      │
│ Current tier: HAIKU             │
│ Context tokens: 6200            │
│                                 │
│ Jev response                    │
│ Task complexity     0.82        │
│ Reasoning required  0.91        │
│ Tool complexity     0.64        │
│ Context size        0.31        │
│                                 │
│ Recommended tier: SONNET        │
│ Selected model: SONNET          │
│                                 │
│ Confidence: 94%                 │
│ Decision: Jev recommendation    │
└─────────────────────────────────┘

The report is rendered locally from the exact prompt, System One request, and System One response saved when routing occurred. Recent decisions are retained per CLI session; invoking the explanation skill does not ask Jev to score the prompt again.

Explanation data location

Both jev-claude and jev-codex keep up to 20 recent routing exchanges in one JSON file per CLI session under Node.js's operating-system temporary directory:

Platform Default location
Windows %TEMP%\jev-claude\<session-id>.json
macOS $TMPDIR/jev-claude/<session-id>.json (normally under /var/folders/.../T)
Ubuntu/Linux ${TMPDIR:-/tmp}/jev-claude/<session-id>.json

Print the exact directory selected on the current machine with:

node -e "console.log(require('node:path').join(require('node:os').tmpdir(), 'jev-claude'))"

Claude filenames use Claude Code's session UUID. Codex filenames use codex-<jev-codex-process-id>.json. These temporary files contain prompt text and Jev's exact request and response, so they are readable only by you (the directory is created with mode 700 and each file with 600). Files not updated for 7 days are deleted automatically, and the operating system may also remove them during normal temporary-file cleanup.

Choosing a model with Enter can save it as Claude Code's default. jev-claude restores the previous default on exit so jev-router cannot break plain claude.

OpenAI Codex interface

Jev Router in the OpenAI Codex model picker

jev-codex launches Codex with a temporary Jev Router provider and selects jev-router. The native /model picker still contains the models available to the account. Selecting a concrete model pauses routing; selecting Jev Router resumes it.

Each fresh decision appears as Codex commentary:

[Jev] routed this turn to gpt-5.6-sol (jev, confidence 0.91).

jev-codex installs or refreshes the packaged $jev-explain skill when it starts, so it is available from any repository without separate setup.

Codex's footer shows jev-router because it displays the selected picker entry, not the model chosen behind that provider. If Jev is unavailable, the commentary names the fallback model and explains how to set JEV_API_KEY.

How it works

Each command starts a loopback proxy, launches the real CLI, and forwards the CLI's existing authorization headers without reading, storing, or modifying them.

you -> Claude Code -> jev-claude proxy -> Anthropic
                         |
                         +-> Jev: choose a tier

you -> OpenAI Codex -> jev-codex proxy -> OpenAI
                         |
                         +-> Jev: choose a tier

Claude Code uses ANTHROPIC_BASE_URL; Codex uses a temporary custom provider with requires_openai_auth=true. Claude and Codex both use jev-router as the routing sentinel. Any concrete model selected by the user passes through unchanged.

Routing policy

One Jev call per fresh user turn selects a shared abstract tier:

Tier Claude Code default Codex default
Fast Haiku gpt-5.6-luna
Balanced Sonnet gpt-5.6-terra
Strong Opus gpt-5.6-sol
Long Fable gpt-6-astra

src/policy.mjs then applies these rules:

Tool-loop continuations keep the tier chosen at the start of the turn. Main conversations and sub-agents are pinned separately. Routing is fail-open: Jev failure never blocks the CLI.

Configuration

Variable Interface Effect
JEV_API_KEY Both Enables routing. TYPESAFE_API_KEY also works.
JEV_ALLOW_FABLE Both Enables the opt-in long tier.
JEV_DEBUG Both Logs decisions and rewrites to ~/.jev-claude.log in interactive sessions.
JEV_DUMP Both Dumps request bodies for debugging wire-format changes.
JEV_NO_STATUSLINE Claude Disables the injected Claude status line.
JEV_CODEX_FAST_MODEL Codex Fast model; defaults to gpt-5.6-luna.
JEV_CODEX_BALANCED_MODEL Codex Balanced model; defaults to gpt-5.6-terra.
JEV_CODEX_STRONG_MODEL Codex Strong model; defaults to gpt-5.6-sol.
JEV_CODEX_LONG_MODEL Codex Long model; defaults to gpt-6-astra.

Existing environment variables have highest precedence, followed by .env in the launch directory, ~/.jev-router.env, and the legacy ~/.jev-claude.env.

Tier definitions, Jev's question, confidence thresholds, and timeouts live in src/config.mjs. Both launchers send Jev the exact models in the signed-in account's native catalog, so model versions such as claude-opus-4-8 and claude-opus-5 remain separate choices. Static model ids are used only until the CLI fetches its catalog.

Compatibility notes

Development

npm install
echo "JEV_API_KEY=..." > .env

npm test
node test/live-routing.mjs
node bin/jev-claude.mjs -p "what is 2+2?"
node bin/jev-codex.mjs exec "what is 2+2?"

The test suite covers shared policy, both request formats, model rewriting, capability handling, settings restoration, Codex authentication forwarding, native model-picker injection, and decision display.

Limitations

Contributing

Issues and pull requests are welcome. Use Issues to report bugs, request improvements, or ask questions. Include the relevant Claude Code or Codex version, reproduction steps, expected behavior, and useful logs with secrets removed.

For a pull request:

  1. Open an issue first - all PRs by contributors should be linked with an approved issue. Explain the problem and validation in the issue description.
  2. Fork the repository and create a focused branch from master.
  3. Make the smallest change that solves the problem.
  4. Run npm test and include tests for non-trivial behavior changes.
  5. Claude/Copilot/Codex shall not be the contributors.

Please do not commit API keys or other secrets. All contributions require review, and only the repository owner can merge pull requests.

License

MIT

jev-router (gargpratyush/jev-router)

Searching Database…

这是什么?jev-router 会在 Claude Code 或 OpenAI Codex 的每一轮对话中自动挑选能胜任任务的、最便宜的 AI 模型:简单请求交给快速/廉价档,困难请求交给更强的档,同时完全不动各 CLI 原生的界面、工具和认证。
它是 Claude Code 里的插件,还是一个独立的 CLI?它是一个包装用的 CLI:jev-claude 和 jev-codex 命令会启动一个本地回环代理,并通过它启动真正的上游 claude 或 codex CLI,只拦截模型选择这一步。
怎么开始使用?在 Node.js 20.12+ 上安装 npm 包(或用 npm link 链接本地代码),然后在任意仓库里用 jev-claude 或 jev-codex 代替平常的 claude/codex 命令;如果没有 npm link,也可以直接运行 node bin/jev-claude.mjs 或 node bin/jev-codex.mjs。
运行前需要准备什么?需要 Node.js 20.12+、一个已登录的 Claude Code 或 Codex 账号,以及一个 TypeSafe API key,设置为 JEV_API_KEY 即可启用路由(TYPESAFE_API_KEY 也可以)。
如果路由服务连不上会怎样?路由采用 fail-open 策略,Jev 失败、超时或返回无法识别的结果时,只会继续沿用当前模型,不会阻塞 CLI;另外该项目只在 Windows 上、针对特定版本的 Claude Code 和 Codex 开发和测试过。
它在 Windows、macOS 和 Linux 上表现一致吗?是的,它明确支持这三个平台,各自有独立的临时文件位置用来存放路由决策日志。
Jev 会向 TypeSafe 发送什么数据?只有当前这一轮的提示词文本会发送给 TypeSafe 用于做路由决策,不会传输其他数据。
/jev-explain 技能会显示什么?在 jev-claude 中运行 /jev-explain(或在 jev-codex 中运行 $jev-explain)会打印一份本地报告,说明上一轮为什么被路由到某个档位,内容根据保存的提示词、请求和响应渲染,不会重新给提示词打分。
我能强制指定某个模型,而不是让 Jev 来选吗?可以,明确指定模型(比如 use opus、use luna、use strong)会让该轮绕过路由器;在 /model 里选择具体模型会暂停路由,直到重新选回 Jev Router。
为什么它拒绝在对话中途降级?该策略从不在低置信度时降级,也会阻止大型对话中那些浪费的提示词缓存工作量超过节省量的降级,让路由兼顾成本又不破坏上下文。
TypeSafe 是什么?TypeSafe 是签发 JEV_API_KEY 并根据提交的提示词文本实际执行模型档位打分的外部服务。
Size
0.4 MB
Stars
608
Updated
CommitSep 19
Age
1mo
Commits · 90 Days