· Timo Kilpilehto · 6 min read
Rails won't save your AI agent much time
Frameworks made the agent more expensive in all five languages and saved little code against a strict API contract. Why a human's biggest saving is the agent's smallest.
Draft. Part 2 of 3 in the series Does the language still matter when the AI writes the code? The numbers are final; the wording is not.
My starting hypothesis was simple. Rails let a human build a Twitter clone in fifteen minutes; a framework with batteries included should do the same for an AI agent. Less code to write, less to get wrong, and the effect should stack on top of the language: an expressive language and a mature framework.
So for every language I ran the agent twice on the same spec:
- Lean: the standard library plus a short allowlist — an HTTP server, a Postgres driver, a password hasher, a test runner. Routing, validation, error handling, rate limiting, OpenAPI and migrations: write them yourself.
- Batteries: the mainstream full-stack choice — Rails, Django + Django REST framework, NestJS + Prisma, Spring Boot, and axum + sqlx for Rust — plus any well-maintained library.
Same model (Claude Opus 5.5), same spec, same rules, three growth steps each. Here is what came out.
Frameworks cost more to build with — in every language
| Total build cost, 3 steps | Lean | Batteries |
|---|---|---|
| Python | $4.42 | $6.26 |
| Ruby | $4.94 | $6.82 |
| TypeScript | $4.60 | $5.86 |
| Rust | $5.41 | $5.98 |
| Java | $6.50 | $6.67 |
Single runs are noisy — I built one cell three times and its cost moved by about 20 % — so no one row proves anything. But the direction is the same in all five languages, at the first build and again at most growth steps.
…and shrink the code much less than you’d expect
Counting everything the agent wrote and would have to maintain (application code, schema migrations, a hand-written API description where there is one; tests excluded):
| Maintained code at step 1 (tokens) | Lean | Batteries | Change |
|---|---|---|---|
| Python | 23.8k | 19.9k (3 builds) | −16 % |
| Ruby | 25.3k | 23.3k | −8 % |
| TypeScript | 26.8k | 29.2k | +9 % |
| Rust | 34.4k | 34.0k | −1 % |
| Java | 45.1k | 36.1k | −20 % |
Compare that with the gap between languages: Python and Ruby need 1.4–1.9× less code than Rust or Java for the same behaviour. The framework is a ±20 % effect; the language is a 50–90 % effect.
Where the effort goes instead
I had two agents dig into the code and the session logs.
The domain is the same size everywhere. The note logic — checklist trees, check propagation, converting text to lists, manual ordering — is 14–20k characters in all ten implementations. No framework touches it. Frameworks only compete on the plumbing: routing, validation, auth, persistence, API docs.
Some plumbing gets smaller, some gets bigger. ActiveRecord and JPA genuinely save persistence code. But validation and error handling grew under DRF, NestJS, axum and Spring. The spec demands an exact error format — RFC 9457 problem details with stable machine-readable codes — and every framework has its own opinion about error shapes. Each build needed an adapter to translate one into the other. NestJS and Spring also add ceremony: controller/service splits, DTO classes, dependency-injection constructors and imports (16 % of Java-batteries’ source is imports and wiring, against 4 % in the lean build).
The extra cost is mostly thinking and setup, not debugging. Every run starts with one long design pass before the first line of code. In framework runs that pass was usually longer, and it was followed by setup work a lean build doesn’t have: installing the framework, running the generator, deleting what it generated, reading library source to find out how a rate limiter stores its counters. Framework friction showed up too — a circular import from Django’s custom exception handler in all three Django builds, Rails defaults that had to be switched off — but it cost a handful of tool calls, not the bulk of the bill.
What the framework does buy: some robustness, not much — and it costs at runtime
Correctness was near-perfect either way (≥ 99 % of the base spec in all ten builds). The differences show up at the edges, and they cut both ways.
- Frameworks leak their defaults. Fuzzing found more contract violations in the framework build
in 4 of 5 languages (Spring: 83 % vs 99 % for hand-written Java; NestJS: 89 % vs 94 %). Rails
accepted a valid token under the
Tokenscheme as well asBearer, and rewrote client request ids. None of these are holes — they are the framework’s own answers not matching the spec. - Hand-written plumbing has its own bugs. Two lean builds — Python on raw ASGI and Java on the
JDK’s HTTP server — add ~40 ms to every response,
/healthincluded: the signature of a response written in two TCP segments meeting delayed ACKs. A framework would have handled that. - The worst bug sat in a framework build. The NestJS + Prisma sync feed lost changes under concurrent writes — the one real correctness failure in ten implementations — even though the agent had named the trap in its README and tried to engineer around it.
- Frameworks cost CPU. Per request, Django used 3–4× the CPU of hand-written Python, NestJS 2.8–4× hand-written TypeScript, Spring 2.4× hand-written Java, Rails 2× hand-written Ruby. axum was the exception: slightly cheaper than hand-written hyper.
Why this is different for humans
A framework saves a human two things: typing, and knowing how. The agent doesn’t type, and it already knows how to hand-roll a router or a migration runner. What it doesn’t know in advance is this framework version’s exact conventions — so it has to look them up, try them, and adapt them to the spec. The human’s biggest saving is the agent’s smallest; the human’s small cost (learning the conventions) is a real cost for the agent at every first build.
The caveats, honestly
- This spec is hostile to frameworks. A bespoke error format, custom token rules and global rate limits in Postgres all fight framework defaults. A spec written in Rails’ own idioms would likely look better for Rails. Many real API contracts are like this one, though.
- “Produce as little code as possible” is in every builder’s instructions, which may make lean builds cut corners — the 40 ms HTTP floor is probably one. Robustness is reported next to size for that reason.
- Small systems. Each codebase is 20–55k tokens. Whether a framework’s conventions help an agent find its way around a large codebase is a different question, and this benchmark doesn’t answer it.
- One model. Everything here is Claude Opus 5.5.
So should you still pick Rails?
For an AI-written service, pick the framework for the humans who will read and run the code — its conventions, its security track record, its ecosystem, the plumbing bugs you won’t have — not because you expect the agent to build faster with it. Expect to pay for it twice: in tokens at build time, and in CPU at runtime. And if your contract is bespoke, budget for the adapter.
Part 1 compares the languages themselves, and what the extra code buys you in performance. Part 3 is about everything that went wrong in measuring this.