Claude Code sends 33k tokens before reading the prompt; OpenCode sends 7k

Claude Code sends 33k tokens before reading the prompt; OpenCode sends 7k

Claude Code 在读取提示词前发送 3.3 万个 Token;OpenCode 仅发送 7 千个

We put Claude Code and OpenCode on the same model, the same machine, and the same tasks, then examined everything sent and received. 我们将 Claude Code 和 OpenCode 放在相同的模型、相同的机器和相同的任务上,然后检查了所有发送和接收的数据。

Claude Code is far hungrier: When we asked both harnesses for a one-line reply, Claude Code used roughly 33,000 tokens of system prompt, tool schemas, and injected scaffolding before the prompt even arrived. OpenCode used about 7,000. Claude Code 的“胃口”大得多:当我们要求两个工具仅回复一行内容时,Claude Code 在提示词到达之前,就消耗了大约 33,000 个 Token 用于系统提示词、工具架构和注入的脚手架代码。而 OpenCode 仅使用了约 7,000 个。

That first test was on Sonnet 4.5. Re-running on Claude Fable 5 narrowed the gap to about 3.3x, because Claude Code sends newer models a much smaller system prompt; still far hungrier, but the multiple is model-dependent. 首次测试是在 Sonnet 4.5 上进行的。在 Claude Fable 5 上重新运行后,差距缩小到了约 3.3 倍,因为 Claude Code 会向较新的模型发送更小的系统提示词;虽然依然消耗更多,但倍数取决于模型。

Claude Code is far more cache inefficient: OpenCode’s request prefix was byte-identical in every run we captured; it paid to cache its payload once per session and read it back for pennies. Claude Code 的缓存效率要低得多:在我们捕获的每一次运行中,OpenCode 的请求前缀在字节上完全相同;它只需在每次会话中缓存一次有效载荷,后续读取只需极低的成本。

Claude Code on the other hand re-wrote tens of thousands of prompt-cache tokens mid-session, run after run, and on the same task wrote up to 54x more cache tokens than OpenCode. 相比之下,Claude Code 在会话期间、在一次次运行中不断重写数以万计的提示词缓存 Token,在同一任务中,它写入的缓存 Token 比 OpenCode 多出 54 倍。

Cache writes of course are billed at a premium, which accounted for the usage dashboard climbing when using Claude Code. 当然,缓存写入的计费价格较高,这就是为什么使用 Claude Code 时使用量仪表板数值会不断攀升的原因。

Config further bloats the prompt: A production repository’s 72KB instruction (AGENTS.md or CLAUDE.md) file adds another (avg) 20,000 tokens to every single request. Five modest MCP servers add 5,000 to 7,000 more. By the time a real working setup sends its first request, it is 75,000 to 85,000 tokens deep before the user has typed a word. 配置进一步加重了提示词负担:生产环境仓库中 72KB 的指令文件(AGENTS.md 或 CLAUDE.md)会为每个请求额外增加(平均)20,000 个 Token。五个适度的 MCP 服务器会再增加 5,000 到 7,000 个。当一个真实的工作环境发送第一个请求时,在用户输入任何内容之前,就已经消耗了 75,000 到 85,000 个 Token。

Subagents add to the cost: A small task that cost 121,000 tokens done directly cost 513,000 tokens when fanned out to two subagents, because every subagent has its own bootstrap cost, and the parent then consumes its transcript. 子代理增加了成本:一个直接执行仅需 121,000 个 Token 的小任务,在分发给两个子代理执行时,成本飙升至 513,000 个 Token,因为每个子代理都有自己的引导成本,且父代理随后还要消耗其转录内容。

We found one result in favour of Claude Code: On a multi-step task Claude Code’s whole-task total came out lower than OpenCode’s, because it batches tool calls into fewer requests while OpenCode re-pays its smaller baseline turn after turn. The meter starts higher; how the session unfolds decides who spends more. 我们发现了一个 Claude Code 的优势:在多步骤任务中,Claude Code 的任务总消耗量低于 OpenCode,因为它将工具调用批量处理为更少的请求,而 OpenCode 则在每一轮中重复支付其较小的基准成本。虽然 Claude Code 的起步成本更高,但会话的展开方式决定了谁最终花费更多。

The rest of this post shows how we measured all of this at the API boundary, where the tokens go, and what prompt caching does and does not save you. 本文的其余部分将展示我们如何在 API 边界测量这一切、Token 的去向,以及提示词缓存能为你节省什么、不能节省什么。

Why measure this at all

为什么要进行测量?

Token overhead is cost, latency, and context budget. Every token of harness payload is a token of working context you cannot spend on code, and the baseline is re-sent, or re-read from cache, on every single turn. Token 开销意味着成本、延迟和上下文预算。工具载荷中的每一个 Token 都是你无法用于代码编写的工作上下文,且基准数据在每一轮中都会被重新发送或从缓存中重新读取。

If you operate agentic AI in production, particularly under the EU AI Act where Article 12 expects you to log and understand your system’s behaviour, “what does my agent actually send” is a question you should be able to answer with data rather than folklore. 如果你在生产环境中运行代理 AI,特别是在欧盟《人工智能法案》(EU AI Act)第 12 条要求你记录并理解系统行为的情况下,“我的代理到底发送了什么”是一个你应该能够用数据而非传言来回答的问题。

Method

方法

We spliced a logging proxy between each harness and the model endpoint. 我们在每个工具和模型端点之间接入了一个日志代理。

harness (Claude Code / OpenCode) → logging proxy (captures request payloads + response usage) → model endpoint 工具 (Claude Code / OpenCode) → 日志代理(捕获请求载荷 + 响应使用情况) → 模型端点

