Measured it: headless Claude Code (Agent SDK / claude -p) eats ~3x more of the 5-hour limit per token than interactive use (vscode)

TL;DR: I ran the same coding task six times through four ways of running Claude Code, with the same model and effort, and checked /usage before and after each run. Interactive use (VS Code extension, terminal CLI) cost about 1.7% of the 5-hour limit per $1 of API-equivalent tokens. Headless use (Python Agent SDK, claude -p ) cost about 5.2% per $1 . Same tokens, roughly 3x more of the limit. I couldn't find this documented anywhere. Why I tested it I run some coding tasks headless through the Agent SDK in a container, and I kept noticing that one mid-sized headless task ate a big chunk of my 5-hour window. The same kind of work in VS Code felt far cheaper. At first I assumed the headless agent was just burning more tokens, so I measured. Setup Claude Code Pro Task: a medium refactor in a Python monorepo. Add an optional field to a shared protocol model, handle it on several failure paths in a worker, update the docs, and write tests across three packages. Roughly 45–75 model calls per run. Same starting point: the same commit every time, each run in a fresh git worktree. Model: Opus 5, effort medium , standard tier, no fast mode. I checked this in the transcripts for every run. Flow: "study the repo and propose a plan" → "plan approved, implement, run tests, commit". The claude -p run got a single prompt covering both. Nothing else on the account during the runs: no claude.ai , no other sessions. Measurement: /usage right before and right after each run, then again 10–20 minutes later to catch any delayed accounting. There was none. Cost: computed from the per-message usage in the session JSONL transcripts at API list prices. It matched Claude Code's own cost tracking to the cent. Results Mode Entrypoint (from transcript) Steps Max context API-equiv. cost 5h usage % of limit per $1 VS Code extension, run A claude-vscode 56 119k $4.01 +7% 1.7 VS Code extension, run B claude-vscode 76 144k $5.66 +9% 1.6 Interactive CLI in terminal cli 63 119k $4.38 +8% 1.8 Python Agent SDK, run A sdk-py 54 81k $2.88 +15% 5.2 Python Agent SDK, run B sdk-py 61 98k $3.44 +18% 5.2 claude -p sdk-cli 44 84k $2.53 +13–14% 5.1–5.5 What stands out The headless runs used fewer tokens than the interactive ones: smaller context, fewer steps, cheaper at API prices. They still took about 2x the limit per run, which works out to about 3x per token. The ratio held steady: 5.2% per $1 in both SDK runs, 1.6–1.8% across all three interactive runs. It isn't VS Code vs. terminal. The interactive CLI landed right next to VS Code. The split is interactive vs. headless. It isn't a custom system prompt or odd SDK settings. claude -p on the same machine, with the same CLI version as the VS Code extension and the default system prompt, gave the same ~3x number as the SDK. Practical takeaway With these numbers, a headless task costing about $18 at API prices takes roughly 90% of a 5-hour window. The same amount of work done interactively takes about 30%. If you run agents headless on a subscription, budget for that. Caveats It's a small sample: six runs, one task, one model, one account ([Pro]). /usage shows whole percentages, so each reading is ±1%. I don't know which signal the accounting actually uses: the entrypoint, request patterns, or something else.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论