Skip to content

NextClaw × DeepSeek: five-stage optimization cuts cost 62.0%, 10.8% below DeepSeek Harness

Completing the same three tasks, NextClaw's cost fell from USD 0.022664 to 0.008613: 62.0% lower. The optimized build cost 10.8% less than official DeepSeek Harness in the same suite.

VersionPassed ↑Cost USD ↓Cache hit ↑Total tokens ↓Time s ↓
NextClaw · Original3/30.02266461.99%239,07435.91
NextClaw · Optimized3/30.00861384.08%173,41128.90
DeepSeek Harness3/30.00965678.92%159,42828.48

Bold marks the best value. Costs use provider-reported usage; time includes startup and verification. These are development-build measurements with one three-task run per stage, not a statistically significant or universal advantage.

Cost across five cumulative stages

Each stage adds one group of changes to its predecessor; S0 predates all five. All 21 task cases passed, without excluded failures or selective retries.

NextClaw five-stage cost curve with original and DeepSeek Harness references

StageCost USDCache hitInput tokensOutput tokensTotal tokensTime sCalls
S0 Original0.02266461.99%236,2162,858239,07435.9115
S1 Model rounds0.01505477.85%250,0852,278252,36327.5516
S2 Resident prompts0.01504177.82%248,8722,332251,20429.9817
S3 Stable declarations0.01175784.01%250,1842,249252,43330.2717
S4 Compaction retention0.01164583.17%237,4622,230239,69228.7016
S5 On-demand parameters0.00861384.08%170,9562,455173,41128.9016
DSH0.00965678.92%157,1532,275159,42828.4815

Changes from the preceding stage

Negative cost, token, and time changes mean reductions. Cache changes are percentage points. The original-relative column measures cumulative change; row percentages are not additive.

StageCost vs previousCost vs originalCache changeTotal-token changeTime change
S1 Model rounds-33.58%-33.58%+15.86 pp+5.56%-23.29%
S2 Resident prompts-0.09%-33.64%-0.03 pp-0.46%+8.83%
S3 Stable declarations-21.83%-48.12%+6.19 pp+0.49%+0.98%
S4 Compaction retention-0.95%-48.62%-0.84 pp-5.05%-5.21%
S5 On-demand parameters-26.04%-62.00%+0.91 pp-27.65%+0.71%

What each stage tells us

S1: preserving history delivers the first major reduction

Cost fell 33.58% and cache hit rate rose 15.86 percentage points, even though total tokens increased 5.56%. Uncached input fell from 89,784 to 55,397.

History/tool-prefix rewrites fell from 9 to 1. Persisted model-round boundaries prevent subsequent calls from merging old history again; the remaining rewrite involved tool declarations. Savings came from reducing expensive uncached input rather than simply sending fewer tokens.

S2: shorter prompts do not produce a matching cost reduction

Cost fell just 0.09%, cache rate fell 0.03 points, total tokens fell 0.46%, and time increased 8.83%. This is essentially flat, not evidence of major independent savings.

File-task cost rose from USD 0.005476 to 0.008267 while the other tasks became cheaper. Its tool list still changed from 49 to 50 entries, disrupting the prefix; execution paths also varied. Prompt size must be evaluated alongside cache stability.

S3: stable declarations deliver the second major reduction

Cost fell 21.83%, cache rate rose 6.19 points, and uncached input fell from 55,208 to 40,008. Total tokens increased 0.49%, calls stayed at 17, and prefix rewrites fell from 1 to 0.

Session search is declared at startup; execution reports indexing readiness. Becoming ready no longer adds a tool to the prefix. Request evidence supports the observed mechanism.

S4: compaction fixes are present, but the short suite does not activate them

Cost fell 0.95%, cache rate fell 0.84 points, total tokens fell 5.05%, and calls fell from 17 to 16.

There were no summary calls, so this small cost reduction cannot be attributed to the compaction fix. The stage demonstrates successful execution with the fix included; timing and cost differences accompany different execution paths. Isolating compaction savings requires a long-session experiment that actually triggers compaction.

S5: reducing resident schemas delivers the third major reduction

Cost fell 26.04%, total tokens fell 27.65%, and cache rate rose 0.91 points. Calls stayed at 16 and time increased 0.71%; lower cost does not necessarily mean faster execution.

