cd /news/ai-agents/prompt-caching-made-my-ai-agents-3x-… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-183054] src=limascloud.com β†— pub= topic=ai-agents verified=true sentiment=↑ positive

Prompt caching made my AI agents 3x cheaper, then the tests started biting

Enabling prompt caching in mergecrew, an open-source team of AI agents, cut the cost per merged pull request from $6.14 in round one to $2.03 in the first $50 of round two, with 86% of input tokens read from cache versus 0% previously, according to the operator's write-up. Across the round-two batch, 72 million tokens were read back from the cache and only about 13,000 were sent uncached, while the agents produced roughly the same ~15,000 output tokens per pull request. The operator also fixed loop-level bugs β€” merges from a GitHub Actions token that failed to trigger CI or close issues, a run stuck on a NUL character Postgres refused to store, and tickets exhausting the Coder's 50 model turns at 240k tokens β€” and now clears old tool results so contexts stay under 100k tokens.

recommendation

Cache the stable prefix of every agent request and clear old tool results on long steps so contexts stay under 100k tokens; the source saw 86% cache reads and cost per merged PR fall from $6.14 to $2.03.

more in playbook: Controlling LLM cost
by read10 min views13 publishedDec 6, 2026
Prompt caching made my AI agents 3x cheaper, then the tests started biting
Image: source

In the first post I pointed mergecrew, my open-source team of AI agents, at claudedvan.com, a camper van planner written entirely by Claude, and let it burn through $200 of expiring API credit in one night. It merged 33 pull requests for about $6 each, and the biggest lesson was embarrassing: zero prompt cache reads. Almost all of the money went to re-sending the same conversation at full price.

I have another $200 that expires at the end of December. This time I'm spending it in four rounds of $50, with a post after each one, and changing things only between rounds. This is the first $50.

There's also a vertical version for phones.

What changed since the first night #

  • Prompt caching. mergecrew now marks the stable part of every request (instructions, tools, the conversation so far) as cacheable. Reading it back costs about a tenth of the normal price.
  • A real backlog. Between rounds, Claude and I turned the plans into about 180 GitHub issues in 10 epics, each ticket with the files to change, the steps and how to check it, plusDepends on: #n lines. mergecrew takes the next approved issue in epic order and waits for its dependencies to close.
  • The human homework. The manufacturers' manual numbers are in the repo now, with page references, so the agents stop guessing from search snippets.
  • Two specialist reviewers , an electrical/structural one and a source checker, that only run when a PR touches their files.
  • Spend checkpoints. Instead of waiting for the full $50, I stopped every $10–15, looked at what went wrong, fixed it, and let it run again.

Caching works #

Two $10 test runs before the batch settled it: 94% of input tokens came out of the cache. Over the whole batch it's 86%: 72 million tokens read back from the cache, and only about 13,000 sent uncached.

The agents do about the same amount of work per pull request as in round one (the same ~15,000 output tokens). What changed is what they pay to re-read their own context.

The plumbing, again #

As in round one, a real workload found bugs in mergecrew before it found any in the van. This time they were about the loop around the agents:

  • Merges that didn't count. A GitHub Actions workflow merged the agents' PRs, and GitHub deliberately doesn't trigger anything from that token's merges: no CI on main, no deploy, andCloses #n didn't close the issue, so dependent tickets never started. Now mergecrew merges its own PRs with its GitHub App, only when the reviewer approved, CI passed and the risk score is low, and never when the PR touches CI or deploy files.
  • A run stuck forever because one tool's output had a NUL character in it, which Postgres refuses to store.
  • Big tickets hit the turn limit. A family-build ticket used up the Coder's 50 model turns with its context at 240k tokens, which is also where the money goes: every turn re-reads everything before it. mergecrew now has the API clear old tool results (file reads, searches) on long steps, so contexts top out under 100k.

Once those were fixed, the whole chain ran on its own: run β†’ review β†’ merge β†’ CI β†’ issue closed β†’ the next ticket unblocked β†’ deploy to the dev site.

Three times cheaper (with an asterisk) #

The first numbers looked too good: tickets at $0.24 to $0.98 each, against ~$6 a PR in round one. But round two's tickets were smaller and pre-planned, and round one paid for its own research. So I compared them by size, too:

Round 1 Round 2, first $50
Spend $202.60 $48.82
Pull requests / merged 34 / 33 29 / 24
Median PR size 184 lines 168 lines
Cost per 100 changed lines $3.09 $0.94
Cost per merged PR, failures included $6.14 $2.03
Input tokens from cache 0% 86%

Like for like it's roughly three times cheaper, and all of the saving is caching.

The asterisk is quality.

Then I made the agents run the tests #

Partway through, 5 of 7 pull requests failed CI. Not flaky tests: real breakage, like analytics twice and a battery-bank check failing after the water tanks moved. Looking at the transcripts, the Coder had never run the tests once. Its instructions literally said "CI runs npm test and build". Round one got away with it because the codebase was young and the test suite was small. Round two runs against ~900 tests and a size budget.

