Sandbox
@insightflo/chatgpt-codex-proxy

Proxy for Claude Code to use ChatGPT Codex

This proxy speaks Claude Code's Anthropic API on one side and ChatGPT Codex on the other. It transforms messages, streams responses, maps model names, and can inject MCP tool schemas from `~/.claude.json` so Claude Code can keep using its tools.

44 stars12 forksTypeScriptUpdated 1mo ago
Who it's for

Builders who run Claude Code and want the same workflow to use ChatGPT Codex instead of Anthropic.

What it delivers

You can keep using `claude` as usual while your requests are served by GPT and your MCP tools still work.

What it does

Anthropic Messages API compatibility

Accepts `POST /v1/messages` so Claude Code can talk to the proxy without changing its normal workflow.

OAuth login for ChatGPT

Uses ChatGPT account login instead of an API key, so it can run from a Plus or Pro subscription.

Request and response transformation

Maps Anthropic requests to Codex requests and Codex SSE responses back to Anthropic format.

Model passthrough and mapping

Can forward Claude model names directly or map them to Codex models with environment overrides.

MCP tool injection

Reads `~/.claude.json`, connects to MCP servers over HTTP or stdio, and adds their tool schemas to Codex requests.

Parallel tool call guard

Detects mutating tools like Edit, Write, Delete, and Bash, then disables parallel tool calls for safety.

How to get it

  1. 1Then in another terminal
    export ANTHROPIC_BASE_URL=http://127.0.0.1:19080
    export ANTHROPIC_API_KEY=dummy   # value is unused; variable must be set
    claude
  2. 2Run
    cp .env.example .env

README

ChatGPT Codex Proxy

Run Claude Code on your ChatGPT Plus/Pro subscription — zero workflow change.

What is this?

This proxy lets Claude Code talk to ChatGPT's Codex backend instead of Anthropic's API. You keep using claude exactly as before — same UI, same slash commands, same MCP tools — while inference is served by GPT.

Claude Code  ──POST /v1/messages──>  chatgpt-codex-proxy  ──POST /codex/responses──>  ChatGPT
             <──Anthropic response──                       <──Codex SSE response──

When to use this

SituationThis proxy helps?
Anthropic quota exhausted / rate limited✅ Switch to GPT with one env var
Want to try GPT models without leaving Claude Code✅ Same workflow, different backend
Have ChatGPT Plus/Pro idle and want to make use of it✅ No API key cost
Need MCP tools (Stitch, Linear, etc.) to work with GPT✅ Only proxy that bridges this
Need an OpenAI-compatible endpoint for other clientsUse ChatMock instead
Need Ollama compatibilityUse ChatMock instead

Why this, not ChatMock or similar tools

ChatMock and similar projects expose an OpenAI/Ollama-compatible API — great for general-purpose clients, but you'd have to switch away from Claude Code entirely.

This proxy is built specifically for Claude Code:

  • Zero workflow changeclaude command, keybindings, CLAUDE.md, slash commands, all work unchanged.
  • MCP tools cross the boundary — Claude Code's MCP servers (Stitch, Linear, Chrome DevTools, etc.) are normally only available to Claude's backend. This proxy reads ~/.claude.json at startup, connects to your MCP servers, and injects their tool schemas into every GPT request. GPT gets the same tool access Claude would have.
  • Parallel tool call safety — the proxy detects mutating tools (Edit, Write, Delete, Bash) and automatically disables parallel_tool_calls to prevent unsafe concurrent file operations.
  • Claude model name passthrough — use --model claude-sonnet-4-20250514 as usual; the proxy maps it to the right Codex model automatically. Or use GPT model names directly in passthrough mode.

Example session

chatgpt-codex-proxy example session

Features

  • Anthropic Messages API compatible (POST /v1/messages)
  • OAuth 2.0 login — no API key, just your ChatGPT subscription
  • Full request/response transformation (Anthropic ↔ Codex)
  • SSE streaming
  • Claude → Codex model mapping with env overrides
  • MCP tool injection (see below)

Quick start

git clone <repo-url>
cd chatgpt-codex-proxy
npm install && npm run build

# Login with your ChatGPT account (browser opens)
npm run login

# Start the proxy
npm run dev

Then in another terminal:

export ANTHROPIC_BASE_URL=http://127.0.0.1:19080
export ANTHROPIC_API_KEY=dummy   # value is unused; variable must be set
claude

That's it. Claude Code is now running on GPT.

Optional: shell helper

Add this to .zshrc/.bashrc for a quick gpt alias:

gpt() {
  emulate -L zsh
  local proxy_port="${CHATGPT_CODEX_PROXY_PORT:-19080}"
  local token="${ANTHROPIC_AUTH_TOKEN:-${ANTHROPIC_API_KEY:-dummy}}"

  export ANTHROPIC_BASE_URL="http://127.0.0.1:${proxy_port}"
  export ANTHROPIC_AUTH_TOKEN="$token"
  export ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-$token}"
  export API_TIMEOUT_MS="${API_TIMEOUT_MS:-90000}"
  export PASSTHROUGH_MODE="${PASSTHROUGH_MODE:-true}"
  unset CLAUDE_CONFIG_DIR

  echo "Using local Codex proxy on :${proxy_port}"
  claude "$@"
}

MCP tool injection

Claude Code's MCP tools are normally invisible to non-Claude backends. This proxy bridges that gap.

Claude Code                   chatgpt-codex-proxy               ChatGPT Codex API
   │  tools: [Edit, Bash, ...]      │  tools: [Edit, Bash, ...        │
   │  (deferred: stitch, qmd, ...)  │          + mcp__stitch__*       │
   │                                │          + mcp__qmd__*  ]       │
   │ ──────────────────────────────>│ ──────────────────────────────> │

How it works:

  1. On startup: reads ~/.claude.jsonmcpServers
  2. Runs MCP handshake (initializetools/list) for each enabled server
  3. Caches schemas in memory for the lifetime of the proxy process
  4. On every /v1/messages request: appends cached tools to the Codex tools array
  5. When GPT calls a tool: Claude Code receives the tool_use response, executes the real MCP call, and sends the result back through the proxy

Both HTTP (type: http) and stdio (command) MCP servers are supported.

Configuration — set PROXY_MCP_SERVERS in .env:

# Specific servers (names must match keys in ~/.claude.json)
PROXY_MCP_SERVERS=stitch,linear

# All servers registered in ~/.claude.json
PROXY_MCP_SERVERS=all

# Disabled (default)
PROXY_MCP_SERVERS=

Startup log:

[mcp-registry] connecting to: stitch, linear
[mcp-registry] stitch: 8 tools loaded
[mcp-registry] linear: 6 tools loaded
[mcp-registry] ready: 14 total MCP tools

Configuration

.env setup

cp .env.example .env

Model mapping

By default (PASSTHROUGH_MODE=true) the proxy forwards whatever model name Claude Code sends straight to Codex. Set PASSTHROUGH_MODE=false to enable automatic Claude → Codex mapping:

Claude modelCodex model
claude-sonnet-4-20250514gpt-5.2-codex
claude-3-5-sonnet-20241022gpt-5.2-codex
claude-3-haiku-20240307gpt-5.3-codex-spark
claude-3-opus-20240229gpt-5.3-codex-xhigh
(fallback)gpt-5.2-codex

Override per family:

ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt-5.3-codex-spark
ANTHROPIC_DEFAULT_SONNET_MODEL=gpt-5.2-codex
ANTHROPIC_DEFAULT_OPUS_MODEL=gpt-5.2-codex

Available Codex models

ModelEffortNotes
gpt-5.4highFlagship (2026)
gpt-5high
gpt-5-codexhighOptimized for agentic coding
gpt-5-codex-minimedium
gpt-5.3-codexhigh
gpt-5.3-codex-xhighxhigh
gpt-5.3-codex-mediummedium
gpt-5.3-codex-lowlow
gpt-5.3-codex-sparklowSpeed-optimized, >1000 tok/s
gpt-5.2-codexhighProxy default
gpt-5.2-codex-xhighxhigh
gpt-5.2-codex-mediummedium
gpt-5.2-codex-lowlow
gpt-5.1-codexhigh
gpt-5.1-codex-maxxhigh
gpt-5.1-codex-minimedium

Shorthand aliases: gpt-5.3gpt-5.3-codex, gpt-5.2gpt-5.2-codex, gpt-5.1gpt-5.1-codex

Effort control

Claude Code's effort slider only affects native Claude models — it is not included in API requests when using GPT models. Control reasoning effort via:

