kodemux router ladder guardrails claude code GitHub ↗
repo-native middleware · for AI coding agents

Route each task to the cheapest model that can do it.

kodemux estimates how hard a prompt really is — from signals, not a keyword lookup — and decides the whole execution plan: which model on a Haiku → Sonnet → Opus → Fable ladder, at what effort, in what mode, and how many agents to run in parallel. It flags security & production risk, escalates when unsure instead of guessing, and wraps the change in git-level guardrails.

View on GitHub
01

Try the router

This runs the actual estimator + policy, ported line-for-line from the source. No server, no API calls.

files touched3
diff size (lines)40

In the CLI these numbers are read automatically from git diff, and the critical-path flag fires on the real changed files — here you drive them by hand. All signals are additive.

This page demonstrates the free, instant deterministic core only. The CLI also has an optional AI-assist step (--no-ai to disable) that consults a cheap Haiku judge — reusing your existing Anthropic credentials, no setup — whenever this confidence score drops low; a static page can't safely make that call, so it isn't shown here. See docs/INTERNALS.md §5.8.

New in v0.6.0: --max-tier / --max-effort let you cap the routed tier/effort for one prompt without touching config — the router still runs this full analysis, the cap just clamps the result downward. CLI-only (no UI here to keep this page a pure "what would it pick" demo). See docs/INTERNALS.md §5.7a.

New in v0.7.0: the target agent toggle above. The rungs, thresholds, floors and escalation are identical for both — only the models behind them and the directive syntax change, so the same decision maps onto claude-* or the GPT-5.6 family (kodemux route "…" --provider codex).

intent
confidence
why this route
    02

    The capability ladder

    Four rungs by cost & capability. The router picks the lowest rung that clears the complexity threshold — then floors upward for risk.

    TierModelReaches at complexityEffortBest for

    Floors: any security/production risk → complex (Opus) minimum · architecture intent → complex · features/fixes/refactors never route below standard (Sonnet). Haiku takes no /effort directive.

    03

    Guardrails, before and after

    Pre-hooks catch problems before the agent runs; post-hooks clean up after. Both are live below.

    kodemux scan pre-hook

    Scans changed files for secret-shaped strings and refuses to hand them to an agent. Findings are always masked.

    kodemux guard pre-hook

    Refuses direct edits on a protected branch, so an agent is forced onto a feature branch first.

    protected: main, master, production

    04

    Wire it into Claude Code & Codex

    One command per agent. In Claude Code it becomes native hooks — a routing recommendation appears before every prompt, risky commits are blocked outright. Codex has no prompt hook, so there it becomes an AGENTS.md block the agent reads at the start of every session.

    # in any repo, once
    kodemux hooks install            # -> ./.claude/settings.json (Claude Code)
    kodemux hooks install --global   # -> ~/.claude/settings.json, every project
    
    kodemux codex install            # -> ./AGENTS.md (Codex)
    kodemux codex install --global   # -> ~/.codex/AGENTS.md, every project

    The difference is enforcement, not advice: Claude Code hooks can block a git commit (exit 2), while the Codex block is an instruction the agent follows. Routing is advisory in both.

    UserPromptSubmit advisory

    Runs the deterministic router on your prompt and injects the recommendation as context. The agent count is always stated, even when it's 1 — never left to be inferred from an absent line. Never blocks — Claude can always override it.

    // "fix a typo in the README"
    tier simple · model claude-haiku-4-5 · mode single
    agents: 1 — do not parallelize; a single
    agent working sequentially is enough.
    
    // wide-scope, multi-step rewrite
    tier frontier · model claude-fable-5 · mode multi-agent
    agents: 4 — genuinely parallelizable;
    split it across 4 agents.

    PreToolUse Bash · enforced

    Intercepts git commit and runs guard + scan automatically — a hit exits 2 and blocks the tool call outright.

    // git commit on a protected branch
    {"decision":"block","reason":"kodemux guard:
    refusing direct edits on protected branch
    'main'. Create a feature branch first."}

    Additive & idempotent — merges into whatever hooks already exist, backs up the file first, safe to re-run. Prefer zero-install? pack/ is the same rubric as a copy-paste markdown skill, no Node CLI required.

    05

    Get started

    Node ≥ 20. Free and open source, MIT.

    STEP 1

    Install

    Clone & npm link — no build step, dist/ is committed.

    STEP 2

    Init

    kodemux init detects your stack and scaffolds .kodemux/.

    STEP 3

    Route, guard & hook

    Wire route/guard/scan/post into your agent, or run hooks install (Claude Code) / codex install (Codex).

    # clone & link — works everywhere, incl. Windows & the Claude Code terminal
    git clone https://github.com/vibhusharma101/kodemux.git
    cd kodemux && npm install && npm link
    
    # in any repo
    kodemux init
    kodemux route "design a distributed rate limiter"   # → opus-5 / xhigh / /plan
    kodemux route "fix a typo in the README"          # → haiku-4-5 / single
    kodemux route "fix a typo" --provider codex        # → gpt-5.6-luna / low
    kodemux guard         # refuse edits on main
    kodemux scan          # secrets check
    kodemux hooks install # native Claude Code UserPromptSubmit + PreToolUse hooks
    kodemux codex install # AGENTS.md block for the Codex CLI
    the one idea

    Model choice should track how hard the task actually is — estimated from many signals, floored for risk, and escalated when unsure. That's a decision you can read, test, and override — not a habit.