Experiment · 18 November 2026

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.

Bottom line

The whole picture

One task, run twice: the only thing that differs is one environment variable
Click a box for what it does. Blue is the plain arm and orange is Code Mode, here and in every chart below.
8 taskswith hidden truth driverexpect → real TUI plain sessionRead, Bash, Edit … Code Mode sessionREPL runs JavaScript run foldertask outputstranscriptusage per request graderscore 0–1 token tallyrequests, $
Click a box to see what it does.
Read it as: a paired design. Same task files, prompt, model (Sonnet 5.5, medium effort), CLI version (2.1.327) and permissions; three repetitions per cell, with the arm that goes first alternating by repetition. Solid boxes are processes, the dashed box is stored output.

Code Mode was cheaper on all eight tasks

Cost of each of the 48 sessions, by task
US dollars per session, from the CLI's own estimate at list prices · n = 3 per task and arm · lower is better
Read it as: the orange cluster sits below the blue one in every column, and the two almost never overlap. The one high orange dot (logs, $0.32) is a run that read 145 folders one file at a time from inside its script. Hover a dot for the run.

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

Where the saving came from, by kind of token
Share of the total saving in price-weighted tokens, all 48 runs · weights relative to one uncached input token: cache write 1.25, cache read 0.1, output 5
Read it as: output tokens, which is where "write one script instead of many calls" would show up, are a tenth of the saving. The rest is context: less written to the cache and less read back from it.

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.

Cost against number of API requests, one dot per session
US dollars per session · all 48 runs
Read it as: two parallel bands. At the same number of requests a Code Mode session costs about 7 cents less; moving left along a band (fewer requests) saves much less than dropping from the blue band to the orange one.
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

Repairing a seven-module pipeline with twelve bugs: who does what
Two real sessions on pipeline_repair, both 21/21 on the hidden tests · click a step, or use the buttons or arrow keys
Read it as: in the plain session every arrow leaving Claude is a separate API request. In Code Mode the third script is the difference: eleven file operations and a test run happen inside it, and Claude sees only what the script returns.

The 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

Context sent with each request
Tokens of input (uncached + cache write + cache read) per API request · pipeline_repair, plain run 1 and Code Mode run 2
Read it as: the two lines start 15,000 tokens apart and the gap widens to 25,000 at request 2, when the plain session is sent the connector tool list. The plain session then pays for its taller context two more times.
RequestPlain: writereadoutputCode Mode: writereadoutput
115,20327,43515814,86112,716178
214,36342,6382004,20827,577252
34,11457,0012183,60531,7851,429
42,53461,1157931,76135,390634
51,01463,6491,072
61,21064,663739
Total38,438316,5013,18024,435107,4682,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

Predicted cost ratio as a session gets longer
Illustrative model, not data: starting prompts as measured (42,626 and 27,567 tokens), 550 output tokens per request, context growing by a fixed amount per request · black dots are the eight measured tasks
2,500tokens
Read it as: at the default, the same-requests line starts near 0.6 for a short session and drifts to about 0.8 by 40 requests, as accumulated context dilutes the prompt gap. Push the slider up (large file reads, long logs in context) and it climbs toward 1 much sooner; only cutting requests keeps Code Mode well ahead.
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

TaskScored byPlainCode ModeRequests, plainCode Mode
The one task with a trap: churn from three raw tables
ROC AUC on 2,000 held-out customers, one dot per session · axis starts at 0.68, not zero · higher is better
Read it as: all six sessions land just under the leak-free reference and far above where a model that uses post-cutoff rows ends up. Neither mode fell for the leak, and the spread within a mode is as large as the gap between them.

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

Duration of each session, by task
Seconds from first to last transcript record, log scale · n = 3 per task and arm
Read it as: most dots sit between 14 and 60 seconds in both colours (medians 27.5 s plain, 26 s Code Mode). The three orange dots near 620 s hit Code Mode's ten-minute limit on running code; the blue dots near 150 s are a shell command hitting its 120-second timeout.

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

Sources

  1. 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.
  2. 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.
  3. make_tasks.py, make_tasks2.py: the task generators and what each hidden truth is.
  4. run.sh, drive.exp, score.py: the driver, and the grading and token accounting.
  5. The two pipeline_repair session 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”).