Claude Code vs Codex vs OpenCode: Does the Agent Change the Result?

推理时代阅读约 9 分钟
Claude Code vs Codex vs OpenCode: Does the Agent Change the Result?

Claude Code, Codex and OpenCode can run the same model, but they differ in which models they accept, which API protocol they speak and how they bill. In a small, informal AIHubMix test, the same model passed the same task in every agent, while cost and time per run differed: Claude Sonnet 5.5 cost $0.051 per run in Claude Code and $0.100 in Codex. Larger published studies report the same pattern, with success rates a few points apart across harnesses and one model's cost up to about 5x apart.

How do the three agents differ?

Three agents at a glance: Claude Code by Anthropic is closed source, runs Claude only, takes Anthropic Messages endpoints, Claude Pro from $20 a month; Codex by OpenAI has an Apache-2.0 CLI, OpenAI models by default, Responses API endpoints only, CLI from ChatGPT Plus at $20 a month; OpenCode by Anomaly is MIT-licensed, runs any provider, takes Chat Completions, Responses and Messages endpoints, free with an optional $10 Go plan

  • Claude Code includes subagents, skills, hooks, plugins, MCP and a headless mode; the Agent SDK is a separate package. Anthropic's docs say it doesn't support routing to non-Claude models.
  • Codex ships three sandbox modes (read-only, workspace-write and danger-full-access), and its default model is GPT-6.2 Sol. ChatGPT Free and Go include Codex only in the desktop app, with GPT-6 Luna; the CLI and IDE extension start at Plus.
  • OpenCode comes from Anomaly, the team formerly behind SST, and is at version 2.4.3 (npm package @opencode/cli; opencode-ai is the 1.x package). Besides API keys, it accepts a ChatGPT Plus or Pro sign-in.

Prices are from each vendor's pricing page on December 2, 2026.

What happened in the AIHubMix test?

The test was small and informal. On December 2, 2026, each agent had to implement two functions in a small Python repository: parsing and formatting duration strings such as "1h30m". A run passed if the agent left the test files untouched and both the 6 visible tests and 12 hidden tests passed; the hidden tests were added only after the agent finished. Claude Sonnet 5.5 (claude-sonnet-5-5) ran in Claude Code, Codex and OpenCode. GPT-6.2 Sol (gpt-6.2-sol) ran in Codex and OpenCode, since Anthropic doesn't support Claude Code with non-Claude models. Each combination ran three times, each time in a new copy of the repository, with reasoning effort set to high in each agent and models served by AIHubMix. Versions: Claude Code 2.1.333, Codex 0.172.0, OpenCode 2.4.3. The task and scripts are not published.

Cost is estimated from the token counts each agent reported, at the official list prices on the Anthropic and OpenAI pricing pages, which AIHubMix matches: $2 input, $10 output, $0.10 cache read and $2.50 cache write per million tokens for both models. Every run passed, so cost per run is also cost per completed task.

Same model, different agent: all 15 runs passed. Mean cost per run for Claude Sonnet 5.5 was $0.051 in Claude Code, $0.058 in OpenCode and $0.100 in Codex; for GPT-6.2 Sol, $0.084 in OpenCode and $0.101 in Codex. Median times were 17.5, 26.5, 31.8, 88.1 and 112.1 seconds

In this set of runs:

  • All 15 runs passed, so accuracy didn't separate the agents on this task.
  • Sonnet 5.5 cost about twice as much per run in Codex as in Claude Code. Codex runs averaged about 22,000 cached input tokens per run against about 44,000 in Claude Code, which suggests more input was billed at the full rate. Sonnet reached Codex through the Responses API, so the route may account for part of the gap.
  • With GPT-6.2 Sol, OpenCode finished faster than Codex in all three runs (median 88.1 against 112.1 seconds). Its mean cost was also lower ($0.084 against $0.101), though one $0.123 Codex run accounts for most of that gap.
  • The Codex runs with Sonnet reported no reasoning tokens, so the high effort setting may not have reached the model on that route.
  • In Claude Code, the first run also paid to write the cache: $0.069, against about $0.04 for the next two.

One small task with three runs per combination can't show an accuracy gap of a few points. Codex and all GPT-6.2 Sol runs reported zero cache-write tokens, so those costs may be understated. No open model was tested.

