test-codex-locally
Skill5.6k starsChanged 2 months agoApache-2.0View on GitHub
Run the Weave router locally in docker compose and drive it with `codex exec` to reproduce and verify routing/translation/marker behavior for Codex's Responses API path. Use when verifying a router fix end-to-end for Codex, reproducing a prod Codex routing bug, confirming routing-marker / force-model / subscription-passthrough behavior, or testing a `/force-model` route — without touching the user's global Codex config.
- Reads credentials
- Deletes or force-pushes
Trending
Quiet since October.thin dataabout the whole repository
Who's talking about weave-os/router
- sudosubin/agents.nix“agent-skills.github.weave-os.router: 0.2.23 → 0.2.28”GitHub · Oct 4, 2026
- sudosubin/agents.nix“agent-skills.github.weave-os.router: init at 0.2.23”GitHub · Oct 3, 2026
- PyTorchKR/landscape“[Add] Weave Router (weave-os/router)”GitHub · Oct 3, 2026
- datarelay-labs/datarelay-atlas“[Roadmap] Adaptive Model Routing — Weave Router reference / cache-aware switching”GitHub · Oct 2, 2026
The biggest 4 of 4 mentions linking to the repository that our crawl found. Each line is their own headline.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- cmd/AGENTS.mdAGENTS.md
- db/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- cmd/CLAUDE.mdCLAUDE.md
- db/CLAUDE.mdCLAUDE.md
- debug-claude-sessionSkill
- debug-codex-sessionSkill
- pr-merge-readySkill
- test-claude-locallySkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
No credits / no key = no reproduction: If the real upstream returns an error (e.g.
- Very specific: line 88
Use a throwaway CODEX_HOME containing a copy of the real ~/.codex/auth.json, with requires_openai_auth = true and X-App = "codex".
- Very specific: line 114
Add this to the server service in docker-compose.override.yml:
- Very specific: line 148
Do not point this at ~/.codex.
- Very specific: line 175
Do not set X-Weave-Router-Strategy unless you are deliberately pinning a strategy — omitting it uses the local deployment default (same …
- Very specific: line 203
Do not use codex exec -c 'model_providers.weave-local.http_headers."x-weave-force-model"=…' as the pin.
- Distinctive: line 216
Confirm the model was actually served: before drawing conclusions:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing the router locally with Codex
For an automated pre-merge regression net (fixture-driven, asserts caching/streaming/decision-headers against real Anthropic), run
make smoke— see docs/SMOKE.md. This skill is the interactive counterpart for the Codex CLI (codex exec): stand the stack up by hand and drive it via a throwawayCODEX_HOMEso~/.codex/config.tomlis never edited.
Stand up the router in docker compose, point a one-off codex exec at it via CODEX_HOME, and read the local server logs to confirm behavior. Two upstream modes: the real provider API (needs a working key + credits, and for native GPT models a ChatGPT OAuth login) or a mock upstream that emits an exact SSE shape (deterministic, no credits).
The sibling skill test-claude-locally is the Claude Code (claude -p) counterpart. Stack bring-up and seeding are identical; only the client driver differs.
Critical gotchas (read first)
- Never edit
~/.codex/config.tomlor~/.codex/auth.json. Those are the user's live Codex install (prod Weave Router + ChatGPT OAuth). Redirect with a throwawayCODEX_HOMEdirectory that contains its ownconfig.toml(and a copy ofauth.jsonwhen ChatGPT OAuth is required).CODEX_HOMEis how Codex finds config; there is no--settingsflag equivalent to Claude Code. requires_openai_auth = trueis required. Codex 0.149 hangs or never issues a/v1/responsesrequest if the custom provider usesrequires_openai_auth = falseorenv_key. Copy~/.codex/auth.jsoninto the throwawayCODEX_HOMEso Codex can attach the ChatGPT JWT +ChatGPT-Account-ID. The mock-router experiment that dropped OAuth never even hit the mock.- Codex always sends a ChatGPT JWT +
ChatGPT-Account-ID. The local router will classify that as a Codex subscription (codexResponsesRequest→ native Responses passthrough for OpenAI decisions). That is the path this skill is usually exercising (routing markers on verbatim GPT frames). To force the prepaid/BYOK translation path instead, flipsubscription_routing_disabled=trueon the seeded installation (see step 3). codex execis one-shot. A standalone/force-modelcall does not persist to the nextcodex exec(new session id every time, unless youcodex exec resume). Put/force-model <model>as the first line of the SAME prompt. The leading space is load-bearing — Codex consumes unknown slash tokens as local commands; a leading space makes it a normal user message the router can parse.- Pin via
config.toml, notcodex -c. On Codex 0.149.1,-c 'model_providers.weave-local.http_headers."x-weave-force-model"="…"'did not merge into the outgoing request (nox-weave-force-model appliedin server logs; the scorer served something else). Put"x-weave-force-model" = "<id>"on the samehttp_headerstable in the throwawayconfig.toml(step 4). Confirm withdocker compose logs server | grep 'x-weave-force-model applied'before drawing conclusions. - The router ignores the request's
modelfield for routing (cluster scorer / pins win). Codex's-m gpt-5.5only changes what Codex requests;/force-modelorx-weave-force-modelis the only way to pin a specific routed model. Native GPT family (gpt-5.6-sol/terra/luna, plus whatever-mCodex defaulted to) still goes through the scorer unless forced. - No GNU
timeouton macOS. Drivecodex execdirectly. If a run hangs (Reading additional input from stdin...with no banner), Codex is waiting on a TTY/stdin — do not pipe into it, and make sure-s read-only(or--dangerously-bypass-approvals-and-sandbox) is set. - Docker may not be running.
docker composefails with aunix://…/.docker/run/docker.sockconnect error if Desktop is stopped.open -a Dockerand wait fordocker infobefore step 1. - Other agents in the same workspace can
docker compose downand delete/tmpscratch. If health suddenly 404s orCODEX_HOMEvanishes mid-run, re-up the stack and reseed — do not reuse a key you can no longer/validate. - Session key is
apiKeyID+ first user message. Reusing the same curl/prompt body on the same key reuses the pin slot.routingMarkerForthen returns empty whenPriorServedModel == ServedIdentity()(sticky same-model). For first-turn marker tests, seed a new key or change the first user text. Isolated/validatefirst:curl -sS -o /dev/null -w '%{http_code}\n' -H "X-Weave-Router-Key: $KEY" http://localhost:8080/validatemust be200. - Native GPT passthrough + tool-only emits a synthetic badge item.
SetPassthroughBadgerewrites existingresponse.output_text.*events and, when a ChatGPT-subscription turn has no assistant text, inserts a leading assistant message item before native tool/reasoning output. Verify the badge in the Responses SSE/JSON; the Codex TUI can bury the first-turn line under tool chatter. GET /v1/models501 from a mock is fine. Codex probes<base_url>/modelsfirst, logs an HTML 501, then continues toPOST /v1/responses. The real local router implementsGET /v1/modelsas Anthropic passthrough, so this only shows up against a Python mock.- Port 8085 conflict. The monorepo's pubsub emulator may already own host port 8085. Drop the router's host binding with a
docker-compose.override.yml(see workflow). The server still reaches the emulator over the compose network. - No credits / no key = no reproduction. If the real upstream returns an error (e.g. OpenRouter "Insufficient credits"), use the mock-upstream path instead.
Workflow
- [ ] 1. Bring up the stack (handle port 8085)
- [ ] 2. Seed an API key
- [ ] 3. Choose upstream + subscription vs prepaid path
- [ ] 4. Write a throwaway CODEX_HOME (copy auth.json)
- [ ] 5. Drive with `CODEX_HOME=... codex exec`, forcing the target model
- [ ] 6. Read local logs to verify behavior
- [ ] 7. Clean up1. Bring up the stack
cd <router-repo>
# Drop the pubsub host-port binding to avoid an 8085 conflict:
cat > docker-compose.override.yml <<'EOF'
services:
pubsub-emulator:
ports: !reset []
EOF
docker compose up -d --build server # --build picks up code changes
until curl -sf http://localhost:8080/health >/dev/null; do sleep 2; doneThe override file is gitignored-by-intent scaffolding — delete it in cleanup.
2. Seed an API key
docker compose run --rm seedCopy the rk_... key it prints — only the line under Weave Router key (shown once — store it now):. Seed stdout repeats the same token in curl examples and installer snippets; grep -oE 'rk_[A-Za-z0-9]+' can grab a stale key from an earlier seed in the same log. Always /validate before driving Codex:
curl -sS -o /dev/null -w '%{http_code}\n' \
-H "X-Weave-Router-Key: rk_REPLACE_ME" http://localhost:8080/validate
# expect 200A 401 mid-session usually means the stack was torn down and reseeded (new installation, old token dead).
3. Choose the upstream
Real provider — set the provider key in .env.local (e.g. OPENAI_API_KEY=..., FIREWORKS_API_KEY=...) and restart docker compose up -d server. Confirm the boot log shows <Provider> provider enabled with the real base_url. Use this to confirm a model genuinely produces the behavior.
For an actual Codex subscription response, do not set ROUTER_CODEX_BASE_URL
and do not run either mock. Remove that environment entry from
docker-compose.override.yml, then rebuild the server:
unset ROUTER_CODEX_BASE_URL # also remove it from docker-compose.override.yml
docker compose up -d --build serverUse a throwaway CODEX_HOME containing a copy of the real
~/.codex/auth.json, with requires_openai_auth = true and X-App = "codex".
The router detects the OAuth bearer plus ChatGPT-Account-ID and calls the
real https://chatgpt.com/backend-api/codex/responses endpoint. This consumes
the user's ChatGPT quota and requires a valid login; the mock is only for
repeatable tests when that endpoint is unavailable or too expensive.
Mock upstream — for a deterministic, credit-free repro of a precise SSE shape. Point the provider's base URL at a local mock and restart. Codex talks to the router (POST /v1/responses); the mock sits behind the router as the upstream the router dispatches to:
python3 .claude/skills/test-claude-locally/scripts/mock_openai_upstream.py >/tmp/mock.log 2>&1 & # serves :8099
# In docker-compose.override.yml under `server:`, add:
# environment:
# FIREWORKS_BASE_URL: http://host.docker.internal:8099/v1
# FIREWORKS_API_KEY: sk-mock
# extra_hosts: ["host.docker.internal:host-gateway"]
docker compose up -d serverTo exercise the production-equivalent native Codex subscription path, use a native Responses mock instead of the Chat Completions mock:
python3 .claude/skills/test-codex-locally/scripts/mock_codex_upstream.py >/tmp/mock-codex.log 2>&1 &Add this to the server service in docker-compose.override.yml:
environment:
ROUTER_CODEX_BASE_URL: http://host.docker.internal:8099/v1
extra_hosts: ["host.docker.internal:host-gateway"]This preserves real Codex subscription detection (OAuth bearer plus
ChatGPT-Account-ID) and native Responses passthrough, while replacing only
the outbound ChatGPT backend with a deterministic tool-only stream. The mock
emits a function call, so the expected result is a synthetic marker message at
output_index: 0, followed by the native tool at output_index: 1.
Edit the mock's emitted chunks to match the upstream shape you're reproducing. Provider→env-var names live in internal/providers/provider.go; base-URL overrides are read in cmd/router/main.go (<PROVIDER>_BASE_URL). For local testing, ROUTER_CODEX_BASE_URL overrides only the subscription backend; the default remains https://chatgpt.com/backend-api/codex.
Subscription vs prepaid (important for marker / passthrough tests):
Codex will attach a ChatGPT JWT. The local router then treats the turn as a Codex subscription:
- OpenAI-family decision → verbatim Responses passthrough (
SetPassthrough/SetPassthroughBadge) to the Codex backend (orROUTER_CODEX_BASE_URLin the native mock setup). This is the path the routing-marker-on-Codex work exercises. - Non-OpenAI decision → Chat Completions translation +
ResponsesWriter.SetBadgeText.
To force the prepaid/BYOK translation path (no ChatGPT backend, uses OPENAI_API_KEY / other provider keys):
docker compose exec postgres psql -U router -d router -c \
"SET search_path TO router; UPDATE model_router_installations SET subscription_routing_disabled=true WHERE external_id='__router_admin__';"Revert with subscription_routing_disabled=false when done.
4. Throwaway CODEX_HOME
Do not point this at ~/.codex. A unique temp dir keeps the user's prod Weave + ChatGPT login intact.
export CODEX_HOME=/tmp/weave-codex-local
rm -rf "$CODEX_HOME"
mkdir -p "$CODEX_HOME"
cp ~/.codex/auth.json "$CODEX_HOME/auth.json" # required; see gotchas
cat > "$CODEX_HOME/config.toml" <<EOF
model_provider = "weave-local"
[model_providers.weave-local]
name = "Weave Router (local)"
base_url = "http://localhost:8080/v1"
wire_api = "responses"
requires_openai_auth = true
http_headers = { "X-Weave-Router-Key" = "rk_REPLACE_ME", "X-App" = "codex" }
EOFOptional headers on the same http_headers table:
| Header | Purpose |
"X-Weave-User-Email" = "dev@localhost" | Attribution in local logs |
"x-weave-force-model" = "z-ai/glm-5.1" | Preferred pin. Put it here — do not rely on codex -c (see gotchas). |
"X-Weave-Routing-Marker" = "off" | Suppress the in-band routing marker |
Do not set X-Weave-Router-Strategy unless you are deliberately pinning a strategy — omitting it uses the local deployment default (same rationale as install/install.sh --codex --local).
5. Drive it
cd <scratch-dir-with-files-to-act-on>
CODEX_HOME=/tmp/weave-codex-local \
codex exec --skip-git-repo-check -s read-only -C "$(pwd)" \
' First send exactly: /force-model z-ai/glm-5.1
Then <task that requires tool use>, then stop.'Notes:
--skip-git-repo-checklets you run against/tmpor any non-git scratch dir.-s read-only(or--dangerously-bypass-approvals-and-sandboxin a throwaway dir) avoids the interactive approval TUI, whichcodex execotherwise cannot answer.- Leading space before
/force-modelis required (Codex otherwise treats it as an unknown local slash command and never sends it to the router). codex execprintsprovider: weave-localin its session banner when the throwaway config took; if it printsprovider: weaveit is still reading~/.codex—CODEX_HOMEwas not exported.- Confirm Codex actually reached the local router:
docker compose logs server --since=1mshould show aPOST /v1/responses(andProxyOpenAIChatCompletion start).
Headless pin, no slash command — bake the header into the throwaway config.toml (step 4), then:
CODEX_HOME=/tmp/weave-codex-local \
codex exec --skip-git-repo-check -s read-only -C "$(pwd)" \
"say hi and stop"Do not use codex exec -c 'model_providers.weave-local.http_headers."x-weave-force-model"=…' as the pin. On 0.149.1 that override is silently dropped. After the run, grep 'x-weave-force-model applied' in server logs must fire; if it doesn't, Codex never sent the header.
6. Verify via logs
Codex ingress is ProxyOpenAIResponses → ProxyOpenAIChatCompletion. The decision + completion log per action is ProxyOpenAIChatCompletion complete. Strip ANSI first:
docker compose logs server --since=3m 2>&1 | sed -E 's/\x1b\[[0-9;]*m//g' \
| grep 'ProxyOpenAIChatCompletion complete' | grep 'decision_model=z-ai/glm-5.1'Useful fields: decision_model, decision_provider, decision_reason, routing_marker, hard_pinned, cross_format, turn_type, proxy_err, upstream_status. Also grep for recovery nudge, tool-call loop, no-progress. SetBadgeText is not logged — look at the Codex transcript / codex output for the ✦ **Weave Router** → <model> (or **Weave Router** — <model> legacy) line.
Confirm the model was actually served before drawing conclusions:
docker compose logs server --since=3m 2>&1 | sed -E 's/\x1b\[[0-9;]*m//g' \
| grep 'ProxyOpenAIChatCompletion complete' | grep -oE 'decision_model=[^ ]+' | sort | uniq -cIf you only see other models, the pin didn't take. Recheck: (1) x-weave-force-model is in CODEX_HOME/config.toml (not only a -c flag), (2) server log has x-weave-force-model applied, (3) leading space on in-prompt /force-model if you used that path. Codex's session banner model: gpt-5.6-sol is what Codex requested, not what the router served.
Routing-marker specific checks (the usual reason to use this skill):
- Cross-format (non-OpenAI decision, or prepaid OpenAI): first assistant text is
✦ **Weave Router** → <model> · <reason>. Log fieldrouting_markeris non-empty. - Verbatim GPT passthrough (Codex subscription + OpenAI decision): same marker is injected into the first native assistant text, or as a synthetic assistant message item before tool/reasoning-only output (
SetPassthroughBadge). Log still hasrouting_marker. X-Weave-Routing-Marker: off(and not subscription-only warning): no badge. Subscription-only depleted-credits warning still wins over the opt-out.- Same model, second action (
prior_served_modelequalsdecision_model):routing_marker="". Expected. Seed a new key (or change the first user text) to re-see a first-turn badge. - Tool-call-only on the translated path: marker is a leading
output_item(output_index0) ahead of the function call — includingstream:falseJSON. Confirm in the SSE / JSON, not only incodex execstdout (the TUI can bury the first-turn line under tool chatter). - Tool-call-only on verbatim GPT passthrough: a leading synthetic message item carries the badge, followed by the native tool call. Sequence/output indices are shifted to remain valid.
- Non-Codex client (
X-Appunset) on a translated decision still gets the✦ **Weave Router** → …text badge today; native OpenAI passthrough withoutX-App: codexstays byte-identical (SetPassthroughwith no badge rewrite). - For curl-level checks (no Codex CLI),
POST /v1/responseswithX-Weave-Router-Key+X-App: codexis enough. Isolate first-turn cases with a freshly seeded key.
7. Clean up
pkill -f mock_openai_upstream.py 2>/dev/null
pkill -f mock_codex_upstream.py 2>/dev/null
rm -rf /tmp/weave-codex-local
rm -f docker-compose.override.yml
# `docker compose down` if you want to stop the stack
# do NOT touch ~/.codexNotes
- Local cluster version comes from
ROUTER_CLUSTER_VERSIONin.env.local; it may differ from prod, which is why/force-model(not the scorer) is the reliable way to hit one model. - Native Codex models
gpt-5.6-sol,gpt-5.6-terra, andgpt-5.6-lunause the caller's ChatGPT OAuth plan when subscription routing is on. Other OpenAI / Anthropic / Gemini / OpenAI-compatible models use WorkWeave deployment or BYOK credentials, same as Claude Code. - To confirm a deploy contains a given router commit: the prod Cloud Run revision name maps to a monorepo commit;
git ls-tree <monorepo-commit> router-internal/routershows the pinned router submodule SHA. codex exec --ignore-user-configis not a substitute forCODEX_HOME: it skips$CODEX_HOME/config.tomlentirely (so you'd have no weave-local provider) while auth still usesCODEX_HOME. Always write a full throwaway config.- Codex rollout transcripts live under
$CODEX_HOME/sessions/<yyyy>/<mm>/<dd>/rollout-*.jsonl. Grep those forWeave Routerwhencodex execstdout is noisy. docker-compose.override.ymlis gitignored. If you add a mock*_BASE_URLthere, remember to rewrite the file back to the pubsub-onlyports: !reset [](or delete it) before a real-provider Codex run — a leftover mock URL will servesk-mockagainst production-looking model names.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