Tool declarations shrank from 29,898 to 15,036 characters, and input tokens from 237,462 to 170,956. Some full schemas are queried through stable tool_schema; foundational tools retain full parameters and execution keeps validation and permissions.

These tasks mainly use directly declared foundational tools. They do not establish lower cost or unchanged quality for workloads with many schema lookups.

Experimental setup and complete data

  • Official deepseek-v4-flash, enabled/high reasoning; DSH SDK 0.1.2-rc.1.
  • Tasks: five-file investigation with follow-up, configuration diagnosis with follow-up, and Python shipping-boundary repair with independent tests.
  • Uniform 2,048 output-token cap per request, 120-second task timeout. No case hit the output limit.
  • Each case uses an independent process, HOME, XDG directories, and workspace; native tools remain, user-installed skills and history are excluded.
  • Stage order rotates across tasks; no provider-cache reset or extra warm-up. One observation per task per stage, without confidence intervals.
  • Original source: c0b131f19, retaining only the shared public-entry chatStream receiver-binding fix needed to run measurement. The manifest records cumulative source changes.
  • Measured September 8, 2026, 05:15–05:18 UTC, within one pricing window: USD 0.22 / 0.007 / 0.66 per million uncached input / cached input / output tokens.
  • 21 cases, 112 model calls, USD 0.094429860 in estimated usage cost, below the USD 0.25 ceiling. This is not an invoice charge.

The core cache ratio includes initial requests and is weighted by input tokens. Output includes reasoning. All tables and the curve come from this unified experiment; earlier 512-token-cap runs are not combined with it.

Cache conditions affect the size of the advantage

S5's initial requests cached 6,912 tokens in total; DSH's initial requests cached none. Repricing only these initial requests as uncached gives USD 0.010085404 for S5 versus USD 0.009656344 for DSH, putting NextClaw about 4.4% higher.

Thus the measured 10.8% advantage includes the observed provider-cache conditions. This sensitivity calculation is not a real cache-reset rerun. Matching task specifications does not fully control provider caches.

Full cache, reasoning, and request metrics
StageCached inputUncached inputReasoning tokensAPI sPrefix rewrites
S0146,43289,7841,04523.869
S1194,68855,39766819.001
S2193,66455,20869420.431
S3210,17640,00852819.660
S4197,50439,95859118.400
S5143,74427,21274419.940
DSH124,03233,12158019.780
All 21 task results
StageTaskPassedCost USDCache hitInputOutputTime sCalls
DSHconfig0.00257022474.63%34,9876598.164
DSHfiles0.00433012082.22%86,4046869.347
DSHrepair0.00275600075.16%35,76293010.974
S0config0.00588755658.50%56,0098269.264
S0files0.01230006459.03%123,3881,01216.077
S0repair0.00447616471.86%56,8191,02010.584
S1config0.00578701667.56%69,34377310.135
S1files0.00547648884.14%123,6786569.267
S1repair0.00379013276.71%57,0648498.164
S2config0.00337025683.32%66,2128409.995
S2files0.00826686071.78%116,79965010.047
S2repair0.00340341282.99%65,8618429.965
S3config0.00326875683.02%65,6776589.895
S3files0.00499490085.21%117,92668710.037
S3repair0.00349367682.86%66,58190410.355
S4config0.00326720479.15%53,2058068.724
S4files0.00497244485.22%117,76066710.587
S4repair0.00340544082.77%66,4977579.405
S5config0.00230096881.32%36,6768869.594
S5files0.00390166485.06%88,6346989.317
S5repair0.00241051684.41%45,6468719.995

Rerunning and tracking

The private @nextclaw/agent-benchmark package reuses tasks, acceptance checks, request observation, and budget accounting. A stage manifest freezes source and fingerprints. Reports include absolute metrics and differences from the preceding stage and original. Resume skips completed cases without selectively retrying failures.

Run inside the package directory. Inspect tasks and budget with --dry-run, then remove it to execute. Reading existing JSON or Markdown reports makes no model calls.

sh
pnpm exec tsx --conditions=development \
  --tsconfig ../../scripts/dev/dev-runtime.tsconfig.json \
  src/diagnostics/staged-study.manager.mjs \
  /absolute/new-result-dir /absolute/dsh-sdk-dir --dry-run

Released under the MIT License.