crabex
v1.0.0
Published
Route models and inspect context inside Codex
Readme
Crabex is a local proxy that sits between Codex
(CLI and Desktop) and its backend. Codex keeps working exactly as it does today:
your ChatGPT subscription login, the /model picker, native subagents, Apps,
WebSockets. Crabex lets you put other models inside that shell, and shows you
precisely what Codex sends to them.
Like a hermit crab, the model moves in; the shell stays the same.
Why
Most "use other models with Codex" setups replace Codex's provider with an API key and lose what makes the harness good. Crabex takes the opposite approach:
- No new login. It forwards your existing Codex OAuth session to
chatgpt.com. No API key, no CLIProxyAPI. Routed models use their own tokens. - Native, not bolted on. Routed models appear in Codex's own model picker, can be spawned as native subagents, and keep tool calls, compaction, and reasoning working across providers.
- Glass box. Every request chain is captured locally, so you can see which instructions, tools, and history consume your context, then trim them.
What it does
| | Capability | Details |
| --- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🔀 | Model routing | Map any Codex model slug to an OpenAI-compatible Responses gateway or a native Anthropic Messages API (including Bedrock Mantle). HTTP/SSE and WebSocket on both sides. Anthropic routes |
| 📋 | Model picker integration | Routed models are injected into Codex's /models catalog with display names, descriptions, ordering, and metadata copied from a template model. Catalog refresh |
| 🛟 | Failover and flex | Ordered fallback targets with retry, backoff, and circuit breakers. Advertise -flex slugs for half-price OpenAI flex processing that falls back to standard. Flex routes |
| 🧑🤝🧑 | Subagents across providers | Spawn routed models as Codex subagents, see which routes hold native spawn slots, and safely mix provider histories in forks and child agents. Tool compatibility |
| 🧰 | Tool compatibility | Per-route tool policy: pass, translate, broker, omit, or reject each tool type. Freeform apply_patch, tool_search, and web search keep working on models that don't support them natively. Tool compatibility |
| 🔍 | Context inspector | Captures every request chain and breaks it into context parts, sections, tools, and token estimates, per model, harness, and project. Captures · Design |
| ✂️ | Transformations | Rules that delete context parts, rewrite text, or disable tools before a request leaves your machine, with hit/miss telemetry and on-demand preview. Inspector |
| 🔌 | Apps relay | Keeps Slack, Drive, and other ChatGPT Apps working when Codex's ChatGPT base URL points at the proxy. Apps relay |
| ⚙️ | Config-bundle overrides | Answer Codex's remote config-bundle fetch with your own edited bundle, from the Advanced page. |
| 📈 | Live traffic and stats | Watch in-flight requests, routing attempts, fallbacks, cache use, and flex vs. standard serves. |
| 🍎 | macOS service | One command installs a LaunchAgent with its own runtime, local HTTPS with Keychain trust, safe restarts, and automatic rollback. macOS service |
Everything is configured from the web UI served on the proxy's own port, or
from plain JSON files under .crabex/.
How it works
Codex CLI / Desktop Crabex (127.0.0.1:8765) Upstreams
┌──────────────────┐ Responses API ┌───────────────────────────────┐ OAuth ┌──────────────────┐
│ /model picker │ ────────────────▶ │ capture ─▶ transform ─▶ route │ ────────▶ │ chatgpt.com │
│ subagents, tools │ HTTP / WS │ │ ────────▶ │ Responses gateway│
│ Apps (MCP) │ ◀──────────────── │ UI + local API on same port │ ────────▶ │ Anthropic API │
└──────────────────┘ └───────────────────────────────┘ └──────────────────┘Unrouted models go to chatgpt.com with your login, unchanged except for any
transformations you enable. Routed models are translated to the target API and
back, so Codex never knows the difference.
Quick start
With Bun and a working Codex login:
bunx crabex@latest proxyOr install with Homebrew (includes Bun):
brew install niieani/tap/crabex
crabex proxyThe proxy runs anywhere Bun does; the background service is macOS-only.
To build from source, install Vite+ (vp, which provides
Bun), clone this repository, and run:
vp install
vp run build
./packages/proxy/dist/cli.mjs proxyOpen http://127.0.0.1:8765. On the Codex setup page, turn on both endpoint
toggles. Or add them to ~/.codex/config.toml yourself:
openai_base_url = "http://127.0.0.1:8765/backend-api/codex"
chatgpt_base_url = "http://127.0.0.1:8765/backend-api"Prefer to opt in for a single CLI session? Pass both settings on the command line:
codex \
-c 'openai_base_url="http://127.0.0.1:8765/backend-api/codex"' \
-c 'chatgpt_base_url="http://127.0.0.1:8765/backend-api"'For a reusable opt-in profile on current Codex versions, put those two TOML
settings in ~/.codex/crabex.config.toml and run codex --profile crabex.
See the Codex configuration guide
for configuration precedence and profile support.
Then run Codex as usual. Captures show up live in the UI. Add a route on the
Model routes page and the new model appears in Codex's /model picker.
To keep Crabex running across reboots (and use the ChatGPT desktop app, which requires HTTPS):
bunx crabex@latest service install --httpsWith Homebrew, use crabex service install --https. After updating the package,
refresh the service's independent copy using the service update instructions.
Configuration
All state lives in .crabex/ relative to where you start the proxy (the macOS
service keeps its own copy under ~/Library/Application Support/crabex/data).
Keep private route configuration there rather than in a repository.
| File | Purpose |
| -------------------------------------------- | ------------------------------------------------------------------------------------------- |
| model-routes.json | Routes, targets, tool policies, picker metadata |
| transformations.json | Context transformation rules |
| config.json | Proxy settings (Apps relay, routed agents, search broker) |
| config-bundle.json | Config-bundle override |
| captures/ | NDJSON request captures, kept for 7 days or 2 GiB (retention) |
| stats.json | Route counters and a daily per-model token ledger, kept indefinitely |
| upstream-cache.json, snapshot-cache.json | Caches |
Every path can be overridden with a flag; run crabex --help for the full list.
CLI
crabex proxy [--listen 127.0.0.1:8765] [--upstream https://chatgpt.com] [--project <key>] ...
crabex service install [--https] [--env NAME]... [-- proxy options]
crabex service uninstall|status|restart|logs
crabex service tls status|renew|removeDocumentation
- Anthropic Messages routes: Claude via Anthropic or Bedrock Mantle
- Flex routes: half-price flex processing with fallback
- Codex tool compatibility: tool policies, search, subagent handoff
- Captures and Probes: what is recorded and how to inspect it
- Context inspector design and domain language
- Apps authentication relay: keeping ChatGPT Apps working
- macOS service: LaunchAgent, HTTPS, updates
- Refreshing the model catalog
- Upgrading from agent-context-trimmer
Privacy and security
Crabex binds to loopback by default and is meant for a trusted, single-user machine. Captures stay on disk with owner-only permissions and never include headers. Your ChatGPT credentials are held in memory only; route tokens come from environment variables you name. See the Apps relay limitations before exposing the listener beyond localhost.
Development
vp run dev # build both packages and watch, single listener
vp check # format, lint, type check
vp run test # tests (Bun-native; not bare `vp test`)
vp run buildThe repository holds packages/proxy (Bun server and CLI) and packages/ui
(React and Tailwind UI). vp run dev:ui runs a standalone Vite server for
frontend-only work.
See CONTRIBUTING.md for contribution guidelines and SECURITY.md for private vulnerability reporting.
License
MIT © Bazyli Brzóska
