GitHub - lidge-jun/opencodex: Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code
Key Points
- 1OpenCodex is a lightweight local proxy that enables users to integrate a wide variety of LLMs, such as Claude, Gemini, and local models, into the Codex CLI, App, and SDK environments.
- 2It functions by translating Codex's responses API to match the requirements of various providers, while offering features like automatic quota management, multi-account session pooling, and advanced model routing.
- 3The software supports flexible installation via command-line tools or system services, allowing for seamless integration without modifying native configurations while maintaining history-safe operation.
OpenCodex is a lightweight, local proxy server designed to decouple the Codex CLI, App, and SDK from the native OpenAI backend, enabling the use of diverse Large Language Model (LLM) providers. By acting as a universal protocol adapter, it translates OpenAI Codex’s v1/responses API into formats compatible with over 40 providers, including Anthropic, Google Gemini, xAI, Ollama, DeepSeek, and any OpenAI-compatible Chat Completions endpoint.
Core Methodology and Technical Architecture
The proxy functions as an intermediary middleware layer that intercepts requests between the Codex client and the backend. Its architecture is built on a modular adapter pattern that maps Codex’s specific request-response cycle to various upstream protocols, such as Anthropic’s Messages API or general Chat Completions.1. Protocol Mapping and Model Routing
OpenCodex performs transparent translation of API payloads. It routes requests based on a provider/model syntax, aliasing model IDs and handling reasoning tokens, tool calls, and streaming natively. For models supporting advanced capabilities, it exposes per-model reasoning effort controls (low, medium, high, ultra) by mapping these to provider-specific parameters. Notably, it injects "compact delegation guidance" into prompts for advanced multi-agent systems, such as the GPT-5.6 Sol/Terra/Luna series, to manage sub-agent spawning and effort thresholds.
2. Credential Management and Account Pooling
To optimize resource utilization, OpenCodex implements a stateful ChatGPT account pool. It monitors quota windows across different time scales:
where the proxy automatically routes new sessions to the healthiest account (lowest usage) while maintaining affinity for existing threads via thread-ID pinning. This ensures that long-lived sessions (e.g., SSH or tmux-based) remain associated with the original authentication context, preventing session drops.
3. Integration and Deployment
The system uses a non-destructive injection strategy. It updates the Codex openai_base_url configuration to point to the local proxy (typically localhost:10100), ensuring the Codex client remains unaware of the redirection. This allows for clean teardowns using ocx restore, which reverts configuration changes and restores original history backups stored in ~/.opencodex/codex-history-backup.json.
4. Advanced Features and Sidecars
- Multi-Agent/Reasoning: The proxy handles complex orchestration by feature-flagging specific models in the Codex UI and managing model rosters.
- Image Generation: It provides a native bridge for Codex’s
image_gentools, mapping requests to the appropriate upstream generation or editing endpoints. - Experimental Bridge: It includes an experimental adapter for Cursor, which allows for local execution of shell commands, grep, and file system operations, though these are gated by an
unsafeAllowNativeLocalExecflag to mitigate security risks. - Security: For LAN-based deployments, the proxy enforces an authentication requirement via the
x-opencodex-api-keyheader, verified in constant time to prevent timing attacks.
The tool is distributed as an npm package that automatically bundles the Bun runtime, ensuring cross-platform compatibility across macOS, Linux, and Windows without requiring manual dependency management.