Does Code Mode save tokens without hurting the results?
Yes on cost, and no difference in results that this experiment could detect: across 48 Sonnet 5.5 sessions on eight data-science tasks, Code Mode in Claude Code cost 34% less and scored the same.
- Code Mode cost $3.75 against $5.71 for the same 24 task runs, with 21% fewer output tokens and 16% fewer API requests. measured
- About 90% of the saving is input-side: a Code Mode request starts from roughly 27,600 tokens of prompt and tool definitions against 42,600, and that gap is paid on every request. Batching tool calls mattered much less. computed
- Every task was solved by both modes, so quality sits at the ceiling. n is 3 per cell, one model, tasks under four minutes.
The whole picture
Code Mode was cheaper on all eight tasks
The ratio is steady: Code Mode cost between 0.55× and 0.79× of plain on every task, 0.66× overall measured. The first five tasks are short single-script jobs; the last three (repair, tables, logs) were built to need more steps, and the gap did not widen.
Nine-tenths of the saving is a smaller prompt, paid on every request
The first request of a plain session carried 42,626 tokens of context; in Code Mode it carried 27,567 measured. Every later request re-reads that. Two things in the transcripts account for the gap measured: the logged system prompt plus tool definitions is 134,072 characters plain and 72,454 in Code Mode, and the plain session is also sent the list of this machine's connector tools on its second and third requests (36,434 and 11,608 characters), which the Code Mode transcript never receives. So the gap grows to about 25,000 tokens by request 2.
How the split is computed
# per arm, summed over 24 runs plain code mode
cache_write 926,103 617,342
cache_read 8,756,086 4,056,331
output 89,611 70,854
saving = 1.25*(926103-617342) + 0.1*(8756086-4056331) + 5*(89611-70854)
= 385,951 (write) + 469,976 (read) + 93,785 (output) = 949,712 units
shares = 41% write, 49% read, 10% output
The same repair task took six requests plain and four in Code Mode
pipeline_repair, both 21/21 on the hidden tests · click a step, or use the buttons or arrow keysThe plain session was not naive. It batched too, with a shell loop to read every file and one Python heredoc to apply every fix. That is why the request counts are close (6 and 4) and why batching explains so little of the saving on these tasks.
Worked example: the two repair sessions, request by request
pipeline_repair, plain run 1 and Code Mode run 2| Request | Plain: write | read | output | Code Mode: write | read | output |
|---|---|---|---|---|---|---|
| 1 | 15,203 | 27,435 | 158 | 14,861 | 12,716 | 178 |
| 2 | 14,363 | 42,638 | 200 | 4,208 | 27,577 | 252 |
| 3 | 4,114 | 57,001 | 218 | 3,605 | 31,785 | 1,429 |
| 4 | 2,534 | 61,115 | 793 | 1,761 | 35,390 | 634 |
| 5 | 1,014 | 63,649 | 1,072 | |||
| 6 | 1,210 | 64,663 | 739 | |||
| Total | 38,438 | 316,501 | 3,180 | 24,435 | 107,468 | 2,493 |
plain = 1.25*38,438 + 0.1*316,501 + 5*3,180 = 48,048 + 31,650 + 15,900 = 95,598 units
code mode = 1.25*24,435 + 0.1*107,468 + 5*2,493 = 30,544 + 10,747 + 12,465 = 53,756 units
ratio = 0.56 CLI's own dollar estimate: $0.141 / $0.228 = 0.62
Note request 3 in Code Mode: 1,429 output tokens, the single script that makes every fix. The plain session spreads the equivalent across requests 4 and 5.
What this predicts for longer tasks
The model
# P = starting prompt, g = tokens added per request, o = 550 output tokens per request, N = requests
# w0 = tokens written to the cache on request 1 (15,200 plain, 14,900 Code Mode; the rest was already cached)
# late = connector tool lists the plain session receives on requests 2 and 3 (about 10,100 and 3,200 tokens,
# my estimate from their character counts); zero in Code Mode
context(k) = P + late arrived by k + (k-1)*g
cost(N) = 0.1 * sum over k = 1..N of context(k) # every request reads the context
+ 1.25 * (w0 + late + (N-1)*g) # new material is written to the cache once
+ 5 * o * N
ratio(N) = cost_code(N_code) / cost_plain(N)
# "same requests": N_code = N "23% fewer": N_code = 0.77*N, as measured in round two
Both modes scored the same, because both solved everything
| Task | Scored by | Plain | Code Mode | Requests, plain | Code Mode |
|---|
Mean scores: 0.961 plain, 0.962 Code Mode (n = 24 each). With six of eight tasks at exactly 1.0 in every run, this measures cost at equal quality; it cannot rank the modes on quality.
Typical time was the same; the slow runs were stalls, in both modes
The stalls I traced came from running unattended, not from the modes. In Code Mode a file write inside the script waited on a permission prompt nobody could answer, which froze the whole script until the limit; allowing writes outright in round two removed it. In plain mode a shell command hung and was moved to the background. I traced one stall of each kind and confirmed the timeout message in three more plain runs.
What's uncertain
- Quality is untested. Sonnet 5.5 solved every task both ways. A real comparison needs tasks it sometimes fails, or a weaker model. First check: rerun with Haiku 5.5.
- n = 3 per cell. The cost gap is far larger than the run-to-run spread, so its direction is safe; the exact percentages are not.
- The prompt gap depends on this machine. It has many plugins and connectors loaded, and part of the gap is their tool list. On a lean install the gap, and so most of the saving, should be smaller. First check: rerun with plugins and connectors disabled and compare the context of requests 1 and 2.
- I compared prompt sizes, not prompt contents. The character counts show Code Mode's prompt and tool definitions are about half the size; I did not diff what was removed.
- The token weights are approximate. The 1.25 / 0.1 / 5 weights give 0.62 overall where the CLI's dollar estimate gives 0.66, so the CLI prices something slightly differently. The split by kind of token uses the weights.
- Short tasks. The longest clean session was about a minute. The docs pitch Code Mode for long jobs with many dependent calls; the model above is a guess at that regime, not a measurement.
- Cache state carries between sessions. Sessions ran back to back, so each first request read part of its prompt from a cache warmed by earlier runs. Alternating arm order does not remove that.
Sources
- Run tool calls from code with Code Mode, Claude Code docs. What Code Mode is, how to turn it on, the ten-minute limit, and that it runs only in the interactive terminal.
results.csv, the experiment's own results file: one row per session with score, requests, tool calls, tokens by kind, CLI cost and duration. Every chart of measured data on this page is drawn from it.make_tasks.py,make_tasks2.py: the task generators and what each hidden truth is.run.sh,drive.exp,score.py: the driver, and the grading and token accounting.- The two
pipeline_repairsession transcripts (plain run 1, Code Mode run 2): the sequence diagram, the per-request table and the prompt sizes.
The harness, task generators and results file are not published. Every session's numbers are in the table under the first chart (“All 48 sessions”).