Skip to content

aminmarashi/codex-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

codex-proxy

Bridge between Anthropic's Claude Code CLI and OpenAI Codex (ChatGPT Plus/Pro subscription).

Lets you run claude using your existing ChatGPT plan instead of a separate Anthropic API key or subscription.

How it works

Claude Code → localhost proxy (Anthropic format)
  → codex-proxy (translates to OpenAI Responses API)
    → chatgpt.com/backend-api/codex/responses
  • Authenticates via OAuth with your OpenAI account (same as opencode's Codex plugin)
  • Translates Anthropic Messages API and OpenAI-compatible requests to Codex Responses on the fly
  • Routes through chatgpt.com/backend-api/codex/responses using your subscription token
  • Maps Claude models to equivalent GPT models (e.g. claude-opus-4-7gpt-5.5)

Requirements

  • Node.js 18+
  • A ChatGPT Plus, Pro, or Team subscription with Codex access
  • Claude Code CLI

Setup

# 1. Authenticate with OpenAI (one-time)
./codex-proxy.js auth

# 2. Start the proxy (leave running in a terminal)
./codex-proxy.js proxy 9876

# 3. In a separate terminal, run Claude Code through the proxy
ANTHROPIC_BASE_URL=http://127.0.0.1:9876 ANTHROPIC_API_KEY=any claude --bare

# Or point OpenAI-compatible clients at the same proxy
OPENAI_BASE_URL=http://127.0.0.1:9876/v1 OPENAI_API_KEY=any your-openai-client

Commands

Command Description
codex-proxy.js auth [browser|headless] Authenticate with OpenAI (browser or device flow)
codex-proxy.js proxy [port] Start proxy server (default port: 9876)
codex-proxy.js token Print current access token

How it works

  1. Auth: Uses OAuth PKCE flow (browser) or device code flow (headless) to authenticate with your OpenAI/ChatGPT account. Tokens are stored in ~/.opencode-codex/token.json and auto-refreshed.

  2. Translation: Converts Anthropic Messages API requests and OpenAI-compatible /v1/responses or /v1/chat/completions requests to OpenAI Responses API format:

    • System prompts → instructions field
    • User/assistant messages → input array
    • Tool definitions → tools array
    • Tool calls → function_call / function_call_output items
  3. Routing: Forwards to https://chatgpt.com/backend-api/codex/responses with your OAuth access token.

  4. Response: Streams Codex SSE events back as Anthropic SSE when Claude requests streaming, or returns Anthropic JSON for non-streaming requests.

Performance knobs

Set these environment variables before starting the proxy:

Variable Description Default
CODEX_PROXY_REASONING_EFFORT Codex reasoning effort for normal requests low
CODEX_PROXY_TEXT_VERBOSITY Codex text verbosity low
CODEX_PROXY_INFLIGHT_LOG_MS Interval for verbose in-flight waiting logs; set 0 to disable 15000
CODEX_PROXY_RESPONSE_TIMEOUT_MS Total response timeout/retry budget; set 0 to disable 45000
CODEX_PROXY_VERBOSE_LOGS Set to 1 for detailed per-stage request logs 0
CODEX_PROXY_LOG_STREAM_EVENTS Set to 1 to include per-event stream logs 0

Notes

  • The proxy streams responses to Claude Code when stream: true is requested.
  • Before an upstream response starts, response timeouts are retried across 3 attempts with 10s/20s exponential backoff inside the response timeout budget.
  • Requests use Claude's session metadata as a stable prompt_cache_key when available.
  • Default per-request logs include request summaries, completion summaries, and errors. Set CODEX_PROXY_VERBOSE_LOGS=1 for detailed timing and stream diagnostics.
  • Token refresh happens automatically when the access token expires (checks before each request).
  • Model mapping: Claude models → GPT equivalents:
    • claude-sonnet-4-*, claude-opus-4-*, claude-3-5-sonnet-*gpt-5.5
    • claude-haiku-3-5*, claude-3-5-haiku*gpt-5.4-mini
    • Detected compact/summary requests for other models → gpt-5.4-mini
    • Unknown models default to gpt-5.5 (logged to stderr).
    • Model routing is fixed and has no environment variable override.

About

Bridge Claude Code CLI with OpenAI Codex subscription

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors