Blog · AI Agent News · Coding agents VIEN

Claude Code Mode vs. Tokendoctor: Cut Token Spend Up to 38%?

Comparing Claude Code Mode JS tool batching and Tokendoctor context tuning: real numbers, exact setup steps, strict limits, and who benefits.

Claude Code Mode vs. Tokendoctor: Cut Token Spend Up to 38%?
Images: Tirza van Dijk tirzavandijk / Wikimedia Commons (CC0)
In this article
  1. How does Code Mode work, and where did the 37% figure come from?
  2. How does Tokendoctor cut session costs?
  3. Comparing both approaches and how to test them
  4. My take

Opening a Claude Code session to inspect dozens of files starts cheap, then token spend climbs sharply as the conversation drags on. Every new turn resends the entire chat history plus earlier file reads back to the model. This week, Claude Code users have focused on two very different ways to trim that bill: Anthropic’s experimental Code Mode and the open-source Tokendoctor plugin. Both come with headline figures around 37% to 38%, yet each number carries real caveats worth checking before you touch your config.

Editorial comparison between Claude Code Mode batching tools in JavaScript and Tokendoctor tuning the 400K context limit
Code Mode filters intermediate tool output in one JavaScript step, while Tokendoctor replays 30 days of local logs to tune compaction limitsImage: ptm m / Wikimedia Commons (Public domain); NOIRLab/NSF/AURA/T. Slovinský / Wikimedia Commons (CC BY 4.0)

How does Code Mode work, and where did the 37% figure come from?

In standard mode, Claude calls one tool at a time, pulls the full search or file output back into context, and then decides the next step. With Code Mode enabled, Claude writes JavaScript that runs several tool calls together, filters intermediate noise locally, and sends only what matters back to the model.

Anthropic added Code Mode in v2.1.323 on November 12, 2026, and extended support to agent teams in v2.1.326 on November 16, 2026. Notably, neither the Code Mode documentation nor the release changelog publishes a 37% token-savings benchmark. That 37% figure originated in Anthropic’s November 24, 2025 post on API Programmatic Tool Calling, where average usage on complex research tasks fell from 43,588 to 27,297 tokens. Keeping those sources separate helps set realistic expectations instead of assuming every task will drop by a third.

How does Tokendoctor cut session costs?

Rather than rewriting how tools execute inside a single turn, Tokendoctor targets long-running context bloat on 1M-window models. As documented in the repository, Claude Code waits until nearly 967K tokens before compacting, which makes the tail end of marathon sessions expensive because every request resends the whole history. In the author’s personal usage logs, two-thirds of main-thread spend went to requests with more than 400K tokens already in context.

Editorial bar chart comparing Claude Code's 967K default compaction threshold, Tokendoctor's 400K cap, and the author's average context drop from 412K to 219K tokens
Lowering the compaction cap from 967K to 400K reduced the author's average context per turn from 412K to 219K tokens

Tokendoctor replaces guesswork with local diagnostics. Running /tokendoctor:sessions replays the past 30 days of local transcripts at 200K, 300K, 400K, and 600K compaction windows without making any model calls. Next, /tokendoctor:audit runs 38 checks against Claude Code docs, while /tokendoctor:optimize proposes changes from your numbers and previews diffs for only the changes you pick, with /tokendoctor undo ready to roll back. An optional slide mode drops old tool outputs in milliseconds instead of waiting an average of 79 seconds for an LLM summary.

The author’s headline numbers require context too. Comparing one month before and one week after setting a 400K compaction cap plus Sonnet for subagents (roughly 23K versus 19K main-thread requests), average context per request dropped from 412K to 219K and main-thread API cost per request fell 38%. The author notes this is one person’s before-and-after, not a controlled experiment. On their controlled Haiku 5.5 TypeScript benchmark, tasks rarely crossed 400K so changing the compaction window alone did not save money, while sliding window cut median per-task cost by 11% to 21% (individual runs ranged from -40% to +17%).

Also readAnthropic CEO's Open-Source AI Warning Sparks Backlash on X

Comparing both approaches and how to test them

Because one optimizes tool round-trips and the other trims stale conversation history, the two approaches solve different bottlenecks. This side-by-side table summarizes the trade-offs before you change any setting.

CriteriaClaude Code ModeTokendoctor Plugin
Core mechanismBatches multiple tool calls into one JS script, filters locallyReplays 30-day logs, tunes 400K compaction cap, slides old output
OriginOfficial experimental feature by AnthropicOpen-source MIT plugin on GitHub
Reported savingsNo Code Mode benchmark published; API equivalent -37%Author personal setup -38%; Haiku 5.5 slide median -11% to -21%
Key constraintNative terminal only; strict resume and auto mode limitsPays off mainly when sessions regularly exceed 400K tokens
RollbackRemove env var or set it to 0Run /tokendoctor undo

To test Code Mode on a single interactive terminal session in macOS, Linux, or WSL, launch Claude Code with the opt-in flag:

CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude

To enable it across your user sessions, add "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1" under "env" in ~/.claude/settings.json, noting that Claude Code ignores this variable inside project-level settings files. To try Tokendoctor without changing settings first, install the plugin and run the read-only replay:

claude plugin marketplace add localixai/tokendoctor
claude plugin install tokendoctor@tokendoctor

Restart Claude Code and run /tokendoctor:sessions to see what your own past 30 days would have cost at each window before accepting any change.

My take

Looking past the 37% and 38% headlines, neither tool is a universal discount switch. Code Mode tackles chatty tool round-trips when Claude has to scan or edit dozens of files in one go, yet it locks you into the native terminal and still lacks an official Anthropic benchmark for Claude Code itself. Tokendoctor takes a more grounded route by auditing your own 30-day transcripts first, though short tasks under 400K tokens will barely feel a compaction cap change.

If I were testing these on a daily coding setup, I would run /tokendoctor:sessions first because it stays offline on your machine and spends zero tokens. Only if those transcripts show heavy spending above 400K would I adjust the window, or test Code Mode on an isolated branch where its terminal and permission limits will not get in the way.

Sources

  1. Run tool calls from code with Code Mode - Claude Code Docs Anthropic
  2. Claude Code Changelog (v2.1.323, v2.1.326) Anthropic
  3. Introducing advanced tool use Anthropic
  4. localixai/tokendoctor: Replays your own past sessions to save on Claude Code GitHub
  5. Show HN: Tokendoctor – Replay your Claude Code sessions to cut token waste Hacker News

Coding agentsClaude & AnthropicAutomation

Was this useful?

More on this topic