Claude Code vs Codex CLI: Cost per Session, Setup

Claude Code vs Codex CLI for real coding work: cost of one session with Opus 5.5 and GPT-6.2 Sol, custom API key setup, approvals, sandbox, MCP and config.

GoiAPI · · 13 min read

Ask AI and more
View as Markdown

Bar chart of one 40-request coding session on GoiAPI: Claude Code with Opus 5.5 about $0.34, Codex CLI with GPT-6.2 Sol about $0.096, Haiku 5.5 about $0.019, GPT-6 Luna about $0.015

Claude Code vs Codex CLI comes down to which model family you want to work with and how much each session may cost. Claude Code is Anthropic's terminal agent, built for Claude models such as Claude Opus 5.5; Codex CLI is OpenAI's, built for GPT models such as GPT-6.2 Sol. On GoiAPI prices checked on December 5, 2026, one example 40-request coding session costs about $0.34 with Claude Code on Opus 5.5 and about $0.10 with Codex on GPT-6.2 Sol, roughly 3.5 times apart for the same token mix. Both tools can run on one API key, so you can keep both and pick per task.

This guide compares the two for everyday coding work: what a session costs (with every assumption written down), how to point each tool at your own API key and base URL, which models each runs best, context windows, approvals and sandboxing, MCP servers, and the config files you will edit. Tool facts come from Anthropic's Claude Code docs and OpenAI's Codex docs, checked on December 5, 2026. The latest versions on npm that day were Claude Code 2.1.337 and Codex CLI 0.174.0.

Claude Code vs Codex CLI at a glance

Claude CodeCodex CLI
Made byAnthropicOpenAI
Built forClaude models (Opus, Sonnet, Haiku aliases)GPT models
API format it sendsAnthropic Messages (/v1/messages)OpenAI Responses (/v1/responses) only
Custom key setupEnvironment variables or the env block in settings.jsonA [model_providers.<id>] block in ~/.codex/config.toml
Default safety modelAsks before most edits and commands; Bash sandbox is opt-inSandbox on by default (workspace write, network off), asks when needed
Project instructionsCLAUDE.md (reads AGENTS.md if there is no CLAUDE.md)AGENTS.md
MCPclaude mcp add, stored in ~/.claude.json or .mcp.jsoncodex mcp add, stored under [mcp_servers.<name>] in config.toml
Example session on GoiAPIabout $0.34 with Opus 5.5about $0.10 with GPT-6.2 Sol

The session row is explained in the cost section below. It is a calculation from published prices, not a measurement of either tool.

The models each tool runs best

Claude Code is designed and tested for Claude models. It has three model aliases, opus, sonnet and haiku, and the haiku one is also used for background tasks. On GoiAPI you can use Claude Opus 5.5 (claude-opus-5-5) for hard work and Claude Haiku 5.5 (claude-haiku-5-5) for small tasks. GoiAPI does not offer a Sonnet model, so if you switch aliases, map the sonnet alias to Opus or Haiku with ANTHROPIC_DEFAULT_SONNET_MODEL, as shown in the Claude Code API key guide.

Codex CLI is built around OpenAI's GPT models. The newest GPT model on the GoiAPI models page is GPT-6.2 Sol (gpt-6.2-sol), which costs the same as GPT-6.1 Sol. For cheap, simple edits there is GPT-6 Luna (gpt-6-luna). Inside Codex, /model chooses the active model and, when available, the reasoning effort.

Can you cross over? Partly:

  • Anthropic says it does not support Claude Code with non-Claude models. In our short test on December 3, 2026, Claude Code did answer through GoiAPI with gpt-6.1-sol, but printed an unrecognized-model warning, and we did not test long sessions that edit files. Claude Code Router covers that setup and its trade-offs.
  • Codex can call any model that an API service offers on the Responses API. GoiAPI's Codex integration guide even uses claude-haiku-5-5 as its example. How well a non-GPT model handles Codex's tool calls varies, so try a small task first.

The practical rule: Claude models in Claude Code, GPT models in Codex. If you want to compare model families on the same task, run each in its native tool.

