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.

In this article
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.

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.

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 XComparing 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.
| Criteria | Claude Code Mode | Tokendoctor Plugin |
|---|---|---|
| Core mechanism | Batches multiple tool calls into one JS script, filters locally | Replays 30-day logs, tunes 400K compaction cap, slides old output |
| Origin | Official experimental feature by Anthropic | Open-source MIT plugin on GitHub |
| Reported savings | No Code Mode benchmark published; API equivalent -37% | Author personal setup -38%; Haiku 5.5 slide median -11% to -21% |
| Key constraint | Native terminal only; strict resume and auto mode limits | Pays off mainly when sessions regularly exceed 400K tokens |
| Rollback | Remove env var or set it to 0 | Run /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
- Run tool calls from code with Code Mode - Claude Code Docs Anthropic
- Claude Code Changelog (v2.1.323, v2.1.326) Anthropic
- Introducing advanced tool use Anthropic
- localixai/tokendoctor: Replays your own past sessions to save on Claude Code GitHub
- Show HN: Tokendoctor – Replay your Claude Code sessions to cut token waste Hacker News
Coding agentsClaude & AnthropicAutomation
Safety & policy · Nov 17, 2026Claude Incognito Chats Still Know Who You Are: Here Is WhyMathematician David Bessis caught Claude Opus 5.5 naming him inside incognito thinking, exposing what incognito mode actually hides and keeps.
Agent basics · Nov 17, 2026Apple Tests Daily Siri AI Usage Limits on iOS 27.3 BetaThe iOS 27.3 beta tests daily device caps for cloud Siri AI and Apple Intelligence tools, scaling up to 20x with paid…
AI video · Nov 17, 2026Gemini 4 Hydrogen Review: Fast & Cheap, Yet Weak on 3DGoogle launched Gemini 4 Hydrogen at 2.5x the speed of 3.8 Flash. Here is a hands-on look at Google AI Pro value,…