AI Coding Token Savings Tested: Code Mode Cuts Usage by 13% on Average
This article tests the token-saving claims of Code Mode, an experimental script-based orchestration feature for AI coding tools, by reproducing a small refactoring task across three runs per mode. It shows an average cost reduction of about 12.5% rather than the advertised 77%, explains why cached-read savings of over 30% translate into much smaller bill reductions due to cache-write pricing, and provides a reproducible testing workflow along with guidance on when this mode actually pays off.
1. The Problem: The Gap Between the Hype and the Real Bill
A new experimental capability has appeared in AI coding tools, often described as “script-based orchestration mode.” The idea is straightforward: instead of making the model perform one action at a time, the model combines multiple steps—reading files, searching code, invoking external commands—into a single executable script. That script is submitted once and runs continuously, reducing the context tokens consumed by repeated round trips between the model and the runtime. Reports cite an upper bound of roughly 77% in token savings.
The number is attractive, but it omits a critical premise: the task scale at which it was measured. Any token-saving percentage is strongly correlated with the “tool-call density” of the task, so a percentage quoted without the task shape is meaningless. A more reliable approach is to fix the same task and the same environment, run multiple comparison rounds, and look at the mean and variance rather than the single best result.
The method used here is hands-on reproduction: a very small refactoring task was selected, each mode was run three times, cost and elapsed time were recorded for every run, and changes in cached-read volume were observed. The final section explains why a 30% reduction in cache reads produces only about a 10% reduction in the bill.
2. Experiment Design: Controlling Variables Matters More Than Chasing Numbers
For a comparison to be meaningful, the variables must be locked down first. At least the following five should be fixed:
- Task: the same refactoring requirement, for example extracting configuration items scattered in the entry file into a standalone module and then re-running the unit tests.
- Project: a small open-source target project with a clear structure and test scripts, avoiding noise from business code.
- Model and parameters: the same model version and the same sampling settings, such as temperature.
- Environment: the same machine, the same terminal, and the same network conditions.
- State: before each round starts, the workspace must be returned to a completely clean state.
The last item is the easiest to overlook and the most damaging. If the previous round left uncommitted changes, the model in the current round will “see” the completed work and effectively do nothing, producing an abnormally low cost and a completely distorted conclusion. So before every round, the state must be rolled back and verified:
git checkout .git clean -fdgit status # must confirm the output is clean, with no leftovers in the workspace
Only after git status shows a clean tree is the next round allowed to start. When restoring a historical session, also make sure the environment variable that enables this experiment is still in effect; otherwise you get a mismatch where you think you are testing the new mode but are actually running the old one.
3. Measured Data: The Real Distribution Across Three Rounds
The three-round results for the lightweight refactoring task are shown below (in USD):
| Round | Standard mode | Script-based orchestration mode |
|---|---|---|
| Round 1 | 0.1813 | 0.1480 |
| Round 2 | 0.1794 | 0.1763 |
| Round 3 | 0.1841 | 0.1516 |
| Mean | 0.1813 | 0.1586 |
The range across the three standard-mode runs was only 0.0047, showing very stable behavior. The orchestration mode had a mean of 0.1586, a relative reduction of about 12.5%, but a range of 0.0283, indicating noticeably larger fluctuation. Elapsed time showed no material difference between the two, with both falling in the 23-to-32-second range.
Conclusion 1: On lightweight tasks, script-based orchestration delivers savings of “a little over ten percent,” not the 70%-plus claimed in reports.
Conclusion 2: Its benefit is unstable and has higher variance, meaning the amount saved depends on how the model splits steps in a given round and is therefore partly random.
4. How It Works: Why Cache Reads Drop 30% but the Bill Drops Only 10%
Looking at cached-read tokens in the backend, the orchestration mode dropped by more than 30% on average. This is the most direct source of benefit: after steps are merged, the repeated system prompt, tool definitions, and historical context are reused fewer times, so repeated reads naturally decline.
But the reduction in the total bill is far smaller, for a reason rooted in the other half of the cost structure—cache writes. Once the context is modified (new tool results are added, reasoning fragments are appended), the cache must be written again, and the write price is typically significantly higher than the read price. The two modes have similar costs on the write side, so a substantial portion of the savings on the read side is offset by the write side.
A simplified cost model makes this clearer:
Total cost ≈ input tokens × input price + cached-read tokens × read price+ cached-write tokens × write price + output tokens × output price
When the task is light and the total token base is small, fixed overhead (system prompt, tool declarations) takes a large share, and any optimization is diluted. When the task requires frequent external tool calls and searches across many files, read volume becomes the dominant term, and the savings ratio is amplified toward the upper bound. This explains the gap between 77% and 13%: it is not fabricated data, but different test scenarios.
5. A Reproducible Procedure
Step 1: Prepare the target. Pick a small project with test scripts, install dependencies, and confirm the baseline tests pass:
git clone <repository-url> target-projectcd target-projectnpm installnpm test
Step 2: Enable the experiment flag (PowerShell example):
$env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = '1'claude
On first entry, confirm the prompt to enable it, then submit the refactoring instruction, for example: “Extract the configuration items in the entry file into a standalone configuration module and keep all tests passing.”
Step 3: Read the numbers and exit. When the task finishes, use the built-in cost query command to check the cost of the current round, then exit the session; immediately roll back the state and move to the next round.
Step 4: Repeat three times and take the mean, while recording elapsed time and cached-read volume, then put the data for both modes in the same table for comparison.
6. Applicability and Engineering Recommendations
Script-based orchestration is not a universal acceleration switch. The criteria for judging whether it helps can be summarized in three points:
- High tool-call density: the biggest gains come when you repeatedly read and write files, execute commands, and search across modules.
- High context-reuse ratio: in long sessions and large repositories, the value of reducing repeated reads is amplified.
- Small task granularity: for light tasks that change a single file and run tests once, fixed overhead dominates, so the benefit is limited and unstable.
Three risks also deserve attention in practice. First, a script is submitted once and executed continuously, so observability degrades when something goes wrong; version control and a clean workspace are essential. Second, cost evaluation should look at both mean and variance; a single result is not enough to support capacity planning. Third, if you want to roll this out within a team, combine cost accounting, log retention, and monitoring alerts, and use container platforms and usage services to run batch experiments, avoiding uncontrolled quota consumption.
7. Conclusion
“Saves 77%” is an upper bound observed in a specific scenario, not a general promise. For developers, what is truly valuable is not repeating the marketing number but mastering a reproducible measurement method: lock the variables, reset the state, average over multiple rounds, and break down the cost structure. Understanding the asymmetric pricing of cache reads and writes lets you predict how much a given optimization will actually save in your own tasks. If an organization wants to run similar evaluations at scale on Baidu AI Cloud, it can build a standardized benchmark pipeline using general capabilities such as container platforms, log services, and monitoring alerts, so that every optimization decision is backed by data.