Method 1 — model name suffix (recommended)

export ANTHROPIC_DEFAULT_SONNET_MODEL="gpt-5.3-codex-xhigh"  # xhigh
export ANTHROPIC_DEFAULT_HAIKU_MODEL="gpt-5.3-codex-spark"   # low

Method 2 — global override

PROXY_DEFAULT_EFFORT=high

Priority: thinking.budget_tokens in request → model name suffix/table → PROXY_DEFAULT_EFFORTmedium

CLI commands

CommandDescription
npm run loginOAuth login (browser)
npm run logoutDelete stored token
npm run statusShow auth status
npm run devStart dev server (hot reload)
npm run startStart production server

API compatibility

CapabilitySupportNotes
Basic chat
StreamingSSE
Multi-turn
System promptMapped to instructions
Tool callingFull tool_use/tool_result cycle
Image input⚠️Limited
TemperatureNot supported by Codex backend
Max tokensNot supported by Codex backend

Environment variables

VariableDefaultDescription
PORT19080Server port
PROXY_JSON_LIMIT20mbJSON body size limit
CODEX_BASE_URLhttps://chatgpt.com/backend-apiCodex API base URL
PASSTHROUGH_MODEtruefalse to enable Claude→Codex model mapping
ANTHROPIC_DEFAULT_HAIKU_MODEL-Codex model for Haiku requests
ANTHROPIC_DEFAULT_SONNET_MODEL-Codex model for Sonnet requests
ANTHROPIC_DEFAULT_OPUS_MODEL-Codex model for Opus requests
PROXY_DEFAULT_EFFORT(auto)low / medium / high / xhigh
PROXY_MCP_SERVERS(disabled)all or comma-separated server names from ~/.claude.json

Troubleshooting

# Health check
curl -fsS http://127.0.0.1:19080/health

# Port in use
lsof -tiTCP:19080 -sTCP:LISTEN -nP

# Passthrough test
gpt --model gpt-5.2

# Mapping mode test
PASSTHROUGH_MODE=false gpt --model claude-sonnet-4-20250514

# Recent logs
tail -n 120 /tmp/chatgpt-codex-proxy.log

# Tool calling smoke test
python3 scripts/tool_calling_smoke.py --base-url http://127.0.0.1:19080 --model gpt-5.2

Project structure

chatgpt-codex-proxy/
├── src/
│   ├── index.ts           # Entry point
│   ├── server.ts          # Express server
│   ├── cli.ts             # CLI commands
│   ├── auth.ts            # OAuth login
│   ├── routes/
│   │   └── messages.ts    # /v1/messages endpoint
│   ├── transformers/
│   │   ├── request.ts     # Anthropic → Codex
│   │   └── response.ts    # Codex → Anthropic
│   ├── codex/
│   │   ├── client.ts      # Codex API client
│   │   └── models.ts      # Model mapping
│   ├── mcp/
│   │   ├── config.ts      # Read ~/.claude.json MCP server configs
│   │   ├── client.ts      # HTTP + stdio MCP clients
│   │   └── registry.ts    # Tool schema cache (singleton)
│   ├── types/
│   │   └── anthropic.ts   # Types
│   └── utils/
│       └── errors.ts      # Error handling
├── .env.example
├── package.json
├── tsconfig.json
└── README.md

Security

Designed for personal, local-machine usage only.

npm run dev  # binds to localhost only
export ANTHROPIC_BASE_URL=http://127.0.0.1:19080

If you deploy to a server: add authentication, restrict CORS, add rate limiting, set token file permissions to 600, add monitoring.

Do not bind to 0.0.0.0 unless you have implemented all of the above.

License

MIT

Files in the repo

Repository payload14 top-level entries
  • .github
  • dxt
  • scripts
  • src
  • test
  • .env.example
  • .gitignore
  • chatgpt-codex-proxy.png
  • dxt.mcpb
  • package-lock.json
  • package.json
  • README_ko.md
  • README.md
  • tsconfig.json

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

43k

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code

14k
okf-memory/
okf-agent-memory

Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.

547
tirth8205/
code-review-graph

Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.

31k
2akouwu/
reverify

Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.

1.1k
t8y2/dbxConnectors

20 MB lightweight cross-platform database client for 90+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 90+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP Server。

19k