/model-gateway:model-gatewayfrom model-gateway
Set up, update, or diagnose the local ChatGPT/Codex gateway for Claude Code's /model picker. Use for gateway setup, login, model visibility, routing, or failures.
Ships in model-gateway. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Two local processes give Claude Code native access to the user's ChatGPT subscription models:
claude-code-proxy (does OpenAI OAuth and translates Anthropic Messages API to the Codex
backend) and a shim router this plugin owns. ANTHROPIC_BASE_URL points at the shim: requests
for claude-gpt-* models are un-prefixed and go to the proxy, claude-gemini-* models are
un-prefixed and go to a local antigravity-claude-proxy (installed separately from
https://github.com/badrisnarayanan/antigravity-claude-proxy or the antigravity-claude-proxy
npm package; default http://127.0.0.1:18766, override
with CODEX_GATEWAY_ANTIGRAVITY_ENDPOINT; it needs its own antigravity-claude-proxy accounts add Google login and is advertised only while its /v1/models answers), everything else passes through
to api.anthropic.com with the user's normal claude.ai login. The shim's /v1/models advertises
Codex models with a claude- prefix because Claude Code's model discovery drops ids that don't
start with claude/anthropic. That prefix is shared with the real Anthropic ids, so the route
is decided by the backend family segment (claude-gpt-*, claude-grok-*, claude-gemini-*), never by the prefix.
All commands: node "${CLAUDE_PLUGIN_ROOT}/bin/model-gateway.js" <command>
Project-local wiring is the standard setup. env --write-project writes the current project's .claude/settings.local.json, so the gateway stays configured for this project's sessions and executor worktrees without putting a machine-local endpoint in a committed file. setup uses the same project-local target by default.
env --write-user remains an opt-in shared fallback for people who deliberately want one gateway URL in the active config dir's settings.json ($CLAUDE_CONFIG_DIR/settings.json, defaulting to ~/.claude/settings.json) across every project. Claude Code gives a current project's settings.local.json higher precedence, so doctor marks the winner [effective], names both files, and says that project-local wiring wins when their gateway modes disagree.
The first-run order matters:
setup.login, then run setup again. The second setup finishes the download, wiring, and project confirmation.A plugin reload alone does not reload settings or the picker cache. Do not tell the user to select a new row until that full restart is complete.
The SessionStart hook injects a one-line nudge while the gateway is in any half-configured
state; act on it. The user sees that same line in the transcript, because a state only they can fix used to
reach the model alone. Anything routine stays out of it, and the hook always exits 0 so the line survives:
run ensure yourself when you need an exit code. SessionStart waits at most 12 seconds for a newly started
gateway, then leaves its supervisor to finish in the background so it stays inside Claude Code's hook budget. setup is one-shot and idempotent: it downloads the claude-code-proxy binary
(sha256-verified) and starts everything. Re-running it later is also the upgrade path. A newer cached Model Gateway version replaces an older sibling version from the same marketplace and plugin name. A different marketplace, plugin name, or non-cache install stays foreign and is refused.
node "${CLAUDE_PLUGIN_ROOT}/bin/model-gateway.js" setup
# only if setup says sign-in is needed:
node "${CLAUDE_PLUGIN_ROOT}/bin/model-gateway.js" login # browser OAuth; --device for headless
node "${CLAUDE_PLUGIN_ROOT}/bin/model-gateway.js" setup # finishes the wiring
login opens the user's browser; they complete it themselves (suggest ! node ... login if it
needs a real TTY). env --write-project writes this project's .claude/settings.local.json.
Use env --write-user only when the user wants a shared fallback across projects. If both are
present, project-local wiring wins: doctor marks it [effective], names the shadowed user file,
and fails when their gateway modes differ. All wiring changes apply to new Claude Code sessions,
so restart after the write. The Codex rows appear in /model labeled "From gateway".
The winning ANTHROPIC_BASE_URL source follows Claude Code's precedence: process environment,
current-project .claude/settings.local.json, project .claude/settings.json, then the
user settings.json in the active config dir ($CLAUDE_CONFIG_DIR, default ~/.claude). A process export always wins, so settings writes cannot replace it.
env --write-user --reconcile is confirmation-gated. Plain env --write-user writes the shared
user fallback, then lists recorded projects whose local URL differs without changing their files.
The confirmed command removes only Model Gateway-owned keys from those other projects'
.claude/settings.local.json files: its base URL, the three Claude alias pins, and static gateway
flags whose values equal plugin defaults. It leaves unrelated settings alone, skips projects already
agreeing, cannot change process.env, and needs a restart to affect a new session.
Discovery needs Claude Code v2.1.129+; models shows exactly what the shim advertises. Claude Code
only refetches gateway discovery when it has an API-key credential. OAuth subscriptions do not give it
one, so Model Gateway writes Claude Code's discovery cache whenever its advertised list changes.
Restart remains necessary to surface new rows in /model: Claude Code reads the picker cache once at
session start. /reload-plugins does not reload it. Restoring or refreshing auth on an already-wired
install needs no restart of the current Claude Code process: the proxy is a separate process, so once login + setup re-authenticate it,
the next request routes through cleanly. Settings, discovery-cache, plugin, or model-row changes do need a full restart of the affected project process. Keep these two recovery paths separate. The shim supervisor also probes the proxy's /v1/models endpoint
while it runs, restarting a proxy that stays unavailable across consecutive checks with single-flight bounded
backoff. A proxy that misses a single probe while it still holds its port is left alone, so a slow answer never
costs a live request. It leaves a healthy proxy alone. Recovery output remains in $CLAUDE_CONFIG_DIR/model-gateway/logs/guardian.log; bounded lifecycle records in
$CLAUDE_CONFIG_DIR/model-gateway/logs/lifecycle.jsonl identify supervisor, worker, and proxy PIDs, orderly
stop/restart requests, observed exits, and recovery outcomes. Use doctor to print the evidence path and
the last observed exit. An OS termination or force-killed supervisor may leave no final record, so treat an
absent exit record as absence of evidence, not a clean shutdown. Cleanup kills recorded PIDs only when the
live command still identifies this install and the record matches its command or start time. A stale record is
deleted without stopping its reused PID; doctor prints stale pid file guardian: PID <pid> is now <command>. Proxy recovery stops a listener using the shared proxy binary only
when the live process tree proves it descends from the recovering supervisor. A matching shared binary alone
never proves ownership. This matters when an agent is mid-orchestration
(e.g. dispatching Codex subagents through the gateway): do not tell the user to restart Claude Code just to
bring auth back, or you kill the session that was about to use it.
/model picker: rows like "GPT-5.6-sol (Codex)" and "Grok 4.5".~/.grok/auth.json, or CODEX_GATEWAY_GROK_HOME). Both the shim's boot catalog and its refreshModels() consult the same getGrokReadiness(), so the two never disagree. A missing Grok row therefore means "not signed in", not "shim broken": run grok and log in, then restart Claude Code. Typing /model claude-grok-4.5[1m] still routes and still refuses with the readGrokAuth message — gating is advertisement-only./model claude-gpt-5.6-sol[1m] or /model claude-grok-4.5[1m]. The picker and Sidequest catalog emit those exact ids. The suffix is stripped before routing to Codex or Grok.lib/runtime.js's exported MODEL_WINDOW_POLICY is the sole authority for gateway backend windows, picker aliases, advertised windows, and sentry mode. GPT-5.6 Sol, Terra, Luna, and GPT-6 Astra are measured rows. GPT ids absent from the table are deliberately advertised through its explicitly unmeasured 920k default, rather than silently inheriting a window. Grok 4.5 is a measured 500k row and now has the [1m] picker alias.920000 by default. Its synthetic 413 trigger is the smaller of CODEX_GATEWAY_COMPACT_TRIGGER when set and the policy row's backend window minus 40k tokens. CODEX_GATEWAY_COMPACT_TRIGGER is a ceiling, never an override of that headroom. With the optional client autoCompactWindow cap at 325000, Claude Code compacts around 292000, so the sentry is a backstop that normally does not fire. CODEX_GATEWAY_CONTEXT_WINDOW overrides every advertised Codex window. Claude Code 2.1.261 ignores a settings-file CLAUDE_CODE_MAX_CONTEXT_TOKENS value for its own unrecognized-model resolver, so rows above 200k use their policy's recognized [1m] alias. That alias gives Claude Code a 1M client window, the closest available setting to the verified 920k backend window; it does not promise a 1M backend input limit. A lower explicit autoCompactWindow still wins. Use /context to inspect the selected model and effective cap.[1m]) keep their OWN separate native windows
and compaction limits: the shim forwards their requests byte-identically to Anthropic and never
applies Codex window advertisement or error rewriting to them. The env block pins the current
real 1M aliases (Opus, Sonnet, Fable) to [1m] ids so a gateway session on one gets its full 1M
window instead of the 200k gateway default; Haiku stays unpinned (it's 200k). An env --write-*
command resolves those aliases through the installed Claude CLI's credential-free headless probe;
SessionStart refreshes its cache after the CLI changes or the cache ages out. A failed probe keeps
the last good pin, then a shipped safe default. Set a persistent per-alias override with
pin --opus claude-opus-4-8[1m] (same for --sonnet and --fable), or use pin --opus default
to return to auto-detection. Overrides always win. pin with no arguments shows each effective
pin and whether it is overridden. Overrides live in $CLAUDE_CONFIG_DIR/model-gateway/pins.json, outside
the plugin cache. After a pin change or Claude CLI upgrade, run env --write-project (or
env --write-user for a shared fallback) and start a new Claude Code session; changing a saved value alone cannot alter
an open session.CLAUDE_CODE_AUTO_COMPACT_WINDOW: it applies to both providers and can make Codex
/compact fail after history already exceeds the Codex limit.claude-api, ~800k chars) in a single turn can
spike Codex context past the point proactive compaction can recover from. Prefer pulling large
references incrementally on Codex models.models.json file cannot add a backend that the claude-code-proxy allowlist does not support; update the proxy through setup instead./model cannot
both work. RC-compatibility points ANTHROPIC_BASE_URL at api.anthropic.com, and Claude Code
disables gateway model discovery for that host. The gateway still routes explicit ids: type
/model claude-gpt-5.6-terra[1m], and Claude Code accepts and saves it as the default. Disabling
compatibility restores the picker rows. Sidequest dispatch is unaffected because it resolves its
explicit route marker and never uses picker discovery.Request-route logging is enabled by default. It writes metadata-only JSONL records to
$CLAUDE_CONFIG_DIR/model-gateway/logs/request-routes.jsonl: timestamp, backend, model, request path, route and
effort when present, safe session and agent correlation ids, and dispatch-marker length when present. It
never writes request bodies, prompts, messages, tools, authentication, or arbitrary headers. Honor a user
request to disable it by setting CODEX_GATEWAY_REQUEST_LOG=0 before the shim starts, then restart the shim
through setup or ensure. The value is read when the shim process starts, so /reload-plugins does not
change an already-running shim. CODEX_GATEWAY_REQUEST_LOG_PATH changes the file location.
Usage observability also writes one high-water JSON file per valid session under
$CLAUDE_CONFIG_DIR/model-gateway/request-body/. The filename is derived from the session id. Its contents are the
largest forwarded request-body byte count observed for that session and an observation timestamp. It does
not contain the request body. No retention period is promised for either local record.
For the confirmation-gated procedure, use the remote-control-compatibility skill. It manages the
plugin-marked hosts block, creates a backup before an elevated write, reconciles gateway mode, and
checks the final state. Do not edit the hosts file outside that procedure.
Claude Code's /remote-control only lights up when ANTHROPIC_BASE_URL is exactly the real
Anthropic host, which conflicts with gateway model discovery. Remote Control and the Codex/Grok rows
in /model cannot both work. Before enabling compatibility, tell the user that the rows disappear
from the picker, while explicit ids such as /model claude-gpt-5.6-terra still work and persist as
the default. Disabling compatibility restores the rows. model-gateway offers an opt-in, fully
reversible workaround:
api.anthropic.com to loopback — 127.0.0.1 api.anthropic.com in /etc/hosts on supported
macOS and Linux systems (needs sudo). If asked to help with this, tell the user the exact line
and file, and that they need elevated privileges to save it; do not attempt to edit the hosts file
yourself.ensure/setup/doctor detect the entry (read-only) and, only after confirming the shim can
actually bind loopback port 80, switch ANTHROPIC_BASE_URL to http://api.anthropic.com and
start a second listener on port 80 next to the account's usual loopback shim port. Exactly one line tells
the user to restart Claude Code when the mode changes either direction.doctor reports the hosts entry (if any), whether port 80 actually bound (and why not if it
didn't), and which mode each settings scope (user/project) is wired to.CODEX_GATEWAY_HOSTS_FILE (custom hosts path), CODEX_GATEWAY_COMPAT_PORT
(port other than 80). Neither is needed for normal use.... status # what's running
... doctor # binary, auth, ports, model count, settings wiring
... ensure # start whatever is down (SessionStart hook runs this with --quiet)
... stop
... env --remove # unwire Claude Code (do this BEFORE uninstalling the plugin)
doctor prints the full model-window table: backend and picker ids, backend and advertised windows,
Claude Code's resolved client window and compaction point, sentry mode and trigger, and the measurement
date. It includes Codex, Grok, and native Claude pin rows. Its model-id check is useful for stale shim ids,
but a PASS does not prove every supported model is present. A proxy from 0.1.14 through 0.1.35 can
omit GPT-6 Astra while this check passes. If Astra is missing, check the installed and serving proxy
version, rerun setup to fetch the latest release, and fully restart Claude Code. Astra requires
claude-code-proxy 0.1.36 or newer. A models.json edit cannot add a backend that the proxy allowlist
does not support. A FAIL naming missing and extra ids means the shim is stale even when its version
matches: restart it through the normal ensure or setup path, then restart Claude Code sessions so the
picker re-discovers the rows.
Logs live in $CLAUDE_CONFIG_DIR/model-gateway/logs/. guardian.log has recovery output; lifecycle.jsonl
has bounded process evidence that doctor summarizes. Ports are per account tree: shim 18764 and
proxy 18765 apply only to the default tree (the physical ~/.claude). Every other config dir derives
a stable even/odd pair in 20000-27999 from its path, so two accounts never share a gateway. Override
with CODEX_GATEWAY_PORT / CODEX_GATEWAY_PROXY_PORT (also the remedy for a rare derived-port
collision), but the env block and running processes must agree. A shim never serves another
account's sessions. When readiness reports the port is held by a different install root, rerunning
ensure cannot fix it and that process must never be stopped from here: manage it from the account
that owns it, or set the port overrides for this account.
doctor, check logs. Worst case env --remove restores stock behavior instantly.settings.local.json (or committed settings.json) still sets ANTHROPIC_BASE_URL to the shim
port. doctor WARNs about every project recorded in wired-projects.json that is still wired
while the plugin is disabled in the active tree or the shim is not listening, and prints that
project's exact cd "<project>" && node "<cli>" env --remove command (wiring in a committed
settings.json is named for deletion by hand). Doctor removes nothing itself; offer the user
the printed command. It also lists registry entries whose directory is gone or whose settings no
longer point at the gateway, and drops them only for doctor --prune-wired-projects.
update-loadout prints the same list (via wired-projects) when it skips a disabled gateway.doctor and include its supervisor conflict line and lifecycle evidence.login state
(doctor shows auth), then proxy log. OpenAI gates non-Codex clients by request fingerprint;
when they tighten it, requests die mid-stream until claude-code-proxy ships a fix, so
suggest re-running setup (it fetches the latest release).ensure
or stop after process inspection is available; do not kill an unconfirmed listener or bypass the
refusal with a direct /drain or /restart request. Confirmed older cache siblings may be replaced;
a foreign install must be managed through its own install.ensure invocations overlap (e.g. two SessionStart hooks firing close together): ensure
claims an exclusive ensure.lock in the gateway state dir before deciding recovery is needed. A
second, concurrent ensure waits briefly for the first to finish and reports its actual outcome
rather than independently observing the same symptom and starting its own recovery; a lock left by
a process that is no longer alive is reclaimed, not blocked on forever, and so is one past an
absolute age cap whatever its pid reports, so a holder that died and had its pid recycled onto an
unrelated live process cannot deadlock recovery. Releasing only ever frees a lock the releasing
process still holds, so a reclaimed-from holder cannot delete its successor's lock. startAll (the routine
behind ensure/setup/SessionStart) also requires three consecutive failed shim-health probes
before it will stop a bound-but-unresponsive supervisor, and a racer whose own startup wait times
out still reports ready if a final authoritative check finds the gateway actually serving. Together
these close the 2026-09-14 incident where two concurrent ensures each tore down, on one bad probe,
a supervisor that had been healthy for 16 hours.CODEX_GATEWAY_PROBE_TIMEOUT_MS
(2 seconds by default). An inspection failure stays retryable: recovery leaves the listener alone,
records owner-unknown when process inspection is inconclusive, and tries again after backoff.
Linux discovery retains the /proc fallback when lsof is unavailable. Shutdown kills and reaps
probe children. A confirmed foreign owner is refused and never replaced. Account-specific state
and socket paths remain isolated.doctor shows Not authenticated right after an upgrade: bumping the proxy binary (e.g.
0.1.10 → 0.1.17 via setup) can invalidate the credential the old version accepted — the new
binary reads it as not authenticated and setup stops before wiring. Fix: re-run login, then
setup again to finish. Until then every Codex model is down, so any run that routes to
Codex (a whole sidequest board of Codex-tier tickets, for one) stalls entirely./model: do not diagnose account access first. Check the installed and serving claude-code-proxy version. Astra requires 0.1.36 or newer; 0.1.35 does not include its backend allowlist, while the current doctor floor can still pass. Re-run setup to fetch the latest GitHub release, then fully restart Claude Code. Do not propose models.json: it cannot add a backend the proxy does not allow.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY
missing), Claude Code < v2.1.129, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC is set (it
disables discovery), or RC-compatibility is active. Claude Code only refetches discovery with an
API-key credential, so OAuth users rely on Model Gateway's cache write. Run doctor to check the
cache, then restart Claude Code after it updates; /reload-plugins does not reload picker rows.stop + start). Shift+Tab restores the mode in an affected session. Escape
hatch to re-enable plan tools: CODEX_GATEWAY_KEEP_PLAN_TOOLS=1.400 Invalid schema for function '<Tool>': OpenAI-shaped
backends validate every tool's JSON Schema pattern against ECMA-262 and refuse Unicode property
escapes (\p{...}) and lookbehind. A single offending tool fails the whole request before it
reaches the model, and Claude Code's Artifact tool carries such a pattern on its field
parameter. The shim strips only the unsupported pattern values from Codex- and Grok-bound tool
schemas, leaving parseable ones intact so the model still sees the useful constraints; a
malformed argument then fails at the tool instead of at the API. Claude-bound requests are never
touched. If it recurs, read the tool name out of the error and confirm the shim actually
restarted (stop + start).What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub poindexter12/loadout --plugin model-gateway2 skills in this plugin
Other plugins' skills for the same job