npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-codex-router

v0.1.4

Published

Deterministic Codex model and thinking-level router for Pi

Readme

pi-codex-router

Deterministic Codex model and thinking-level routing for Pi.

npm version license

pi-codex-router automatically selects configurable Luna, Terra, or Sol models and their thinking level for coding tasks. It uses local prompt and repository signals—not another model—to keep routine work inexpensive and escalate complex work before each Pi agent turn.

Status: pi-codex-router is published on npm.

Installation

Install globally:

pi install npm:pi-codex-router

Or install for the current project:

pi install -l npm:pi-codex-router

Try a package for one Pi run without persisting it:

pi -e npm:pi-codex-router

Pin a version when needed:

pi install npm:pi-codex-router@<version>

Pi packages execute with your user permissions. Review package source before installing it.

Usage

Routing is automatic. Restart Pi or run /reload after installation, then send a normal prompt.

Use the /codex-router command to inspect or control the current session:

/codex-router status
/codex-router enable
/codex-router disable
/codex-router override balanced high
/codex-router override provider/model-id medium
/codex-router clear

status reports the selected profile, resolved model ID, and Pi's effective thinking level. Choosing a model or thinking level manually in Pi takes precedence over the router for that session.

Typical Routes

| Request | Profile | Thinking | | --- | --- | --- | | Rename a symbol, fix a typo, format code | fast | low | | Explain a line of code | fast | low | | Explain a security/authentication issue | balanced | medium | | Plan a database migration | advanced | high | | Fix a small regression | balanced | lowmedium | | Implement a normal feature | balanced | medium | | Refactor a module | balanced | high | | Debug a race condition | advanced | high | | Redesign an architecture | advanced | high |

The default profile mappings are:

| Profile | Default model | Intended work | | --- | --- | --- | | fast | openai-codex/gpt-5.6-luna | Small, low-risk tasks | | balanced | openai-codex/gpt-5.6-terra | Everyday development | | advanced | openai-codex/gpt-5.6-sol | Complex debugging and architecture |

These are configurable model IDs, not assumptions about every Pi installation.

How It Works

The router combines deterministic prompt classification with bounded local repository signals. Model selection and thinking selection are independent: Terra can use high thinking for a difficult refactor, for example.

It considers:

  • task and risk language;
  • prompt-mentioned file count;
  • approximate repository file count and language mix;
  • unstaged Git diff size; and
  • the prior route only to avoid switching between closely scored tasks.

Repository inspection skips .git, .pi, and node_modules, uses a short cache, and falls back to neutral signals if inspection fails. Repository signals are modifiers, not decisions by themselves.

Before every routed prompt, the router announces the applied profile, resolved model ID, and Pi's effective thinking level. Each new prompt is treated as a task boundary, allowing the router to downgrade after an unrelated expensive task; hysteresis still avoids switches for genuinely similar work. Pi must accept a route change before the router records it, and status reports Pi's effective thinking level if Pi clamps the requested level. A configured model that Pi cannot resolve falls back to the balanced profile when possible, then Pi's current model. An unavailable model must not prevent Pi from starting.

Configuration

Configuration uses JSON at these locations:

  1. ~/.pi/agent/codex-router.json for global defaults.
  2. .pi/codex-router.json for project overrides.

Project values override global values. Reload Pi after changing either file.

{
  "enabled": true,
  "models": {
    "fast": "openai-codex/gpt-5.6-luna",
    "balanced": "openai-codex/gpt-5.6-terra",
    "advanced": "openai-codex/gpt-5.6-sol"
  },
  "defaultThinking": "medium",
  "advancedThreshold": 70,
  "hysteresis": 12,
  "switchPolicy": "stable",
  "debug": false
}

| Field | Default | Description | | --- | --- | --- | | enabled | true | Enables automatic routing. | | models.fast | Luna ID | Model ID or alias for small tasks. | | models.balanced | Terra ID | Model ID or alias for everyday work. | | models.advanced | Sol ID | Model ID or alias for complex work. | | defaultThinking | medium | Thinking level for ordinary feature work. | | advancedThreshold | 70 | Score for eligible advanced routing. | | hysteresis | 12 | Score band that retains a stable route. | | switchPolicy | stable | stable or always. | | debug | false | Adds a compact route reason to each per-prompt notification. |

Supported thinking levels are off, minimal, low, medium, high, xhigh, and max, subject to Pi and the selected model. Invalid configuration falls back safely to defaults and produces one compact warning after reload; an unavailable explicit model override is cleared with a warning.

Environment Overrides

export PI_CODEX_ROUTER_FAST_MODEL='provider/fast-model'
export PI_CODEX_ROUTER_BALANCED_MODEL='provider/everyday-model'
export PI_CODEX_ROUTER_ADVANCED_MODEL='provider/advanced-model'

Privacy and Limitations

The router runs locally. It does not send prompts, repository contents, diffs, credentials, or usage history to a routing service, and it does not call an LLM to classify work.

It is a heuristic, not a guarantee of the optimal route. Provider-qualified model IDs are more reliable than aliases. Budget awareness, failure-driven escalation, local history, and learned routing weights are intentionally not part of the first release.

Development

npm install
npm test
npm run check
npm pack --dry-run
npm publish --dry-run

To publish:

./publish-to-npm.sh

The prepublishOnly hook runs tests, type checking, and npm pack --dry-run before publishing.

See docs/routing.md for scoring, model resolution, and configuration details.

Contributing

Keep routing deterministic, explainable, and inexpensive by default. Improve the route matrix and tests before changing thresholds or adding features.

License

MIT