What do larger studies report?

  • In HarnessTax, a September 2026 study by UC Berkeley and Arena, 7 models ran in Claude Code, Codex CLI and Pi on 30 SWE-bench Lite tasks and 30 Terminal-Bench 2.0 tasks, three runs per task. The harness moved success rates by about 2 points on average on SWE-bench Lite and about 5 points on Terminal-Bench. On SWE-bench Lite, Claude Code cost about twice as much as Pi; on Terminal-Bench, about 1.5 times. One model's cost varied by up to about 5x across harnesses. In 12 comparisons the model maker's own harness placed first 3 times; with three harnesses, chance alone would give about 4 (computed here, not stated by the study).
  • A June 2026 survey of the Terminal-Bench 2.0 leaderboard found a median gap of 13.6 points between a model's best and worst harness, across 20 models with at least three results. The rows come from different teams with different settings. The benchmark's maintainers found in Benchmarks as Software that longer time limits closed most of a gap of about 20 points between Codex and Terminus 2 on GPT-5.4. Anthropic measured a 6-point swing from container resources alone in its write-up on infrastructure noise, which adds that "leaderboard differences below 3 percentage points deserve skepticism until the eval configuration is documented and matched." After Terminal-Bench 2.1 fixed 28 broken tasks, Claude Code with Opus 4.6 rose from 58.0% to 70.1% in Snorkel's reruns.
  • On the Terminal-Bench 2.1 leaderboard, five models have results both in their vendor's agent and in Terminus 2, the benchmark team's neutral agent. Each pair comes from separate submissions, and the Claude Fable 5 pair ran at different effort levels.

Vendor agent minus Terminus 2 on Terminal-Bench 2.1: Claude Fable 5 plus 3.3, GPT-5.5 plus 5.2, Claude Opus 4.7 plus 2.8, Gemini 3.1 Pro plus 0.2, Gemini 3 Pro minus 8.1 points

In Snorkel's own reruns of agent and model pairs, the gaps were wider, up to 29.2 points for GPT-5.4 mini in Codex over Terminus 2; the maintainers traced most of the Codex gaps to time limits. For OpenCode, the published data is thin: on the Terminal-Bench 2.0 leaderboard, Claude Opus 4.5 scored 52.1% in Claude Code and 51.7% in OpenCode (November 2025).

What changes when a model runs in another vendor's agent?

  • Edit format. Cursor's engineering blog notes that OpenAI's models are trained to edit files with a patch format and Anthropic's with string replacement. Codex is built around the patch format.
  • Reasoning settings. LangChain kept gpt-5.2-codex fixed on Terminal-Bench 2.0 and scored 53.9% at xhigh effort throughout, mostly lost to timeouts, against 63.6% at high. In the AIHubMix test, the Codex runs with Sonnet reported no reasoning tokens.
  • Cost. In the AIHubMix test, Sonnet 5.5 cost $0.100 per run in Codex against $0.051 in Claude Code.

What carries over when you switch?

Item Claude Code Codex OpenCode
Instructions CLAUDE.md, AGENTS.md AGENTS.md AGENTS.md
MCP servers .mcp.json config.toml opencode.json
Hooks settings.json config.toml Via plugins
Protocol Anthropic Responses All three
Plan sign-in Claude ChatGPT ChatGPT

Claude Code reads AGENTS.md from version 2.1.277; when a directory has both files, it reads only CLAUDE.md. OpenCode reads CLAUDE.md in directories without an AGENTS.md. OpenCode's ChatGPT sign-in takes Plus or Pro, and it can use a Claude plan only through its Claude Agent provider, which runs Claude Code on the machine. "All three" means Anthropic Messages, the Responses API and Chat Completions.

  • Instructions written in AGENTS.md are read by all three, subject to the Claude Code rules above.
  • MCP servers and hooks have to be configured again in each tool's format.
  • With a gateway key, Claude Code bills per token instead of drawing on a Claude plan.

How do you connect each agent to one key?

AIHubMix serves Anthropic Messages, the Responses API and Chat Completions on one key. During the test, the prompt in the verification commands below returned OK in all five combinations.

For Claude Code, following the AIHubMix Claude Code guide:

export ANTHROPIC_BASE_URL="https://aihubmix.com"
export ANTHROPIC_AUTH_TOKEN="$AIHUBMIX_API_KEY"
claude -p "Reply with exactly the two letters OK and nothing else. Do not use any tools." --model claude-sonnet-5-5
  • Expected output: OK
  • Common failures: a base URL ending in /v1 (the Anthropic protocol has no /v1; Claude Code adds the path itself), and an env block in ~/.claude/settings.json, which overrides shell variables.

For Codex, in ~/.codex/config.toml, following the AIHubMix Codex guide:

