Monitoring savings¶
codemode-mcp keeps track of what it saves, so you can see the effect on your own workload instead of taking anyone's word for it.

The dashboard, shown here with sample data.
Quick reference¶
codemode-mcp usage # terminal summary (last 7 days)
codemode-mcp usage --range all --json # machine-readable
codemode-mcp dashboard # web dashboard → http://127.0.0.1:8765
codemode-mcp serve --dashboard-port 8765 # dashboard alongside a running stdio server
codemode-mcp serve --transport http # dashboard at /dashboard/ on the same port
codemode-mcp benchmark -c mcp.json -m gpt-4.1-mini "your real task"
codemode-mcp usage --clear # delete recorded data
codemode-mcp usage (last 7 days) - /home/me/.codemode-mcp/usage.db
Code Mode calls 2 upstream tool calls 15
Code Mode tokens 1,074
Classic MCP (estimate) 10,845
Saved 9,771 (90.1%)
by type calls Code Mode classic est.
run_code 2 1,074 10,845
top tools: shop.list_customers (2), shop.get_orders (1)
The dashboard¶
The dashboard is a self-contained page that works offline (no CDN) and refreshes every 10 seconds. It shows:
- Key figures: tokens saved, % saved, Code Mode tokens, the classic-MCP estimate, calls, upstream tool calls and errors.
- Tokens per day: classic estimate and Code Mode side by side.
- By call type:
run_code,search_toolsand direct tools. - Most used upstream tools.
- Benchmarks: measured head-to-head runs (see below).
- Recent activity: tools used, upstream calls, tokens, duration and status.
Pick a time range of 24 hours, 7 days, 30 days or all time. The JSON behind the page is
available at /api/summary?range=7d and /api/events?limit=50.
Two kinds of numbers¶
1. Estimates (every call, automatic)¶
Each run_code, search_tools and direct (hybrid) tool call is recorded in
~/.codemode-mcp/usage.db (or $CODEMODE_HOME, or codemode.usage_db). Tokens are
counted with tiktoken o200k_base when it's installed (pip install "codemode-mcp[tokens]"),
or about 4 characters per token otherwise.
| Call | Code Mode (actual) | Classic MCP (estimate) |
|---|---|---|
run_code |
Code Mode tool definitions + the code + the output returned to the model | Classic tool definitions (all tools) once per run, plus each upstream call's arguments and full raw result. A run with no upstream calls counts as 0 |
search_tools |
Definitions + query + results | 0, because classic clients don't need to search |
| Direct tool | Code Mode definitions + arguments + result | Classic definitions + arguments + result |
The estimate is deliberately conservative:
- It charges the classic tool definitions once per
run_code, as if a classic agent had issued all of that run's upstream calls as parallel tool calls in a single LLM turn. Real agents need a new turn, carrying the definitions again, whenever one call depends on the result of another. - It doesn't count conversation history re-sent on later turns. Real classic agents re-send every earlier result on every turn, which usually costs far more.
- It ignores the model's output tokens. These are often larger in classic mode, because the model has to repeat data between calls.
- It assumes a classic client would have made exactly the same upstream calls.
What it does not model, in either direction:
- Prompt caching. Providers bill cached tool definitions at a discount, so the saving in money on the definitions part is smaller than the saving in raw tokens.
- Clients that defer tool definitions. If your client already loads tool schemas on demand (tool search), it doesn't send every definition on every request, and the definitions part of the saving shrinks accordingly.
Estimates count raw tokens only. For numbers from a real model, use a benchmark.
2. Measurements (real LLM runs)¶
codemode-mcp benchmark -c mcp.json -m gpt-4.1-mini "Find the 3 customers in India with the highest spend"
codemode-mcp benchmark -c mcp.json -m claude-sonnet-4-5 --provider anthropic "..."
codemode-mcp benchmark -c mcp.json -m llama3.1 --base-url http://localhost:11434/v1 "..."
The benchmark runs the same prompt twice with the same model:
- Classic: every upstream tool is given to the model directly, and results go back into the conversation, as in a standard MCP client.
- Code Mode:
run_code(+search_tools).
Model: gpt-4.1-mini
classic MCP Code Mode
LLM turns 15 2
tool calls seen by LLM 14 1
input tokens 41,870 2,980
output tokens 612 140
total tokens 42,482 3,120
seconds 18.4 6.1
Code Mode used 92.7% fewer tokens (measured).
Classic answer: …
Code Mode answer: …
(Illustrative output: your numbers depend on the model, the servers and the task.)
Token counts come from the provider's usage reports. Both answers are printed so you can
check that quality is the same. Results are stored as benchmark events and listed on
the dashboard. --json prints the full result for CI or spreadsheets.
The run_openai / run_anthropic agent loops and codemode-mcp chat also log the
provider-reported usage of every request (llm events, shown as measured LLM usage).
From Python¶
cm.usage() # since this CodeMode started: codemode_tokens, classic_tokens, saved_pct, ...
cm.stats() # tool-definition cost per request, classic vs Code Mode
cm.last_event # accounting for the most recent call
from codemode_mcp import UsageStore
store = UsageStore() # default database
store.summary(since=time.time() - 86400) # same data as the dashboard
store.recent(50)
from codemode_mcp.benchmark import run_benchmark, format_result
result = await run_benchmark(cm, "your task", model="gpt-4.1-mini")
print(format_result(result), result.saved_pct)
Privacy¶
The usage database stores timestamps, counts, durations, tool names and, for benchmarks,
the model name and the first 200 characters of the prompt. It never stores code,
tool arguments or results. To keep a full record of what was run, enable
audit_log. To turn tracking off, set
"usage_tracking": false.