Codex CLI vs Claude Code vs Gemini CLI: how to choose
Updated 2026-07-15
Claude Code produces the strongest multi-file refactors and root-cause debugging of the three, Codex CLI ships the most locked-down sandbox for unattended automation, and Gemini CLI is the only one that runs free inside a daily quota instead of a metered bill. Pick Claude Code for architecture and hard bugs, Codex CLI for CI-safe code generation, and Gemini CLI for fast, no-cost exploration of a large repository.
Quick answer: three different jobs, not one winner.
Codex CLI, Claude Code, and Gemini CLI all do the same basic thing: they sit in your terminal, read your repository, and edit files or run commands on your instruction. The difference is in the defaults each vendor picked and what that means for your workflow and your bill. Claude Code, built by Anthropic, defaults to a Claude Sonnet-tier model with an Opus override for the hardest tasks, and it is widely reported as the strongest of the three at tracing a bug across multiple files and at refactors that touch tests as well as source. Codex CLI, built by OpenAI, runs a GPT-5-family coding model inside an OS-level sandbox by default, with Docker available as an opt-in for stricter isolation, which makes it a safe pick for unattended runs in CI. Gemini CLI, built by Google, defaults to a Google account login but also accepts a GEMINI_API_KEY or Vertex AI credential, defaults to a Gemini model with a very large context window, and is free to use inside a daily request quota rather than billed per token on that default login path. None of the three is a strict upgrade over the others. The rest of this page works through the mechanics, the real cost math, and the setup for each so you can match the tool to the job instead of guessing from a marketing page.
How each CLI actually works, and where the bill comes from.
That last point is what actually drives the bill for Codex CLI and Claude Code. Both are metered per token against whatever account you authenticate with, and because each call in the loop resends the growing context, a single multi-step task can burn far more tokens than the length of your original prompt would suggest. Gemini CLI sidesteps this arithmetic for most users: it runs against a free daily quota tied to your Google account, so the practical limit is a wait for the quota to reset rather than a running dollar total, at least until you exceed what the free tier allows.
- Codex CLI talks to an OpenAI-compatible chat completions endpoint, defaults to a GPT-5-family coding model, and executes shell commands and file edits inside an OS-level sandbox (seatbelt on macOS, landlock on Linux) that isolates network access unless you open it up; Docker is an opt-in, not the default.
- Claude Code talks to the Anthropic Messages API, defaults to a Claude Sonnet-tier model with an Opus override for architecture and hard debugging, and runs commands through a restricted local shell that still prompts before most writes.
- Gemini CLI defaults to a Google account login but also supports a GEMINI_API_KEY or Vertex AI credential, defaults to a Gemini model with the largest context window of the three, and does not wrap file writes or shell execution in the same kind of sandbox the other two use.
- All three are agentic, not single shot. One instruction from you can become a dozen or more model calls as the tool reads files, runs a command, checks the result, and decides what to do next, and every one of those calls resends the conversation built up so far.
Worked example: what a real coding session costs.
Model this by call volume instead of guessing. A short session might run about 8 agent calls, a typical session runs closer to 30, and a heavy day of three long sessions can push past 90. Because each call resends the accumulated context, tokens climb faster than call count: the table below assumes roughly 0.4M input tokens for a light session, 2.4M for a typical one, and 9M across a heavy day, with output staying small in every case. Codex CLI is priced here at OpenAI's direct list rate for a GPT-5-family coding model in this site's catalog, gpt-5.3-codex-spark, and Claude Code at Anthropic's direct list rate for claude-sonnet-4-6. Gemini CLI has no per-token bill for most users because it runs against a free daily quota, so its column reads as free until that quota resets rather than a dollar figure.
| Session profile | Codex CLI (direct rate) | Claude Code (direct rate) | Gemini CLI |
|---|---|---|---|
| Light (about 8 calls) | $0.81 | $1.32 | Free (daily quota) |
| Typical (about 30 calls) | $4.62 | $7.65 | Free (daily quota) |
| Heavy day (about 90 calls) | $17.01 | $28.35 | Free until quota resets |
Why the bill, or the quota, surprises people.
Most of this is avoidable with a bit of routing discipline, which the next two sections cover.
- Free is not unlimited. Gemini CLI's no-cost tier still enforces a daily request cap on your Google account, and hitting it mid-task stops the session rather than a meter running up.
- Agent loops multiply calls fast. A single request to fix a failing test can trigger far more model calls than the one message you typed, and each call re-bills the context that came before it.
- Sandboxing adds latency, not just isolation. Codex CLI's default OS-level sandbox adds a little startup overhead per session that a plain restricted shell skips, and opting into full Docker isolation for CI adds more still, which shows up as slower turnaround rather than a bigger bill.
- Swapping the default model changes the bill without changing the workflow. Pointing any of these tools at the priciest tier for routine edits multiplies cost for work a cheaper model handles just as well.
- CI and other non-interactive runs remove the approval prompts that normally let you notice a runaway loop before it finishes, so the first sign of trouble is often the invoice or the exhausted quota, not a warning on screen.
Codex CLI vs Claude Code vs Gemini CLI, feature by feature.
The three tools converge on the basics: reading a repository, editing files, running commands. They diverge on sandboxing, billing, and how you authenticate. Treat the table below as a practical summary, not a spec sheet; every vendor updates the underlying model on its own schedule.
| Feature | Codex CLI | Claude Code | Gemini CLI |
|---|---|---|---|
| Built by | OpenAI | Anthropic | |
| Default model family | GPT-5-family coding model | Claude Sonnet, Opus override available | Gemini, large-context variant |
| Install command | npm install -g @openai/codex | npm install -g @anthropic-ai/claude-code | npm install -g @google/gemini-cli |
| Billing model | Per token, metered | Per token, metered | Free daily quota by default; metered via API key or Vertex AI |
| Shell and file sandbox | OS-level sandbox by default (Docker optional) | Restricted local shell, prompts before writes | No dedicated sandbox layer |
| Custom endpoint support | Yes, via OPENAI_BASE_URL | Yes, via ANTHROPIC_BASE_URL | No custom endpoint; auth via Google login, API key, or Vertex AI |
| Best fit | CI-safe, unattended code generation | Multi-file refactors, root-cause debugging | Fast, free exploration of a large repo |
Practical ways to keep the cost down.
APIsRouter is one such gateway: an OpenAI-compatible and Anthropic-compatible API with pay-as-you-go billing and no subscription. Global models are priced 20% below their official list rate, Chinese models sit below their own official rates, the first top-up adds a 100% balance bonus, and the /topup checkout takes payment first and emails the key with no signup form. The table below lines up the models used in the worked example above against their official rate and their price through a gateway like this.
- Match the model to the task. Keep an Opus-tier or top GPT-5 variant for architecture calls and hard bugs, and default routine edits, boilerplate, and test scaffolding to a cheaper model in the same family.
- Cap the loop. Scope a Codex CLI or Claude Code task narrowly instead of turning it loose on the whole repository; a tighter prompt means fewer exploratory calls before it reports back.
- Watch the quota, not just the clock, on Gemini CLI. Heavy multi-file analysis burns through a daily cap fast, and there is no pay-as-you-go fallback inside the free tier.
- Use non-interactive mode deliberately. Claude Code's scripting flag and Codex CLI's sandboxed exec mode are built for CI, but skip the manual approval step, so keep task scope tight specifically there.
- Route routine traffic through a cheaper OpenAI-compatible gateway. Both Codex CLI and Claude Code read their endpoint from an environment variable, so pointing that variable at a lower-cost gateway lowers the per-token rate for the same workflow without touching a single prompt.
| Model ID | Official rate ($ in / out per 1M) | Gateway rate ($ in / out per 1M) | Use it for |
|---|---|---|---|
| gpt-5.3-codex-spark | $1.75 / $14.00 | $1.40 / $11.20 | Sandboxed code generation, Codex-style tasks |
| claude-sonnet-4-6 | $3.00 / $15.00 | $2.40 / $12.00 | Default Claude Code driver, refactors |
| claude-opus-4-7 | $5.00 / $25.00 | $4.00 / $20.00 | Hard debugging, architecture calls |
| gemini-3.5-flash | $1.50 / $9.00 | $1.20 / $7.20 | Metered Gemini access outside the free CLI quota |
| deepseek-v4-pro | $0.435 / $0.87 | $0.3915 / $0.783 | Budget swap for routine edits in either CLI |
Install each CLI, then point it at a cheaper endpoint.
All three tools install the same way, through npm, and each reads its credentials from a different place. Codex CLI reads OPENAI_API_KEY and an optional OPENAI_BASE_URL. Claude Code reads ANTHROPIC_API_KEY and an optional ANTHROPIC_BASE_URL, or the matching fields in ~/.claude/settings.json. Gemini CLI reads neither by default; it authenticates through a Google account login on first launch, or through a GEMINI_API_KEY or Vertex AI credential, but none of those give it a custom base URL. That last point matters for routing. Only Codex CLI and Claude Code can be repointed at a different OpenAI-compatible or Anthropic-compatible endpoint; Gemini CLI cannot. Verify a new key with a single short request before pointing a full day of work at it.
# Codex CLI
npm install -g @openai/codex
export OPENAI_API_KEY="sk-your-openai-key"
# Or point at an OpenAI-compatible endpoint instead of OpenAI directly:
# export OPENAI_API_KEY="sk-APIsRouter-..."
# export OPENAI_BASE_URL="https://api.apisrouter.com/v1"
codex
# Claude Code
npm install -g @anthropic-ai/claude-code
export ANTHROPIC_API_KEY="sk-ant-your-key"
claude
# Gemini CLI (auth is chosen interactively on first launch: Google account, API key, or Vertex AI; no endpoint override)
npm install -g @google/gemini-cli
geminiFAQ
Which is better, Codex CLI, Claude Code, or Gemini CLI?
None wins outright. Claude Code is the strongest at multi-file refactors and tracing a bug across a codebase, Codex CLI has the most locked-down sandbox for unattended or CI use, and Gemini CLI is free within a daily quota and defaults to the largest context window of the three. Pick based on the job, not a single benchmark.
Is Gemini CLI actually free?
For most usage, yes. Signing in with your Google account, the default on first launch, runs Gemini CLI against a daily request quota instead of a metered bill, so there is no invoice to watch. The tradeoff is the cap itself: heavy multi-file analysis can exhaust the daily quota, and the free tier itself has no pay-as-you-go top-up, though you can switch the CLI to a metered GEMINI_API_KEY or Vertex AI credential if you need to keep working past the cap.
Can I point Codex CLI or Claude Code at a different API provider?
Yes. Codex CLI reads its endpoint from OPENAI_BASE_URL and Claude Code reads it from ANTHROPIC_BASE_URL, or the matching field in ~/.claude/settings.json, so either tool can be repointed at any OpenAI-compatible or Anthropic-compatible endpoint without changing how you write prompts. Gemini CLI has no equivalent: none of its auth methods, Google account, API key, or Vertex AI, expose a custom base URL.
Which tool is safest for automated or CI use?
Codex CLI, generally. Its OS-level sandbox isolates file and network access by default, with Docker available as a stricter opt-in, which matters more once no human is watching each command get approved. Claude Code's restricted shell and scripting flag are also usable in CI with tighter task scope. Gemini CLI is built for interactive use and does not ship the same sandbox layer.
What is the cheapest way to run Codex CLI or Claude Code?
Keep the same CLI and swap the endpoint. APIsRouter is an OpenAI-compatible and Anthropic-compatible gateway with pay-as-you-go billing and no subscription: global models are priced 20% below their official list rate, the first top-up adds a 100% balance bonus, and the /topup checkout emails a key with no signup form. Point OPENAI_BASE_URL or ANTHROPIC_BASE_URL at it and the same model IDs run at a lower per-token rate.