The proxy records two things per request. The first is the exact JSON payload the harness emitted, meaning the system blocks, tool schemas, and messages. The second is the usage block the API returned, covering input tokens, cache writes, cache reads, and output tokens. 代理为每个请求记录两件事。第一是工具发出的确切 JSON 载荷,即系统块、工具架构和消息。第二是 API 返回的使用情况块,涵盖输入 Token、缓存写入、缓存读取和输出 Token。

The payload capture is ground truth for what the harness sends. The usage block is ground truth for what was metered. 载荷捕获是工具发送内容的真实依据。使用情况块是计费的真实依据。

We tested under these conditions. 我们在以下条件下进行了测试。

Harnesses. Claude Code 2.1.207 and OpenCode 1.17.18, both pinned to claude-sonnet-4-5, July 2026. A reduced matrix (the floor, the cache task, and the multi-step task) was later re-run pinned to claude-fable-5; where the model changed the result, we say so inline. 工具: Claude Code 2.1.207 和 OpenCode 1.17.18,均固定使用 2026 年 7 月版的 claude-sonnet-4-5。随后在 claude-fable-5 上重新运行了一个精简矩阵(基准、缓存任务和多步骤任务);如果模型改变了结果,我们会在文中说明。

Baseline isolation. Fresh config directories with no MCP servers, no user settings, and no memory; an empty workspace with no instruction files; permissions bypassed. Multiplier lanes then add one variable at a time. 基准隔离: 使用全新的配置目录,不含 MCP 服务器、用户设置和记忆;使用不含指令文件的空工作区;绕过权限限制。随后在乘数路径中一次添加一个变量。

Tasks. T1 says “Reply with exactly: OK” and isolates fixed overhead (three runs per harness). T2 reads a seeded file and summarises it. T3 is a write-run-test-fix loop against FizzBuzz plus a checker script. 任务: T1 要求“仅回复:OK”,用于隔离固定开销(每个工具运行三次)。T2 读取一个预设文件并进行总结。T3 是针对 FizzBuzz 的“编写-运行-测试-修复”循环,外加一个检查脚本。

Zero-tools variant. Claude Code with —tools "" and OpenCode with “tools”: {”*”: false}, separating system prompt from tool schema weight. 无工具变体: Claude Code 使用 --tools "",OpenCode 使用 "tools": {"*": false},将系统提示词与工具架构权重分离开来。

One honesty note before the numbers. Our traffic passes through a local LLM gateway that wraps requests in its own envelope, a constant we measured at roughly 6,200 tokens with bare calibration requests and subtracted from every metered figure below. Payload-level figures come from the captured request bodies, which the gateway cannot affect, and are exact. 在列出数据前说明一点:我们的流量通过一个本地 LLM 网关,该网关会将请求封装在自己的信封中。我们通过简单的校准请求测得该常量约为 6,200 个 Token,并已从下方的所有计费数据中扣除。载荷层面的数据来自捕获的请求体,网关无法影响这些数据,因此它们是精确的。

Character-to-token conversion for component estimates uses each harness’s own measured ratio of 4.1 to 4.4 characters per token, derived from cold-cache anchors where the metered write equals the full payload, rather than a generic heuristic. 组件估算的字符到 Token 转换使用了每个工具自身测得的 4.1 到 4.4 字符/Token 的比例,该比例源自冷缓存锚点(此时计费写入等于完整载荷),而非通用的启发式算法。

Part I. The floor

第一部分:基准线

The fixed overhead of saying OK 回复 OK 的固定开销

The task was 22 characters. Here is what each harness sent with it on its first request. 任务内容为 22 个字符。以下是每个工具在第一次请求时发送的内容。

ComponentClaude CodeOpenCode
System prompt27,344 chars, 3 blocks9,324 chars, 1 block
Tool schemas27 tools, 99,778 chars10 tools, 20,856 chars
First-message scaffolding7,997 chars of blocksnone
The actual prompt22 chars22 chars
First-turn payload (calibrated)~32,800 tokens~6,900 tokens

OpenCode’s request is close to minimal. There is one system block that opens with “You are OpenCode, the best coding agent on the planet”, ten classic coding tools, and your prompt as the only user content. OpenCode 的请求接近最小化。它包含一个以“你是 OpenCode,地球上最好的编码代理”开头的系统块、十个经典的编码工具,以及作为唯一用户内容的提示词。

Claude Code’s request is a platform bootstrap. The 27 tools include the coding core plus an entire background-agent and orchestration suite, from CronCreate and Monitor to the Task family, worktree management, and push notifications. Claude Code 的请求是一个平台引导程序。其 27 个工具不仅包含编码核心,还包含一整套后台代理和编排套件,从 CronCreate 和 Monitor 到 Task 系列、工作树管理和推送通知。

Before your prompt, its first user message carries three injected reminder blocks; a catalogue of agent types for delegation, a catalogue of available skills, and user context. 在你的提示词之前,它的第一条用户消息携带了三个注入的提醒块:用于委派的代理类型目录、可用技能目录以及用户上下文。

Tool schemas are the dominant term for both. Roughly 24,000 of Claude Code’s ~33,000 tokens are tool definitions, versus roughly 4,800 of OpenCode’s ~6,900. 工具架构是两者消耗的主要部分。Claude Code 约 33,000 个 Token 中约有 24,000 个是工具定义,而 OpenCode 的 6,900 个中约有 4,800 个。

Zero tools, pure harness 无工具,纯工具载荷

Stripping the tools isolates the system prompt itself. Claude Code’s weighs in at 26,891 chars, about 6.5k tokens. OpenCode’s is 8,811 chars, ab… 剥离工具后可以隔离出系统提示词本身。Claude Code 的系统提示词为 26,891 个字符,约 6.5k 个 Token。OpenCode 的为 8,811 个字符,约…