Cost per coding session

GoiAPI prices used in this comparison

USD per 1 million tokens, from the GoiAPI pricing page and the model pages, checked on December 5, 2026:

ModelModel nameInputCache writeCache readOutputMax context
Claude Opus 5.5claude-opus-5-5$0.442$0.8775$0.0221$2.211,000,000 tokens
Claude Haiku 5.5claude-haiku-5-5$0.0221$0.04388$0.00221$0.11051,000,000 tokens
GPT-6.2 Solgpt-6.2-sol$0.13$0.1625$0.01303$0.781,050,000 tokens
GPT-6 Lunagpt-6-luna$0.0208$0.026$0.002106$0.12481,050,000 tokens

Per token, Opus 5.5 costs about 3.4 times as much as GPT-6.2 Sol for input and about 2.8 times as much for output. Both have one rate at any prompt length on GoiAPI. For the full rate cards and how they compare with the makers' list prices, see Claude API pricing and GPT-6 API pricing.

The example session and its token assumptions

Coding agents resend the conversation on every request: system prompt, tool definitions, project instructions, files read so far and earlier tool output. That makes input and cache tokens the bulk of a session. As a reference point, in our December 3, 2026 test a one-line question in Claude Code (Claude Haiku 5.5, empty folder) used 10,679 input tokens and 15,574 cache-write tokens before any project files were read. We have not measured Codex the same way, so the example below uses the same token mix for both tools.

Example session: one medium task, such as adding an API endpoint with tests in an existing repository, taking 40 requests in total:

  • 100,000 uncached input tokens
  • 200,000 cache-write tokens
  • 1,500,000 cache-read tokens (the repeated context)
  • 40,000 output tokens (code, explanations and tool calls)

Cost = tokens × price ÷ 1,000,000. The small per-request minimum charge is left out, so real costs are slightly higher.

What the session costs

Tool and modelPer session, with caching5 sessions a daySame session if nothing is cached
Claude Code + Claude Opus 5.5about $0.34about $1.71about $0.88
Codex CLI + GPT-6.2 Solabout $0.096about $0.48about $0.27
Claude Code + Claude Haiku 5.5about $0.019about $0.094about $0.044
Codex CLI + GPT-6 Lunaabout $0.015about $0.077about $0.042

Worked example for Opus 5.5: 100,000 × $0.442 = $0.0442 input, 200,000 × $0.8775 = $0.1755 cache write, 1,500,000 × $0.0221 = $0.0332 cache read, 40,000 × $2.21 = $0.0884 output, so about $0.34. For GPT-6.2 Sol the same four lines give $0.013 + $0.0325 + $0.0195 + $0.0312, about $0.096. The "nothing cached" column bills all 1.8 million context tokens at the input rate.

What this means in practice:

  • Cache writes are the largest line for Opus. About half of the Opus session is cache writes. Switching models mid-session or leaving a session idle until the cache expires forces new writes; reducing Claude Code token usage covers the habits that keep the cache warm.
  • Cost per task is not cost per token. If one model needs two attempts where another needs one, the gap changes. Neither vendor publishes a like-for-like tokens-per-task figure for these two tools, and we have not measured one.
  • Tokens differ by tool. Each tool has its own system prompt and tools, and each model has its own tokenizer, so the same task will not produce identical counts. Run one real task in each and compare the cost of each request in Request history.

For a monthly view of Claude Code at light, moderate and heavy use, and how that compares with a Max or Ultra plan, see Claude Code Max vs API cost. To plug in your own numbers, use the cost calculator.

Setup with your own API key and base URL

Both tools can run on an API key instead of a subscription sign-in. The difference is where the settings live and which API format the endpoint must speak.

Claude Code: environment variables

Claude Code sends Anthropic Messages requests. Set the base URL without /v1, because Claude Code appends /v1/messages itself:

BASH
export ANTHROPIC_BASE_URL="https://api.goiapi.com"
export ANTHROPIC_AUTH_TOKEN="sk-..."
export ANTHROPIC_MODEL="claude-opus-5-5"
claude

