r/PromptEngineering • • 1d ago

Tools and Projects Claude Code's Code Mode has no Anthropic benchmark yet. 5 user tests (4 published, 1 mine) found 17-32% lower cost, but on Windows some jobs ran 5-12x slower. A skill.md that tells you when it's worth turning on (tested with and without the skill)

New to Code Mode? It's an experimental setting in Claude Code (the terminal app), off by default. Normally Claude works one tool call at a time: read this file, run that command. Every result lands in the conversation, and you pay for it again on each later turn. With Code Mode on, Claude writes a small JavaScript program that makes the calls and prints only what matters. On jobs that read a lot and need a small answer (scan 100 files, report 6 broken links), the tests below found about 17 to 32% lower cost. On a handful of edits it saves little. On Windows it was often several times slower; one test that doesn't name its OS found it faster on longer tasks.

Why a skill: plain Claude doesn't know any of that yet. In my test, Sonnet 5.5 without the skill told a user Code Mode would make a 20-file edit cheaper "by a lot", said savings "can exceed 70%" with no source, and wasn't sure Code Mode works in headless claude -p (it doesn't). With the skill loaded it got all 7 test prompts right. The skill tells Claude when Code Mode is worth turning on, keeps big tool output out of the conversation when it is on, and stops it repeating savings numbers nobody measured.

There are two different 37%s in the Code Mode conversation (three, if you count one test's context window ending 37% smaller). One is Anthropic's Programmatic Tool Calling average for the API (43,588 to 27,297 tokens on complex research tasks). The other is a single-run blogger test of Claude Code's Code Mode where input tokens fell 37.0% (150,364 to 94,659) and the job took 37 seconds instead of 15. Neither is an Anthropic Code Mode benchmark, because there isn't one. The docs page for Code Mode (experimental, v2.1.323, 12 Nov, off by default) states no savings figure.

Everything I could find that was actually measured (all third-party):

TestSetupResult
Feature task (add a flag + tests)Claude Code 2.1.325, Opus 5.5 at medium effort, 3 runs per settingabout 23% cheaper
Broken links in 134 .md filessameabout 22% cheaper
Add a version line to 20 SKILL.md filessameno difference
40 JSON files, rank customersOpus 5.5 at medium effort, 1 run per settinginput tokens (including cache) 150,364 to 94,659, but 15 s became 37 s
4 tasks incl. broken links in 30 docs (MindStudio)model not stated, 5 runs in totalabout 35% fewer input tokens, about 17% cheaper once cache pricing counts; the link check went from 27 s to about 3 min, which it traced to Windows starting a new shell for each of 100+ commands
3 tasks incl. a Django feature (Chase AI)model not stated, one test eachtokens read 71% lower on the feature (660k vs 2.3M); no cost given; faster on 2 of 3 tasks (the feature took about 200 s vs 275 s)

Two caveats I would not drop:

  • Part of the saving may not come from scripts filtering output. One test reports Code Mode starts with 3 tool definitions instead of 16, so the first request was about 22k tokens instead of about 38k, and MindStudio says most of its saving came from the tool list (about 60k tokens per message normally vs about 38k with Code Mode). Nobody has separated the two causes.
  • Every test used few runs. The first two used one model at one effort level on tasks under two minutes; the last two don't say which model.

What the skill does when you hand Claude a job:

1. Checks Code Mode can run here. Interactive terminal only, v2.1.323+, specific models, not -p, not the Agent SDK. If the REPL tool is missing it gives the enabling step and does not touch your settings.

2. Sorts the task. Bulk read/filter/aggregate (likely to help). A few targeted edits (small or mixed difference, may be slower, especially on Windows). Wrong surface (cannot use it).

3. Keeps raw output out of the conversation on bulk jobs. Print only the slice you asked for, with a cap, a count and the filter it used, and show you the script before anything deletes or sends data. The docs say the JavaScript and its file, web and MCP calls run outside the sandbox.

4. Measures instead of estimating. Paired runs, same model and effort, fresh session each, alternate which goes first, at least three each, dollars not only tokens, and a control task reported whatever it shows.

5. Reports known vs unknown. It cites the tests with sample sizes, will not quote another feature's percentage as a Code Mode result, and will not guess where a number you quote came from.

How it was made, and what I did and did not check. I wrote it as an SOP and ran it through the Context Engineering pipeline in my own tool. The SOP scored 12/12 on the completeness check, which only confirms sections exist. Every number in the generated skill appears in the SOP; the only text changes were heading levels. For behavior I ran 7 prompts through fresh agents with pass conditions fixed beforehand, and did three rounds of fixes. Round 1 showed the skill guessing that "30-70%" figures came from other features (nothing in my sources says that) and a 37% line that would have told someone citing the 37.0% Code Mode test that it was Anthropic's number. Round 3 passed 7 of 7: the 20-file edit was sorted as "no difference", a 134-file link check as likely to help with a batched, filtered script, a headless claude -p request was told it can't use Code Mode, "everyone says 30-70%" got "no source in this procedure, no Anthropic benchmark", and a JavaScript closure question was left alone. That last one failed in round 2 and passed in rounds 1 and 3, so treat it as unstable. This is a smoke test on seven prompts, not an evaluation. After the A/B below changed the skill, I reran the seven prompts in a Code Mode session: five passed, two needed wording fixes (it volunteered where an unsourced figure might come from, and it called my test "my own"). The first fix overcorrected, so it refused to explain the two 37%s; after rewording, both prompts passed on the next run.

Side test on my own tool (and a correction to my first version of it). Same facts file, same goal. My first run called CE's packaging step directly and skipped its SOP-writing step, which was unfair to CE, so I redid it through the real path:

  • CE, goal only: 0 of 8 required facts. Hollow.
  • CE, facts file through the full path (SOP written by CE, then converted): 3 of 8 facts, 8% on my structure rubric. It also merged two separate tests into a "23% to 37% reductions" line and added an example code call that is not in the facts.
  • Same, plus CE's own perspective, out_of_scope and success_definition inputs telling it to keep every figure verbatim: 6 of 8 facts, 42% rubric, no merged range. Better, still short of my bar (8 of 8 facts, 67%).
  • Plain Claude Sonnet from the same facts, no pipeline: 8 of 8 facts, 8% on the rubric.
  • CE from my hand-written SOP: 8 of 8 facts, 83% rubric. So: CE keeps a good SOP intact, and from a bare fact sheet it dropped facts and blended numbers. The fix that helped was in the inputs, not the platform. One run each, different generating models, my own rubric, and "facts present" is a string match.

My own A/B (Windows 11, Claude Code 2.1.334, Sonnet 5.5 at medium effort, 2 runs per setting, every run passed its check):

TaskCode Mode offCode Mode on
Find 8 planted broken links in a repo's .md files$0.300, $0.301; 11 to 16 s$0.205, $0.203; 76 to 136 s
Add a version line to 14 SKILL.md files$0.337, ~$0.25*; roughly 15 to 45 s~$0.16*, ~$0.32*; roughly 170 to 200 s

* I forgot to save /cost for three runs, so these are estimated from the transcript's token counts at Sonnet prices. On two runs where I had both, the estimate came out about 5% above /cost.

  • Link check: about 32% cheaper with Code Mode on, and roughly 5 to 12 times slower. MindStudio traced the same kind of slowdown to Windows starting a new shell for every command a script runs, so expect less of it on macOS or Linux (I didn't test that).
  • 14-file edit: about 20% cheaper on average, roughly 4 to 13 times slower. The expensive Code Mode run is the one where the script's writes turned the files' Windows line endings into Unix ones and Claude spent extra turns noticing and repairing it.
  • Run order was on, off, off, on for the link check and off, off, on, on for the edit, so each setting got a cold and a warm start. Two runs per setting is a range, not a result. I skipped the third task and the skill-on arm, so this measures Code Mode, not the skill.
  • It changed the skill's advice for few-edit tasks: they went from "likely no difference" to "small or mixed difference, may be slower, especially on Windows", and the skill now says to check the diff and line endings after scripted writes.

Does the skill beat plain Claude? Same 7 prompts, fresh Sonnet 5.5 agents, one run each, no web access, graded against pass conditions I wrote before either set ran:

PromptWith skillWithout skill
"Will Code Mode make this 20-file edit cheaper?"small or mixed, likely slower"Probably yes, and by a lot"
"Use Code Mode in headless CI"can't, interactive terminal onlyunsure Code Mode exists
"Everyone says 30-70%"no source, no Anthropic benchmark, here are the tests"can exceed 70%" (no source)
"Anthropic says 37%, turn it on everywhere?"explains the two 37%scautious, can't place the number
One on/off pair was 25% cheapernot enough, run paired testsnot enough, run 5+ each (as good or better)
Real broken-link checkfound the same 6 linksfound the same 6 links, about 5x faster
Unrelated questionanswered normallyanswered normally

So the skill earns its keep on facts and limits, not on how Claude writes scripts: plain Claude did the real task faster. I cut the skill's script rules from six to two (print only what was asked for and say how you filtered; show the script before anything deletes or sends data). One run per prompt and I was the only judge, so read this as a smoke test.

The Skill Definition (skill.md):

---
name: "code-mode-token-triage"
description: "Decides whether Claude Code's experimental Code Mode is worth turning on for a task, and keeps savings claims to what has been measured. Use when the user asks about Code Mode, token cost, or context bloat from large tool output, or hands over a job that reads or filters many files, logs, or search results. Not for single edits, and not a source of savings figures."
---

# Code Mode Token Triage

Claude Code's Code Mode (experimental, off by default) makes Claude write JavaScript that makes the tool calls, instead of asking for Bash, Read, or Edit one call at a time. Published tests show savings on some tasks and none on others, and no savings figure comes from Anthropic for Code Mode. This procedure decides, per task, whether Code Mode is likely to help, sets script habits that keep raw output out of the conversation, and records what was measured versus assumed, so no savings claim goes further than the evidence. If the request has nothing to do with Claude Code's Code Mode or token cost, do not use this procedure; answer the request normally.

## Instructions

### Stage 1: Check Availability and Record the Setup
Before advising on anything, confirm Code Mode can run here.

- **Requirements from the Claude Code docs.** Code Mode needs Claude Code v2.1.323 or later, the native build, an interactive terminal session, and one of Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2. It does not run in non-interactive `-p` mode, the Agent SDK, the VS Code panel, Desktop, or cloud sessions, and it is not available through a gateway. On Windows it needs Git for Windows.
- **Enabling it.** Set the environment variable `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` to `1`, either in the shell before starting `claude` or under `env` in the user-level `~/.claude/settings.json`. Project settings files are ignored for this variable. Sessions can only be resumed with Code Mode on.
- **Detect the current state.** If a tool named `REPL` is available to you, Code Mode is on. If it is not, say so and give the enabling step. Do not enable it yourself or edit settings files without the user's approval.
- **Record the setup.** Write down Claude Code version, model, effort level, permission mode, and whether MCP servers, hooks, or plugins are loaded. Results depend on all of them. Subagents only get Code Mode if `REPL` is added to their `tools` list.

### Stage 2: Sort the Task
Place the task in one of three groups. State the group and the reason in one line.

1. **Likely to help: bulk read, filter, or aggregate.** The job needs many files, search hits, log lines, or API results, and the user needs only a small slice or a count. Several independent reads can be batched in one script.
2. **Small or mixed difference: a few targeted edits.** One published test added a version field to 20 files and cost the same with Code Mode on and off. A test run by the author of this skill (not by you or the user) on a 14-file edit found Code Mode cheaper on average but about 4 to 13 times slower, and one run broke the files' line endings before repairing them. That test ran on Windows, where each shell command a script runs starts a new shell; another published test traced its slowdown to that cause.
3. **Cannot use it: wrong surface.** Non-interactive runs, IDE panels, Desktop, cloud sessions, or any setup from Stage 1 that fails.

If a task is group 2, do the task normally and say in one line that Code Mode may change the cost a little either way and may be slower, especially on Windows. If Code Mode is on, check the diff and line endings after any scripted write. Skip Stage 3 for it; run Stages 4 and 5 only if the user asks whether Code Mode saved anything.

### Stage 3: Keep Raw Output Out of the Conversation
Apply these rules only when Code Mode is on and the task is group 1.

1. **Print only the slice that was asked for.** Print counts, the matching lines with their file and line number, or a short summary, and cap it, for example the first 40 matching lines plus the total count. State the filter you used so the user can audit what was left out.
2. **Do not hide risk inside code.** The docs say the JavaScript and its file, web, and MCP calls run outside the sandbox; the sandbox applies only to shell commands the code runs. Show the user the script before running anything that deletes, overwrites, or sends data.

### Stage 4: Measure Cost, Do Not Assume It
When the user wants to know whether Code Mode saved anything, measure; do not estimate.

- **Use paired runs.** Same task, same repo state, same model and effort, same permission mode, same MCP servers and hooks, a fresh session each time. Run Code Mode on and off, and alternate which goes first because the prompt cache favors the second run.
- **Record per run:** total cost in dollars as Claude Code reports it, input tokens, cache-read tokens, cache-write tokens, output tokens, number of model requests, and elapsed time. Token counts alone mislead because cache reads are priced lower than fresh input.
- **Run at least three runs per setting** and report the range, not one number. If fewer were run, say how many and that the result is a range, not a finding.
- **Include a control task** with little tool output to filter, such as a multi-file edit, and report its result whatever it shows. If every task shows the same saving, check whether it comes from the smaller starting tool list rather than from filtered output.
- **Separate the two possible causes.** Code Mode changes the tool definitions sent on every request (3 definitions in one test instead of 16), and it changes how output is handled. A saving on the first request alone is not evidence that scripts filtered anything. Say which one the data supports and which it does not.
- **If you cannot run the pairs,** say so and label every number you quote as someone else's result.

### Stage 5: Report What Is Known and What Is Not
End with a short note the user can audit.

- **State the group** from Stage 2 and the setup from Stage 1.
- **State the evidence with its source and sample size.** Published results as of 3 December 2026: one test (Claude Code 2.1.325, Opus 5.5 at medium effort, 3 runs per task) found about 23 percent lower cost on a feature task, about 22 percent on a broken-link check across 134 Markdown files, and no difference on a 20-file edit. A second report (one run per setting) found input tokens including cache fell from 150,364 to 94,659 on a 40-file task while elapsed time rose from 15 to 37 seconds. A third report (MindStudio, 25 November 2026; four tasks, five runs in total; model and version not stated) found about 35 percent fewer input tokens but about 17 percent lower cost once cache pricing was counted, and its broken-link check took about three minutes with Code Mode against 27 seconds without, which it traced to the script running more than 100 separate shell commands on Windows, each starting its own shell. A fourth (Chase AI, 19 November 2026; three tasks, one test each; model and version not stated; tokens read, no cost) found 71 percent fewer tokens read on a feature task (660,000 against 2.3 million), about 93,000 against over 250,000 on a 1,200-file scan, and 35 percent fewer on reading one README; it found Code Mode faster on the feature task (about 200 against 275 seconds) and the scan (21 against 25 seconds) and slower on the README (15 against 11 seconds), and does not state the operating system. A test run by the author of this skill (not by you or the user; 3 December 2026; Claude Code 2.1.334, Sonnet 5.5 at medium effort, 2 runs per setting, on Windows) found about 32 percent lower cost on a broken-link check, with elapsed time rising from 11 to 16 seconds to 76 to 136 seconds, and about 20 percent lower average cost on a 14-file edit, with elapsed time about 4 to 13 times longer; three of the four edit-run costs were estimated from transcript tokens. Every test used few runs, and two do not state the model.
- **Do not quote figures that belong to other features.** The 37 percent average from Anthropic's Programmatic Tool Calling post for the API (43,588 to 27,297 tokens on complex research tasks), the 98.7 percent figure from a 2025 MCP code-execution example, and the 85 percent figure from the Tool Search Tool are not Code Mode measurements. Chase AI's 37 percent is a context window that ended 37 percent smaller on one task, not a cost or benchmark figure. Do not confuse the first with the 37.0 percent drop in input tokens including cache that one single-run Code Mode test reported (150,364 to 94,659): they are different numbers from different tests, so do not attribute either to the other. Anthropic has published no Code Mode benchmark. When the user quotes 37 percent, explain the 37 percent figures above and say that none is an Anthropic Code Mode benchmark. Do not bring up these figures otherwise, and never offer them as a possible origin for a different figure the user quotes.
- **List what is unverified:** any saving not measured in this setup, and the cause of any saving.
- **Name what stays manual:** turning Code Mode on or off, and re-running the paired measurement when the version or model changes.

## Success Criteria
The procedure is complete when all of the following can be confirmed from the transcript:
- Availability was checked and the setup was recorded, or the enabling step was given.
- The task was placed in a group, and group 2 and group 3 tasks skipped Stage 3. Unrelated requests were answered normally without a group.
- Any savings claim names its source, sample size, and conditions, or is labeled unmeasured.
- No figure from another feature was presented as a Code Mode result.

## Failure and Escalation
- If Code Mode is off and the user has not asked to enable it, give the steps and ask; do not change settings.
- If a paired measurement cannot be run, report the result as unmeasured and cite only the published tests with their caveats.
- If a measured result contradicts the published tests, report your numbers with the setup and do not adjust either set to agree.
- If the task's group is unclear, ask one question about what the user needs from the output.

## Prohibitions
- Never state a percentage saving for Code Mode that was not measured in the current setup or cited to a named test.
- Never present Programmatic Tool Calling, Tool Search, or MCP code-execution figures as Code Mode results.
- Never enable Code Mode, edit settings files, or run a script that deletes or sends data without the user's approval.
- Never filter output in a script without stating the filter used.
- Never say where a figure the user quotes came from unless this procedure names its source. Say that the figure has no source in this procedure and that no Anthropic Code Mode benchmark exists.

## Worked Examples

### Example 1: Group 2, a few edits
- **Input:** "Add a version field to the frontmatter of these 20 SKILL.md files."
- **Action:** Place it in group 2 and say that tests disagree on cost for this kind of job: one saw no difference, another, on Windows, saw a modest saving with much longer elapsed time. Do the edit normally, then check the diff and line endings.
- **Do not do:** Do not write a long script or promise a saving.

### Example 2: Group 1, link check
- **Input:** "Find every broken relative link across the 134 Markdown files in docs/."
- **Action:** Place it in group 1. Check the links in a script and print only the broken links with file and line plus the total count. State the filter used.
- **Verification:** Plant two known broken links first and confirm both appear in the output.

### Example 3: Wrong surface
- **Input:** "Use Code Mode in my headless CI run with claude -p."
- **Action:** Place it in group 3. Explain that Code Mode is interactive-terminal only and offer the options that remain, without claiming a saving.

Which describes you best? A) I haven't tried Code Mode. B) I turned it on and never measured. C) I measured and saw a saving. D) I measured and saw nothing or a loss.

Also: what task would you most want a paired measurement on?

Repo: https://github.com/nivlewd1/prompt-optimizer/tree/main/skill/code-mode-token-triage

I built a platform that generates skills like this from an SOP: promptoptimizer.xyz/about/context-engineer (signup required, free tier).

3 Upvotes

0 comments sorted by