Token benchmark: the same apps with and without Karni¶
Experimental
The benchmark harness is a script in the repository, not a public API. It may change in any release.
Karni's claim is that an AI coding agent writes less when the framework carries the repeated parts. This page measures that claim on three small apps, and publishes the method, the commands to repeat it, the limits and the raw data. The numbers come from the runs and from nothing else.
Results¶
What the runs show. On these three small apps the plain Django + React side passed its tests and cost less: Karni after the agent-flow work cost about 1.8 to 1.9 times as much per app (median) and took about 3 to 3.5 times as long. With Karni the agent wrote fewer lines of its own in all three apps (median 256 to 431 against 438 to 554), and each Karni project ended with far more code in it (median about 11,500 to 20,000 lines, most of it generated by Karni) than the plain one (about 440 to 570). The agent-flow work between the two Karni sets cut the median cost by 27 to 30 percent and the context the agent read again by 30 to 43 percent, and raised the runs that passed every test from 12 of 15 to 14 of 15. These tasks measure the time and cost to meet a small API contract, not everything a finished app contains.
What each finished project contains¶
The cost and time below measure a small API contract. What the agent leaves behind differs much
more: one kept run per app and condition (run.py --keep --n 1, the same model and agent),
each passing every acceptance test, measured by scripts/benchmarks/tokens/inventory.py. The
project's own Django reports its API routes and the methods each answers, its sign-in and account
routes outside the admin, the models in its admin and whether it serves an OpenAPI schema
(harness/django_probe.py). Its files give the React screens (.tsx files other than main.tsx,
App.tsx, tests and stories), the tests it ships with (the harness's acceptance tests are not
counted), a typed API client, a production Docker stack (Dockerfile and
docker-compose.prod.yml) and rules for the coding agent (AGENTS.md). The data is in
data/inventory.json, and the run records in data/inventory.jsonl.
| In the finished app | Booking, plain | Booking, Karni | CRM, plain | CRM, Karni | Shop, plain | Shop, Karni |
|---|---|---|---|---|---|---|
| API operations (route and method) | 22 | 103 | 24 | 71 | 25 | 135 |
| Sign-in and account endpoints, outside the admin | 1 | 16 | 2 | 16 | 2 | 16 |
| Models in the admin | 2 | 29 | 1 | 26 | 1 | 30 |
| React screens | none | 10 | none | 12 | none | 9 |
| Tests the project ships with | none | 9 | none | 7 | none | 15 |
| OpenAPI schema served | no | yes | no | yes | no | yes |
| Typed API client in the frontend | no | yes | no | yes | no | yes |
| Production Docker stack | no | yes | no | yes | no | yes |
| Rules for the coding agent | no | yes | no | yes | no | yes |
| Acceptance tests passed | 13 of 13 | 13 of 13 | 16 of 16 | 16 of 16 | 17 of 17 | 17 of 17 |
Runs measured: booking-karni-1-20261107T165100, booking-plain-1-20261107T164927, crm-karni-1-20261107T165559, crm-plain-1-20261107T165419, shop-karni-1-20261107T170108, shop-plain-1-20261107T165926 (repository commit 1d7cc1fb).
Model and agent. Every run of both conditions and both sets used the same model and the
same agent CLI version. The project names no AI tool or company, so the published data calls
the model model-A and gives the agent CLI by its version.
Commits. The "before" set ran from repository commits 14aa65a2 and d438dc52, which differ from the release candidate 8f62be82 only in the benchmark harness, not in Karni's packages. The "after" set ran from caebf735, which adds the agent-flow work.
45 completed runs in the data.
Data sets¶
- before: 15 plain, 15 karni completed runs, run 2026-11-07. Karni commit: 14aa65a2, d438dc52. Model: model-A. Agent CLI version: 2.1.318 (coding-agent CLI).
- after: 0 plain, 15 karni completed runs, run 2026-11-07. Karni commit: caebf735. Model: model-A. Agent CLI version: 2.1.318 (coding-agent CLI).
The plain column pools the plain runs of every set that has them: the plain side does not depend on Karni's version, so it is measured once and shown beside each Karni column.
booking¶
Figures are median (minimum to maximum) over the completed runs.
| plain | karni before | karni after | |
|---|---|---|---|
| Runs completed | 5 | 5 | 5 |
| Runs that succeeded | 5 of 5 | 3 of 5 | 5 of 5 |
| Acceptance tests passed (median of total) | 13 of 13 | 13 of 13 | 13 of 13 |
| Runs that passed every test | 5 of 5 (100%) | 3 of 5 (60%) | 5 of 5 (100%) |
| Frontend builds | 5 of 5 | 5 of 5 | 5 of 5 |
| Output tokens | 7,862 (7,634 to 8,452) | 10,473 (9,202 to 11,007) | 8,731 (5,575 to 10,025) |
| Cache-read tokens | 217,972 (172,847 to 262,066) | 1,530,117 (1,289,043 to 1,653,670) | 979,467 (557,513 to 1,267,950) |
| Total tokens | 246,836 (202,658 to 294,520) | 1,596,125 (1,352,950 to 1,709,893) | 1,024,877 (593,412 to 1,319,421) |
| Cost (USD) | 0.19 (0.18 to 0.21) | 0.45 (0.44 to 0.48) | 0.33 (0.23 to 0.39) |
| Wall time (seconds) | 61.76 (59.53 to 68.56) | 208 (174 to 246) | 187 (113 to 243) |
| Tool calls | 5 (4 to 6) | 26 (22 to 30) | 20 (12 to 24) |
| Diff lines, code | 436 (386 to 466) | 14,731 (14,536 to 17,931) | 14,370 (13,725 to 14,609) |
| Diff lines, all | 500 (447 to 527) | 14,875 (14,651 to 18,027) | 14,480 (13,856 to 14,718) |
| Lines the agent wrote | 438 (373 to 453) | 238 (186 to 273) | 256 (212 to 323) |
crm¶
Figures are median (minimum to maximum) over the completed runs.
| plain | karni before | karni after | |
|---|---|---|---|
| Runs completed | 5 | 5 | 5 |
| Runs that succeeded | 5 of 5 | 5 of 5 | 5 of 5 |
| Acceptance tests passed (median of total) | 16 of 16 | 16 of 16 | 16 of 16 |
| Runs that passed every test | 5 of 5 (100%) | 5 of 5 (100%) | 5 of 5 (100%) |
| Frontend builds | 5 of 5 | 5 of 5 | 5 of 5 |
| Output tokens | 9,048 (8,457 to 9,470) | 13,080 (12,294 to 15,269) | 10,077 (209 to 11,851) |
| Cache-read tokens | 263,273 (171,186 to 349,534) | 1,849,233 (1,531,087 to 2,385,489) | 1,051,736 (63,810 to 1,490,390) |
| Total tokens | 296,606 (201,113 to 386,099) | 1,921,982 (1,597,614 to 2,466,466) | 1,104,459 (67,408 to 1,553,571) |
| Cost (USD) | 0.21 (0.19 to 0.24) | 0.56 (0.49 to 0.65) | 0.40 (0.31 to 0.47) |
| Wall time (seconds) | 70.51 (62.65 to 81.05) | 278 (219 to 344) | 236 (187 to 804) |
| Tool calls | 6 (4 to 8) | 31 (27 to 36) | 22 (14 to 28) |
| Diff lines, code | 439 (424 to 462) | 14,161 (13,131 to 14,254) | 11,491 (11,424 to 11,564) |
| Diff lines, all | 519 (483 to 533) | 14,315 (13,277 to 14,400) | 11,630 (11,528 to 11,689) |
| Lines the agent wrote | 440 (426 to 464) | 334 (311 to 349) | 301 (272 to 338) |
shop¶
Figures are median (minimum to maximum) over the completed runs.
| plain | karni before | karni after | |
|---|---|---|---|
| Runs completed | 5 | 5 | 5 |
| Runs that succeeded | 5 of 5 | 4 of 5 | 4 of 5 |
| Acceptance tests passed (median of total) | 17 of 17 | 17 of 17 | 17 of 17 |
| Runs that passed every test | 5 of 5 (100%) | 4 of 5 (80%) | 4 of 5 (80%) |
| Frontend builds | 5 of 5 | 5 of 5 | 5 of 5 |
| Output tokens | 10,000 (9,233 to 14,425) | 15,393 (10,475 to 16,837) | 11,875 (11,451 to 12,694) |
| Cache-read tokens | 277,692 (182,765 to 397,846) | 1,970,436 (1,094,515 to 2,508,958) | 1,373,183 (1,045,932 to 1,702,573) |
| Total tokens | 316,770 (220,024 to 440,476) | 2,053,029 (1,160,702 to 2,605,002) | 1,430,303 (1,108,508 to 1,772,866) |
| Cost (USD) | 0.23 (0.21 to 0.30) | 0.62 (0.44 to 0.74) | 0.44 (0.40 to 0.53) |
| Wall time (seconds) | 72.21 (66.49 to 93.94) | 238 (163 to 320) | 255 (195 to 305) |
| Tool calls | 7 (4 to 10) | 29 (20 to 33) | 24 (18 to 28) |
| Diff lines, code | 565 (496 to 567) | 23,678 (21,479 to 24,181) | 19,977 (19,669 to 22,138) |
| Diff lines, all | 663 (593 to 678) | 23,819 (21,687 to 24,363) | 20,134 (19,816 to 22,319) |
| Lines the agent wrote | 554 (483 to 747) | 464 (330 to 534) | 431 (360 to 478) |
All tasks¶
Counts add up. A figure is the sum of the task medians, with the sum of the task minimums to the sum of the task maximums.
| plain | karni before | karni after | |
|---|---|---|---|
| Runs completed | 15 | 15 | 15 |
| Runs that succeeded | 15 of 15 | 12 of 15 | 14 of 15 |
| Acceptance tests passed (sum of task medians, of the total) | 46 of 46 | 46 of 46 | 46 of 46 |
| Runs that passed every test | 15 of 15 (100%) | 12 of 15 (80%) | 14 of 15 (93%) |
| Frontend builds | 15 of 15 | 15 of 15 | 15 of 15 |
| Output tokens | 26,910 (25,324 to 32,347) | 38,946 (31,971 to 43,113) | 30,683 (17,235 to 34,570) |
| Cache-read tokens | 758,937 (526,798 to 1,009,446) | 5,349,786 (3,914,645 to 6,548,117) | 3,404,386 (1,667,255 to 4,460,913) |
| Total tokens | 860,212 (623,795 to 1,121,095) | 5,571,136 (4,111,266 to 6,781,361) | 3,559,639 (1,769,328 to 4,645,858) |
| Cost (USD) | 0.63 (0.58 to 0.74) | 1.63 (1.37 to 1.87) | 1.17 (0.94 to 1.40) |
| Wall time (seconds) | 204 (189 to 244) | 724 (557 to 910) | 678 (494 to 1,351) |
| Tool calls | 18 (12 to 24) | 86 (69 to 99) | 66 (44 to 80) |
| Diff lines, code | 1,440 (1,306 to 1,495) | 52,570 (49,146 to 56,366) | 45,838 (44,818 to 48,311) |
| Diff lines, all | 1,682 (1,523 to 1,738) | 53,009 (49,615 to 56,790) | 46,244 (45,200 to 48,726) |
| Lines the agent wrote | 1,432 (1,282 to 1,664) | 1,036 (827 to 1,156) | 988 (844 to 1,139) |
The raw data is one JSON line per run in
scripts/benchmarks/tokens/data/runs.jsonl.
The tables above are written from it by report.py. A failed run stays in the data and
counts as a failure. Its tokens are in the figures too.
A run the agent CLI did not finish is different: when a usage or rate limit, an overloaded or
other API error, or a kill cuts it short (an error result, a stream with no result line, or a
non-zero exit without one), the run says nothing about its condition. It is recorded with
interrupted: true and the reason, left out of every figure, and counted in a note under the
results. run.py --resume runs it again, and a usage or rate limit stops the batch at once and
prints the reset time when the message gives one. report.py writes no comparison while a task
and condition has fewer completed runs than --n. Hitting the time limit is not an
interruption: it counts as part of the result.
The method¶
Three tasks, each one written prompt plus an API contract that both conditions must meet:
- Booking with payments. Resources, time slots with a capacity, bookings owned by the member, a checkout that creates a payment through a test provider, and staff who see every booking.
- A CRM with three roles and import. Companies, contacts and deals in a pipeline. The roles are sales (own deals), manager (all deals) and admin. Contacts import from a CSV file.
- A shop with orders and refunds. Products in categories, a cart, orders with a state (pending, paid, shipped, refunded), checkout and a refund through a test payment provider.
The prompt, the contract and the checks are in scripts/benchmarks/tokens/tasks/<task>/.
The contract names endpoints, fields, roles and status codes, and is written so that a plain
Django REST app and a Karni app can both meet it. A list may be a plain array or a paginated
object with results.
Acceptance. The checks are black-box HTTP tests (pytest and requests) against the running
app, plus npm run build in frontend/. The agent sees the contract and the checks and may run
them. The harness runs its own copy after the agent stops, and that run is what counts, never
the agent's claim.
Two conditions, everything else equal.
- Plain. An empty Django 5.2 and DRF project with a Vite, React and TypeScript frontend. Dependencies are installed, Karni is not.
- Karni.
karni newfrom wheels built from the checkout under test, its generated AGENTS.md, the Karni MCP server in.mcp.json, and a prompt that starts with the new-app procedure (Run `karni rules --procedure new-app` and follow every step for this request:).
The agent CLI, the model, the task prompt and contract, the checks, the time limit, the tool
permissions, a fresh directory and a fresh PostgreSQL database per run are the same. No user settings, hooks,
plugins or memory are loaded (--setting-sources project, --strict-mcp-config,
--no-session-persistence, and a new path per run so auto-memory starts empty).
The command of every run. <agent> is the agent CLI (--agent or KARNI_BENCH_AGENT)
and <model> the model (--model or KARNI_BENCH_MODEL). The harness reads the stream-json
events the CLI prints.
<agent> -p "<prompt>" --output-format stream-json --verbose --model <model> \
--setting-sources project --strict-mcp-config --mcp-config <the condition's MCP file> \
--no-session-persistence --dangerously-skip-permissions
It runs inside a throwaway folder under ~/.cache/karni-dev/bench/, with a limit of 60
minutes of wall time. --dangerously-skip-permissions is used only there, for both conditions.
Decisions. One model for both conditions, recorded with every run. There are 5 runs per task and condition, 30 runs in all. Acceptance is the API tests plus the frontend build. The time limit is 60 minutes per run. The runs alternate between the conditions, plain then Karni, so the time of day touches both alike.
Recorded per run. Input, output, cache-read and cache-creation tokens, the reported cost,
tool calls by tool, wall time, the agent CLI's version, the lines the agent wrote itself (counted from its Write, Edit,
MultiEdit and NotebookEdit inputs and from shell heredocs that write a file), the size of the project's git diff (lines added plus deleted, shown with and
without lockfiles, node_modules, migrations and build output), tests passed out of the total,
the frontend build, whether the time limit hit, and the exit status. The report gives the
success rate and, per figure, the median, minimum, maximum and interquartile range.
Comparing a Karni change. report.py takes several labelled data sets, for example plain
Django, Karni before an improvement and Karni after it: --data before=before.jsonl --data
after=after.jsonl. The plain runs of every set are pooled into one column, because the plain
side does not depend on Karni's version, and each label gets its own Karni column, in the order
given. For every task and column the report shows the runs completed, the acceptance tests
passed and the share of runs that passed every test, the frontend builds, output, cache-read and
total tokens, cost, wall time, tool calls, diff lines (code and all) and the lines the agent
wrote, as the median with the minimum to maximum range, and a row across all tasks. The method
section the report writes names, for each set, the Karni commit, the model, the agent CLI version
and the dates of its runs. The --n check applies to each column.
A run counts as a success when the agent ended by itself, every acceptance test passed and the frontend built.
Reproduce it¶
Everything is run from a Karni checkout with a virtualenv that has karni, karni-cli,
psycopg, pytest and requests, Node 20 or later, a test PostgreSQL and the agent CLI
signed in. Unset VIRTUAL_ENV first: the Karni commands prefer it over a project's own
virtualenv.
unset VIRTUAL_ENV
export KARNI_BENCH_AGENT=<the agent CLI> KARNI_BENCH_MODEL=<the model>
# once: the two starting projects (wheels from this checkout, dependencies, node_modules)
python scripts/benchmarks/tokens/run.py --build-starts
# the reference solutions: each task built with Karni, passing its own checks
python scripts/benchmarks/tokens/run.py --reference booking
python scripts/benchmarks/tokens/run.py --reference crm
python scripts/benchmarks/tokens/run.py --reference shop
# see the plan and the exact commands, nothing is started
python scripts/benchmarks/tokens/run.py --dry-run --show-prompt
# test the harness with a stand-in for the agent (no usage is spent)
python scripts/benchmarks/tokens/run.py --fake --n 1 --data /tmp/fake-runs.jsonl
# the 30 real runs (re-run the same command to continue where a stop left off)
python scripts/benchmarks/tokens/run.py --resume
# write the results into this page
python scripts/benchmarks/tokens/report.py
# or, with two Karni versions beside the plain runs (--data LABEL=PATH, repeatable)
python scripts/benchmarks/tokens/report.py --data before=before.jsonl --data after=after.jsonl
--tasks, --conditions, --n, --agent, --model and --limit-minutes narrow or change a
run.
The PostgreSQL is 127.0.0.1:55432 (user postgres) and each run uses a database named
bm_<run id> that is dropped afterwards. Servers listen on a free port between 8700 and 8799.
The reference solutions are in scripts/benchmarks/tokens/reference/. They prove that the
checks can be passed and are never shown to the agents under test.
Limits¶
- One model. The result says nothing about other models.
- Small N: five runs per task and condition. Read the spread, not only the median.
- The tasks and contracts are written by Karni's author. Two of the three fit Karni's recipes closely.
- Agent runs are not deterministic. The same prompt gives different runs.
- The Karni condition includes agent rules written for agents. That is the point of Karni, and it is also part of the condition.
- Package install time is excluded for both conditions. Dependencies are installed before the agent starts.
- Lines written by the agent are counted from Write, Edit, MultiEdit and NotebookEdit inputs, plus
the bodies of shell heredocs that redirect into a file (
cat > f <<'EOF',cat >> f,tee f) and of interpreter scripts (python - <<'EOF') that call a file-writing function.echo >,sed -iand files written by a script's own logic are not counted; they show up in the diff size. - The diff size is measured against the commit the harness made at the start of the run, so work the agent committed itself counts the same as work it left uncommitted.
- The checks measure the contract, not the quality or the look of the app.
- The Karni condition may use a recipe the contract fits. The result describes tasks like these and not every project.