Can Claude Code and Codex Share One Quota? A 3-Step Gateway Setup

Blog / Relays & gateways

Can Claude Code and Codex Share One Quota? A 3-Step Gateway Setup

Short answer: if you sign in with each tool's official subscription, the Claude Code and Codex quotas are separate and cannot be shared. To have both tools draw from one quota, route both through the same gateway. The gateway must be compatible with both the Anthropic and OpenAI API formats. You change one endpoint setting in each tool and use the same key in both.

This approach has costs and prerequisites, which the sections below cover one by one.

Why can't official subscriptions share a quota?

When Claude Code is signed in with a Claude account, usage is recorded on your account at Anthropic. When Codex is signed in with a ChatGPT account, usage is recorded on your account at OpenAI. These are different companies with different metering systems, and there is no shared quota pool. For the exact limits and reset windows, rely on each vendor's official documentation. Two related posts on this site: How Claude usage limits are calculated and Codex usage limit reset timeline.

Another common setup is to switch both tools to API keys and pay each vendor directly. You still get two separate bills, just billed by usage with no subscription window. For the trade-offs between the two billing models, see Claude Code: subscription login or API key.

So "sharing" can only happen at a different layer: an intermediary gateway that accepts requests from both tools and meters them together.

How can one gateway serve both tools?

The two tools speak different "languages" by default:

ToolDefault API formatWhat to change
Claude CodeAnthropic formatEndpoint and key, via environment variables or settings.json
CodexOpenAI formatmodel_providers in config.toml

If a gateway supports both formats, it can accept both kinds of requests and deduct from the same account's quota under its own rules. If it supports only one, it can serve only one tool, and the other still has to go elsewhere. So the first thing to confirm when choosing a gateway is that it is compatible with both formats.

Take AGI Plan as an example (AGI Plan is a commercial partner of cdnping, and is a commercial partner). It is a monthly-subscription gateway that aggregates large models from multiple providers. It bills in RMB (Chinese yuan) and does not require an overseas credit card. It supports both the OpenAI and Anthropic API formats, meters usage in CU, and lets one quota be switched between multiple capability groups. It states clearly that it is not an officially authorized channel, so follow each model vendor's terms of service when using it. Step-by-step guides exist for Claude Code (no Claude account needed) and Codex (no ChatGPT account needed).

How do you set it up? Three steps

What follows is the general approach. For exact endpoints, environment variable names and field values, always use AGI Plan's setup guides and each tool's official documentation. Replace the placeholders in the examples.

Step 1: Get a key

Sign up with the gateway, pick a plan, and create a key. AGI Plan's flow is: sign up with an emailed verification code, choose a plan and create a key, then change one setting. We suggest creating a separate key for each tool so you can later see which one uses more (see How to control AI API spending for splitting by key).

Step 2: Configure Claude Code

Claude Code lets you set the endpoint and credentials through environment variables or the env block in settings.json. For file hierarchy and precedence, see Claude Code settings.json: hierarchy, precedence and env. Sketch:

# Variable names: follow the official Claude Code docs; use the address and key from the gateway's guide
export ANTHROPIC_BASE_URL="<Anthropic-format address from the gateway>"
export ANTHROPIC_AUTH_TOKEN="<your key>"

If you previously signed in with a Claude account on this machine, you may see an auth conflict or a 401. See Claude Code auth conflict and 401 errors for how to handle it.

Step 3: Configure Codex

Codex defines custom providers in ~/.codex/config.toml. For what each field means, see the Codex config.toml field reference. Sketch:

# Field values: follow the official Codex docs and the gateway's guide
model_provider = "gateway"

[model_providers.gateway]
name = "gateway"
base_url = "<OpenAI-format address from the gateway>"
env_key = "GATEWAY_API_KEY"

Then set GATEWAY_API_KEY in your terminal to your key. For fields such as wire_api, follow the gateway's guide.

Once both tools are configured, send a simple request from each to confirm you get a response. Then check in the gateway's account dashboard (see its official documentation for where to find it) that the requests are recorded under the same account.

What should you check before sharing a quota?

Switching to a gateway is not risk-free. These items are worth confirming before you pay:

  • Whether it supports both API formats, and whether the features you need (streaming, tool calls) work.
  • How quota is metered. AGI Plan uses CU, where 1 CU equals 1,000 output tokens of the baseline model. Consumption per capability group follows its published documentation.
  • Whether the models you want are available. Some models are marked "overseas only"; check https://agiplan.dev/models, and follow the terms of service and local regulations.
  • Stability. You can look at the availability data the operator publishes, or check probe results on cdnping's API status page.
  • Data handling. AGI Plan states that request bodies are not stored by default, and that content is not used for training or resale. With any gateway, read the privacy policy yourself.

For a fuller pre-purchase checklist, see Is a third-party AI gateway trustworthy? Eight checks before you buy.

When you don't need to bother

  • You use only one tool and the official subscription quota is enough: there is nothing to share.
  • You depend heavily on official account features or support: a gateway changes billing and the API entry point, and features exclusive to official accounts may not carry over.
  • Your usage is very small: first work out the break-even between pay-as-you-go and monthly plans, as described in AI API: pay-as-you-go or monthly.

Next steps

First estimate roughly how much each tool uses per month, then decide whether merging is worthwhile. If you want to try the gateway route, read How to choose among AGI Plan's four tiers, then follow the steps on the AGI Plan getting-started page. If you hit connection problems afterward, use the online speed test on the cdnping home page to see connection latency to each AI endpoint, then work through Claude Code connection timeouts and errors layer by layer.

Related articles

Keep reading