On Windows PowerShell, use $env:ANTHROPIC_BASE_URL = "https://api.goiapi.com" and the same pattern for the other two. To make it permanent, put the three variables in the env block of ~/.claude/settings.json. Run /status to confirm the base URL is active. The full walkthrough, including the VS Code extension and the 404 you get with a trailing /v1, is in Claude Code API key setup.

Codex CLI: a custom provider in config.toml

Codex talks to custom providers only through the Responses API; the config reference says responses is the only supported wire_api value. Add this to the user-level ~/.codex/config.toml:

TOML
model = "gpt-6.2-sol"
model_provider = "goiapi"

[model_providers.goiapi]
name = "GoiAPI"
base_url = "https://api.goiapi.com/v1"
env_key = "GOIAPI_API_KEY"
wire_api = "responses"

Then set GOIAPI_API_KEY in your shell and run codex. Here the base URL includes /v1. Codex ignores model_provider and model_providers in a project's .codex/config.toml, so this block must go in the file in your home folder. Profiles, Windows commands and error fixes are in Codex CLI custom provider.

SettingClaude CodeCodex CLI
Base URLhttps://api.goiapi.com (no /v1)https://api.goiapi.com/v1
KeyANTHROPIC_AUTH_TOKEN (or ANTHROPIC_API_KEY)Any variable named in env_key
ModelANTHROPIC_MODEL or /modelmodel in config.toml, -m flag or /model
Check it/status, then Request history/status, then Request history

Context window and long sessions

On GoiAPI, Claude Opus 5.5 has a maximum context of 1,000,000 tokens and GPT-6.2 Sol 1,050,000 tokens, with up to 128,000 output tokens each. In practice the two are equal for repository work: both hold far more than a typical session needs.

What matters more is how each tool keeps the context small. Claude Code has /context to show what fills the window, /compact to summarize and /clear to start fresh. Codex has /compact ("summarize the visible chat to free tokens"), /new for a fresh chat in the same CLI session, and /status to show configuration and token usage. If Codex does not know the window of a model from a custom provider, the model_context_window key in config.toml sets it. A big window still costs money: every token in it is resent, and billed, on each request. If a long Claude Code session does hit the limit, see fixing "Prompt is too long" in Claude Code.

Approvals and sandbox

This is the biggest day-to-day difference.

Claude Code controls actions with permission modes. The default mode asks before most file edits, shell commands and network access. acceptEdits lets it edit files in your working directory without asking, plan researches and proposes without editing, auto lets a classifier model approve or block actions, dontAsk denies anything that would prompt (for CI), and bypassPermissions skips prompts and is meant for containers and VMs only. You cycle modes with Shift+Tab, start with --permission-mode, or set permissions.defaultMode. Allow, ask and deny rules in settings files fine-tune it. The Bash sandbox is separate and opt-in: run /sandbox (macOS, Linux and WSL2) or set sandbox.enabled.

Codex CLI combines a sandbox with an approval policy. sandbox_mode is read-only, workspace-write or danger-full-access; approval_policy is on-request, never or a granular table. The default "Auto" preset is workspace-write with on-request, and the agent runs with network access off unless you allow it. The docs say untrusted is no longer supported and on-failure is deprecated, so remove them if an old guide put them in your config. /permissions changes this mid-session, and --yolo turns off both sandbox and approvals (not recommended). The sandbox uses Seatbelt on macOS, bwrap and seccomp on Linux, and a native sandbox on Windows.

In short: Codex starts more locked down and lets the sandbox do the work; Claude Code starts by asking you and leaves sandboxing to you.

MCP servers

Both tools support MCP servers, local (stdio) and remote (HTTP).

BASH
# Claude Code
claude mcp add --transport http notion https://mcp.notion.com/mcp
claude mcp add --scope project context7 -- npx -y @upstash/context7-mcp

# Codex CLI
codex mcp add context7 -- npx -y @upstash/context7-mcp
codex mcp add example --url https://mcp.example.com