model = "gpt-6.2-sol"
model_provider = "aihubmix"
model_reasoning_effort = "high"

[model_providers.aihubmix]
name = "AIHubMix"
base_url = "https://aihubmix.com/v1"
wire_api = "responses"
env_key = "AIHUBMIX_API_KEY"
  • Verify: codex exec "Reply with exactly the two letters OK and nothing else. Do not use any tools.", expected output OK
  • Common failures: wire_api = "chat", which Codex no longer supports, and profile settings from older Codex versions, which can stop it from starting from version 0.134.0 (the AIHubMix guide shows the current format).

For OpenCode 2.x, in ~/.config/opencode/opencode.json, following OpenCode's provider docs:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "aihubmix-claude": {
      "env": ["AIHUBMIX_API_KEY"],
      "canonical": "anthropic",
      "package": "@opencode/ai/providers/anthropic-compatible",
      "settings": { "baseURL": "https://aihubmix.com/v1" },
      "models": { "claude-sonnet-5-5": {} }
    },
    "aihubmix-openai": {
      "env": ["AIHUBMIX_API_KEY"],
      "canonical": "openai",
      "package": "@opencode/ai/providers/openai-compatible/responses",
      "settings": { "baseURL": "https://aihubmix.com/v1" },
      "models": { "gpt-6.2-sol": {} }
    }
  }
}
  • Verify: opencode run -m aihubmix-claude/claude-sonnet-5-5#high "Reply with exactly the two letters OK and nothing else. Do not use any tools.", expected output OK
  • #high sets the reasoning effort; canonical lets the custom provider inherit the model's settings from OpenCode's built-in catalog.
  • Common failure: following AIHubMix's OpenCode 1.x guide, which says its examples don't apply to version 2. Version 2 uses providers, package and settings.baseURL.

Which other agents fill a similar role?

Agent What it is
Copilot CLI GitHub's agent, custom endpoints supported
Cline, Kilo Code IDE extensions and CLIs, AIHubMix built in
Pi Minimal open-source agent, extensible
Gemini CLI Google's CLI, paid API key or Code Assist
Kimi Code, Qwen Code, Mistral Vibe Model makers' CLIs, several protocols
T3 Code, Orca Apps that run several agents at once

In HarnessTax, Pi cost about half as much as Claude Code on SWE-bench Lite. Several tools changed in 2026: Cursor was renamed Grok Build on November 30, Windsurf became Devin Desktop, Roo Code shut down on May 15, Continue was acquired by Cursor and its repository is read-only, and Gemini CLI stopped serving free and Google AI Pro and Ultra users on June 18.

What are the limits of this comparison?

  • The AIHubMix test is informal: one small task, three runs per combination. Its results hold for this task only, and its costs are estimates from reported tokens, not a bill.
  • Leaderboard rows are submissions from different teams, not controlled experiments, and HarnessTax used 30 tasks per benchmark.
  • Anthropic's docs say Claude Code doesn't support non-Claude models. AIHubMix's Anthropic endpoint can serve other models, but that use is unsupported by Anthropic.
  • Prices and versions are as of December 2, 2026.

FAQ

Is Claude Code better than Codex?
The sources here don't show either one ahead across the board. In the AIHubMix test both passed every run; with Sonnet 5.5, Claude Code was faster and cost less per run. In HarnessTax, accuracy differences between harnesses averaged a few points.

Does a model maker's own agent always get the best results from its model?
No. In the AIHubMix test, GPT-6.2 Sol finished faster in OpenCode than in Codex. In HarnessTax, the maker's own harness placed first in 3 of 12 comparisons.

Can Claude Code run non-Claude models?
Anthropic's docs say this isn't supported. Some gateways, AIHubMix included, serve other models on the Anthropic API, but that setup is outside Anthropic's support.

Does CLAUDE.md still work after moving to OpenCode?
Yes. OpenCode reads CLAUDE.md in any directory without an AGENTS.md. All three agents read AGENTS.md, with Claude Code needing version 2.1.277 or later.

Why does one model score so differently on Terminal-Bench?
Leaderboard submissions differ in prompts, versions, time limits and hardware. The Terminal-Bench maintainers found that a longer time limit closed most of a 20-point harness gap for GPT-5.4.

Do T3 Code or Orca change how well the model codes?
They launch agents such as Claude Code and Codex and change how the work is managed; the companion post covers them.

Keep reading: the coding agents series

Sources

一个网关接入多家 AI 服务商, 为生产环境而生。

访问推理时代官网