mergecrew already had the pieces: build skills that run a project's own npm test and npm run build inside a Docker sandbox. Nobody had ever used them end to end, and each layer had a problem:

  1. A config option that went nowhere. The setting that tells mergecrew "for this project, typecheck meansnpm run build " was accepted and then never passed to the skills.
  2. No network. The sandbox runs with networking off, sonpm ci can't download anything. The documented fix was a host firewall script, and reading it closely, it would have cut networking for every container on the server and could wipe Docker's own rules. I didn't run it.
  3. The fix that already existed. mergecrew had a small allowlisting egress proxy that had never been wired in. We finished it properly: sandboxes join an internal Docker network with no route out, the proxy is the only exit, each command carries a signed list of the hosts its project may reach (package registries by default), and the proxy refuses private and internal addresses. No firewall changes on the host, and it works for anyone self-hosting mergecrew.
  4. No home. The sandbox user had no home directory, so npm tried to create its cache in/ and failed.
  5. An old Node. The default sandbox image was Node 20, past its end of life. It's Node 26 now.

And then the tests bit #

A word on that size budget, because it's at the center of this part. claudedvan is a website, and on a phone every kilobyte of JavaScript has to be downloaded before the page appears. Earlier in the batch, the agents had done a round of phone performance work, and part of it was a check that runs on every build: each part of the site (the main page code, the 3D viewer, the styles) has a maximum size, and if a change makes one of them bigger than its limit, the build fails. It's a good guard: it stops a new feature from quietly making the site slow.

With the tests running, the agents behaved better and worse at once:

  • Better: a Coder whose change failed the tests didn't commit it. Another one found that the size budget made its ticket impossible andfiled an issue asking me to raise it , instead of weakening the check.
  • Worse: one Coder rebuilt the site about 30 times trying to shave 0.2 KB off a bundle that sat exactly at its budget, and spent $2.57 doing it. The budget had no headroom: any feature that touched the main bundle failed.

Two changes fixed that: I raised the budget (my call, it's the owner's line), and the Coder got a stop rule: if the same failure survives three fixes, commit nothing, file an issue that says what decision is needed, and stop. The Planner also got a bigger budget for the vague tickets.

After that, the last nine runs of the batch all opened a pull request, all of them ran the tests first, and all nine merged, for $13.83 in total, about $1.54 each. That includes a family-build ticket that had failed three times, and a performance ticket that had burned $2.57 looping. Two of the nine still missed a size budget by a fraction of a KB, the same no-headroom problem in a different bundle. One Coder spotted it and filed an issue about it, I gave that budget room too, and both merged.

Why did the budgets keep landing exactly at the size of the code? My own README said "lowering is fine, raising needs the owner". So every time a PR made a bundle smaller, the agent did the tidy thing and lowered the budget to the new size, and the next PR failed by 0.1 KB. A rule written for humans read very differently to an agent. The fix was one sentence: budgets keep 25–40% headroom, and only I change them, up or down.

So is round two better? #

It's cheaper per merged PR, by a lot. But it wasted about as much of its money: 45% went to runs without a PR or to PRs I had to close, against 43% in round one, even though it looked far worse in the middle of the batch. Three reasons, and only one is bad:

  • Round one hid its failures. 31 of its runs ended "done" with no pull request, $88 that looked like success. Round two marks them failed.
  • The bar is higher. Hundreds of tests and a size budget now, and since the middle of this batch, the agents run them themselves.
  • I changed the system during the batch. Caching, tool clearing, test skills, the sandbox network, the stop rule: nearly every new piece broke the first time it met a real workload. This $50 was as much a shakedown of mergecrew as a measurement.

That's why the next $50 runs with the configuration frozen. Changes wait until it's over, so the next post compares like with like.

What the agents built this time #

  • claudedvan works on a phone : a four-tab navigation, 44-pixel tap targets, tables that turn into cards, a Build page that scrolls with two-finger 3D, and drawings you can pinch and pan.
  • Phone performance: anpm run perf that measures load time and frame rate on an emulated phone, the 3D in its own lazy chunk, fewer draw calls, analytics loaded after the first frame, and a size budget in the build.
  • Family build fixes: a power cupboard under the bed, the diesel heater turned clear of the fuel tank, water tanks boxed in with stops, a galley over the tank, a front bathroom, the van drawn ahead of the build area, and two 300 Ah batteries so the AC runs all night.
  • Sources and checks: where each Transit number was checked in Ford's documents, and build checks grouped with their sources.

| Credit used | $48.82 of the $50 | | Runs | 35, with 1,663 model calls | | Pull requests | 29 opened, 24 merged (5 closed for failing CI, all before the fixes) | | Spend by agent | Coder 60%, Planner 27%, Reviewer 13% | | What the agents did | 1,407 file reads, 1,216 searches, 774 edits, 71 builds, 48 test runs, 7 issues filed |

Next $50 #

  • Frozen configuration: same agents, limits and mergecrew version for the whole round.
  • The questions it answers: how many PRs pass CI on the first try now that the Coder runs the tests, and what a merged PR costs when nothing is changing underneath.
  • Already built and waiting for a later round: a "quick" mode where one Coder plans and codes small, well-specified tickets, and a backlog mode where an empty queue makes the Planner write well-scoped issues instead of code.

Try it yourself #

  • mergecrew is open source:github.com/mergecrew/mergecrew . Everything in this post, from the egress proxy to the stop rule, is in the repo.
  • mergecrew is looking for sponsors. Every experiment here is paid out of pocket in tokens. If you or your company can donate API credits, thesponsors page explains how.
  • claudedvan is live atclaudedvan.com , and its code (with every agent PR, plan and review) is atgithub.com/thiagotigaz/claudedvan . Open it on your phone this time.

If you run agents on your own repo: turn on prompt caching, make the agent run the tests before it commits, give it a stop rule, and leave your quality gates some headroom.

── more in #ai-agents 4 stories Β· sorted by recency
── more on @mergecrew 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/prompt-caching-made-…] indexed:0 read:10min 2026-12-06 Β· β€”