Claude Code has three scopes: local (default) and user are stored in ~/.claude.json, and project scope writes a .mcp.json you can commit; Claude Code asks before using a project's .mcp.json servers. Codex stores each server as a [mcp_servers.<name>] table in ~/.codex/config.toml, or in a trusted project's .codex/config.toml. Both have /mcp to see what is connected.

Config files side by side

PurposeClaude CodeCodex CLI
Personal settings~/.claude/settings.json~/.codex/config.toml
Shared project settings.claude/settings.json (commit it).codex/config.toml (loaded only for trusted projects)
Personal project override.claude/settings.local.jsonA profile file, codex --profile <name>
Project instructionsCLAUDE.md, CLAUDE.local.md; AGENTS.md if no CLAUDE.mdAGENTS.md (/init creates a scaffold)
MCP servers~/.claude.json, .mcp.json[mcp_servers.<name>] in config.toml
FormatStrict JSONTOML

If your repository already has an AGENTS.md, Claude Code (v2.1.277 or later) reads it when there is no CLAUDE.md, so one instruction file can serve both tools. Never put an API key in a shared project file; keep it in your user settings or an environment variable.

Which one should you use?

SituationPick
You want Claude Opus 5.5 for hard bugs and large refactorsClaude Code
You want GPT-6.2 Sol, or a lower cost per sessionCodex CLI
You want the agent sandboxed by default, network offCodex CLI
You want fine-grained allow/ask/deny rules and plan modeClaude Code (Codex also has /plan)
Small edits and boilerplate on a tight budgetClaude Code + Haiku 5.5 or Codex + GPT-6 Luna
A team repository already using AGENTS.mdEither; both read it

Many developers keep both: Claude Code with Opus 5.5 for planning and difficult changes, Codex with GPT-6.2 Sol for well-scoped tasks. With one GoiAPI key, both tools draw from the same balance and show up in the same Request history.

One limit to plan for: each API key has a requests-per-minute limit, and each request can run for up to 15 minutes (Limits and balance). If you run both tools hard at the same time, or many parallel subagents, give each tool its own key with its own spending limit.

Pay for both with one balance

GoiAPI bills every model from one USD balance. Top up with USDT (TRC20 or BEP20) or Binance Pay, with no credit card and no monthly fee. Top-ups are final and cannot be refunded, so add only what you plan to use and start small while you compare the two tools.

FAQ

Is Claude Code or Codex CLI cheaper?

It depends on the model, not the tool. In our example 40-request session on GoiAPI prices checked on December 5, 2026, Claude Code with Opus 5.5 costs about $0.34 and Codex with GPT-6.2 Sol about $0.10. With the small models, Claude Code with Haiku 5.5 and Codex with GPT-6 Luna both cost under two cents per session.

Can I use Claude Code and Codex CLI with the same API key?

Yes, on a service that offers both the Anthropic Messages and the OpenAI Responses formats. With GoiAPI, Claude Code uses https://api.goiapi.com and Codex uses https://api.goiapi.com/v1, with the same key.

Can Codex CLI use Claude Opus 5.5?

Yes, on an API service that offers Claude on the Responses API, such as GoiAPI: set model = "claude-opus-5-5". Codex is designed around GPT models, so test a short task before relying on it for long sessions.

Does Codex CLI still support wire_api = "chat"?

No. The current config reference says responses is the only supported value, so the endpoint must implement /v1/responses.

Which has the larger context window?

On GoiAPI, GPT-6.2 Sol lists 1,050,000 tokens and Claude Opus 5.5 lists 1,000,000. Both are far above what a normal coding session uses.

Try both on the same task

  1. Create a GoiAPI account and generate an API key.
  2. Top up a small amount with USDT or Binance Pay.
  3. Run one real task in Claude Code with claude-opus-5-5 and the same task in Codex with gpt-6.2-sol on separate branches, then compare the diffs and the cost of each request in Request history.

The short setup steps are also in the Claude Code and Codex integration docs.

GoiAPI sells API access to the models mentioned in this article.

Related posts