The Claude prompt that made our CI 3x faster and cut its bill by more than half

Ugur Tas

Published on Dec 4, 2026

Bar chart: the same pull request, with the same 2,107 tests, took 5m 50s on the old CI and 1m 11s on the new one. Billed minutes for that run went from 6 to 2.

Our CI took four minutes to tell a pull request anything. A type error showed up only after two and a half minutes of tests. The lint step passed, but only because it had continue-on-error set. Underneath it were 20 errors that nobody saw.

This post explains how we got the same checks, plus stricter ones, down to about 80 seconds. It also explains how we cut the GitHub Actions bill by more than half. Every number here comes from real CI runs. The brief we started from is at the end of the post.

One pull request, before and after

These are two CI runs of the same feature branch, one day apart. The first run used the old CI, and the second run used the new one. Both runs checked the same 178 test files and 2,107 tests. The branch has more tests than the main branch, so its old runs were slower than the old median.

GitHub’s run page shows the job time and the test summary of each run. On the old CI, the job took 5m 44s:

GitHub Actions run on the old CI. Its one job took 5m 44s, and its Vitest summary shows 178 test files and 2,107 tests passing.

On the new CI, the job took 1m 4s for the same 178 test files and 2,107 tests:

GitHub Actions run on the new CI. Its one job took 1m 4s, and its Vitest summary shows 178 test files and 2,107 tests passing.

The table splits both runs by step:

StepOld CINew CI
Setup, until the first check27s24s
Lint14s1s
FormatNo stepUnder 1s
Typecheck21s1s
Tests4m 13s23s
App build16s8s
Blog install and build11s3s
Job5m 44s1m 4s
Run, total5m 50s1m 11s
Billed minutes62

The old run spent 4 minutes and 13 seconds in tests on one core. The new run spent 23 seconds in tests. GitHub bills the old job’s 5 minutes and 44 seconds as 6 minutes. It bills the new job’s 64 seconds as 2 minutes, because the job ran 4 seconds past the 1-minute line.

The project

The project is a mid-sized single-page app written in React and TypeScript and built with Vite. It has about 1,800 Vitest tests in 160 files, and the tests run in jsdom. A small Astro blog builds next to the app. CI ran as one job on GitHub Actions’ hosted runners. The job installed packages, then ran lint, typecheck, tests, and the build, one after another.

An AI coding agent, Claude Code, did the work from one written brief. It opened one small pull request per change, and each pull request had before and after numbers from real runs. We reviewed and merged them.

Two rules came before speed

The brief set two targets. At the median (p50), a pull request gets its result in under 2 minutes. At the 95th percentile (p95), it gets its result in under 3 minutes. Two rules came before those targets:

  1. Never get faster by hiding failures. That means no retries, no wider timeouts, and no skipped tests. A check that needs a retry has a bug. Find the bug.
  2. The full suite runs before anything reaches the main branch. Running only the affected tests can make pull request feedback faster. It never replaces the full run.

A third rule covered tools. The brief named fast new tools as the defaults, and keeping an old tool needed a measured reason. Before any switch, the old and the new tool ran side by side, and we listed what the new one missed.

Measure where the time goes

Before changing anything, we pulled the last 130 runs. We split every job into three parts: waiting for a runner, setup, and running. Setup covers the checkout, installing Node, and npm ci.

Partp50p95
Waiting for a runner3s4s
Setup54s72s
Running193s260s
Tests, within running146s201s
Total241s335s

Two things stood out. First, everything ran in sequence, so a pull request waited for the sum of all checks. Second, the tests were the biggest part, and they ran on one CPU core. The hosted runner has 2 cores, and Vitest’s default number of workers is the number of cores minus one.

Run in parallel on every core

We split lint, typecheck, build, and three test shards into separate jobs. Vitest got one worker per core. Wall time went from 241s to 147s.

With two workers, two tests timed out, at 7.2s and 5.1s. The easy fix is a longer timeout, and the first rule forbids it. Profiling showed that the tests weren’t flaky. They were CPU-bound. The dropdown under test had about 420 time-zone options, and getByRole('option', { name }) computes an accessible name and the computed styles for each one.

Reading the options from the open listbox does the same check in 365ms instead of 1,160ms. A missing option still fails, and the message names the option.

Cache the node_modules folder itself

Setup was mostly npm ci, and after the split it ran in all six jobs. We cached the node_modules folder itself instead of npm’s download cache. The cache key includes the lockfile, the OS, the CPU architecture, and the Node major version.

We seed these caches from the default branch. A branch can read its own caches and the caches of the default branch. Seeding on the default branch therefore makes even the first run of a pull request a cache hit.

Checkout became a blobless clone with full history. The setting is filter: blob:none. Locally, a blobless clone took 1.3s, and a clone with a depth of 1 took 2.6s. The blobless clone also keeps the history that the diff-based steps need.

BeforeCache hit
Setup per job49 to 63s10 to 19s
Wall time147s84s

Replace ESLint with oxlint, and make lint block

ESLint took 9s at p50 and hid 20 errors. We fixed the 20 errors and made lint block the build. Then we switched to oxlint and turned on every category of every plugin that fits the project. The total was 504 rules. The 238 rules that report problems in today’s code are listed as off, each with its report count. Each count shows how much work it takes to turn that rule on.

We ran both linters side by side on the same code. They agreed on 35 findings. oxlint missed three findings that ESLint reported as warnings, and it found two problems that ESLint missed.

Lint went from 9s to 1s in CI, and from 3.2s to 0.07s locally. Later we turned on the 26 type-aware rules that pass on today’s code. With type information, lint takes about 1.5s.

Typecheck with TypeScript 7, then with bun check

tsc 5.8 took 16s at p50. TypeScript 7, the native compiler, took 4s. Before the switch, we compared the two compilers on a clean tree, on four planted errors, and on 69 strict-mode diagnostics. The results were identical.

bun check arrived in bun 1.4.3. It runs TypeScript 7 inside bun. We compared again, on 723 strict-mode diagnostics. bun check reported each one with the same file, line, column, and error code as tsc. In CI, it takes 0.5 to 1.0s.

Stop rebuilding jsdom for every test file

With Vitest’s default isolation, each of the 161 test files got a new jsdom and imported every dependency again. We turned isolation off with isolate: false. A worker now keeps one jsdom and the loaded node_modules, and it runs one file after another. We also reset the state after every file. The reset exposed leaks that isolation had hidden:

  • Testing Library registers its DOM cleanup when it is first imported. Only the first file in each worker got the cleanup.
  • A vi.mock call in one file didn’t reach modules that another file had already loaded. Now the app’s own modules load again for every file, and node_modules stays loaded.
  • 10 files stubbed globals and never restored them.

Tests now also run in random order. The run prints its seed first, so you can replay any failure. We wrote the cleanup rules into the repository’s instructions for coding agents, so new tests follow them. Across 11 random seeds and 1 to 4 workers, all 1,764 tests passed every time.

Isolatedisolate: false
Local, 1 worker92s39s
CI test shards59s, 82s, and 69s24s, 39s, and 23s
CI wall time113 to 119s57s

Switch to bun, format with oxfmt, and add a pre-push hook

bun replaced npm. We checked that bun installs the same 686 packages as npm, with every name and version the same. On a cache miss, the install went from 17s to between 2s and 3s. In one run, a single bun install stalled for 263s on one download. The time budgets in the next section catch that kind of stall.

oxfmt became the formatter. The repository had no formatter before. The one-time reformat touched 478 files and caused the most serious failure we found. Formatting index.html broke the build-time SEO prerender, because its regular expressions expected each <meta> tag on one line. Lint, types, tests, and the build all passed, while 76 pre-rendered pages lost their titles and descriptions. We excluded index.html from formatting. Then we compared the <head> of every page byte for byte with the previous build.

A pre-push hook checks each push. It runs format, lint, and typecheck on the files that the push changes, in 0.9s. We chose a hook over a line in the README because people and agents both skip steps.

Fail the job when a step goes over its budget

CI gets slower a few seconds at a time, so every step has a time budget. A step that goes over its budget fails the job. These are the budgets:

StepBudget
Waiting for a runner10s
Setup30s
Lint5s
Format5s
Typecheck5s
Tests60s
App build30s
Blog build20s

Each job also has a 5-minute timeout, so a hung job can’t run for GitHub’s default of six hours.

One budget started above its target on purpose. On the 2-core x64 runners, TypeScript 7 took 4 to 9s, so a 5s budget would have failed at random. A check that fails at random is a new flaky check. The typecheck budget started at 10s and dropped to 5s when the measurements allowed it.

A second budget showed a flaw in how we checked budgets. A cache download stalled, and setup took 32s of its 30s budget. The budget check ran inside the setup step, so the setup step failed and every check after it was skipped. The pull request got a failed run with no lint, type, or test results. Now the setup budget is a separate step. A slow setup still fails the job, and every check still runs and reports.

Affected-only tests stay off without a merge queue

For pull requests, we built test selection. Selection runs only the tests that the changed files can reach, with vitest --changed. Then, as the brief asked, we hid a real breaking change from selection on purpose. The change was to the CI configuration. It broke 5 tests, and it sat outside the import graph of every test.

With Vitest’s default triggers, selection found no test files, and the run passed. Only the full suite caught the break. With config and lockfile changes added to the triggers that run every test, selection catches this case.

The experiment still shows that selection is safe only when the full suite is certain to run before merge. A merge queue gives that certainty. A merge queue in a private repository needs GitHub Enterprise Cloud, and the project is on the Free plan. Selection is built and tested, and it stays switched off.

At this point, pull requests got results in 45 to 65 seconds. Then we looked at the bill.

You pay for billed minutes, not wall time

GitHub bills every job rounded up to a whole minute. Five parallel jobs of 21 to 60s each bill 5 minutes per run. The old single job averaged 4.1 billed minutes, so the parallel version cost more. The organization is on GitHub’s Free plan, with 2,000 included minutes a month for all of its repositories. It already used about 1,620 of them. This repository used 705 in November.

We traded some speed for fewer billed minutes:

  • One job again. The job contains every change above. Every step after setup runs even when an earlier step fails, so one run still reports every failure.
  • arm64 runners. On x64 runners, the single job took 87 to 126s because the speed of the runners varied a lot. A 126s run bills 3 minutes. On ubuntu-24.04-arm, the job took 81 to 90s and billed 2 minutes every time. Past the free quota, an arm64 minute costs $0.005 and an x64 minute costs $0.006, according to GitHub’s runner pricing. A 115s job budget fails any run that heads into a third billed minute.
  • Fewer runs. CI now runs on pull requests instead of on every branch push. In the previous month, 22 of 159 runs were for branches that nobody was waiting on. Pushes that change only docs skip CI. The cache-seeding job runs twice a week instead of every weekday.
BeforeParallel jobsOne arm64 job
Billed minutes per run4.152
Pull request result241sabout 60sabout 90s

Replaying the previous month’s 159 runs through the new triggers leaves 126 runs. Billed minutes go from 705 to about 310 a month.

Profile the tests

The job now took 70 to 98s, and the tests were still the biggest step. Their time also depended on the machine. GitHub’s arm64 runners use at least two CPU models, so the same suite took between 29s and 49s.

A CPU profile showed where the time went. Testing Library’s *ByRole queries compute the accessible name of every element with the queried role. Computing the name calls jsdom’s getComputedStyle on each node. On jsdom 20, each call costs about 0.3ms. In one large test file, 17,782 calls took 5.7s of the file’s 9.9s.

jsdom 31 does the same work in about two thirds of the time. We measured both versions on one runner and alternated them, so the CPU model couldn’t skew the result:

Run 1Run 2
jsdom 2046.7s47.1s
jsdom 3130.4s33.9s

Moving from Node 22 to Node 26 took another 3 to 4s off the tests and about 1.3s off the build. The Node version now comes from a .nvmrc file, so developer machines and CI use the same version. The feature branch from the start of this post now runs its whole job in 64s, with the tests at 23s.

One test failed only on developer machines. Vitest loaded the local .env file, and the usual development setup points the app at the live API. One line of config, envDir: false, makes the tests see what CI sees.

Before and after

MeasureBeforeAfter
Pull request result241s p50, 335s p95about 70 to 90s*
Lint9s, with 20 errors hiddenabout 1.5s, blocking, with 530 rules
Typecheck16s0.5 to 1.0s
Tests146s on one core23 to 34s
Setup54sabout 20s
Billed minutes per run4.12
Billed minutes per month705about 310, projected

*These times come from individual runs since the change. We will measure the p50 and p95 over a week of real runs.

Three parts of the brief need money or an account

If your organization is on GitHub’s Free plan, you can skip this section. Each item below needs a paid GitHub plan or a third-party service.

The brief asked for anything that needs money or an account to come back as a list. Three items are on that list:

  • A merge queue. It guarantees that the full suite runs before every merge, and it lets affected-only tests turn on. In a private repository, it needs GitHub Enterprise Cloud.
  • Blacksmith runners. They would move CI off GitHub’s minute quota, and Blacksmith’s free tier has 3,000 minutes a month. An organization owner has to install the Blacksmith app.
  • 8-core test machines. They need Blacksmith or a paid GitHub plan.

What we learned

  • The audit picked the first fix. It showed that the tests were the biggest part and that they ran on one of two cores.
  • Every flaky-looking test had a cause. The causes were a CPU-bound query, a cleanup that ran once per worker, stubs that were never restored, and a local .env file.
  • Passing checks missed real failures twice. Lint passed for months with 20 errors under it. The reformat broke the SEO of 76 pages while every check passed.
  • A safety net needs a planted failure. Hiding a breaking change from test selection showed that selection alone would have let it through.
  • Speed and cost pulled in different directions. Parallel jobs gave the fastest results and the biggest bill. One job on arm64 runners is about 30 seconds slower and bills 2 minutes per run instead of 5.

The brief

This is the prompt we gave the agent. We fixed typos and formatting, and we removed the line that moved every job to Blacksmith runners.

Make this repo’s CI as fast as possible without letting it lie. Target: a PR gets its result in under 2 minutes at the median and under 3 at p95.

Two rules outrank speed:

  • The full suite runs before anything reaches main, in a merge queue. Selection only narrows PR feedback.
  • Never get faster by hiding failures. No retries, wider timeouts or skipped tests. A check that needs a retry has a bug; find it.

First, audit. Pull the last 150 runs and split every job into waiting, setup and running, at p50 and p95. Fix the biggest bucket first. It is rarely the tests, so don’t spend time deleting them.

Then hit these budgets:

  • Waiting, under 10 seconds: a 5-second job that queues 10 minutes is a 10-minute job. Cancel a branch’s in-progress run when a new commit lands.
  • Setup, under 30 seconds: get PR cache hits above 95% by seeding caches from main. Cache node_modules itself, not just the package cache. Use a blobless clone (filter: blob:none), not a shallow one.
  • Lint, under 5 seconds: oxlint. Delete ESLint, and turn on every rule you can.
  • Typecheck, under 5 seconds: bun check. Fall back to TypeScript 7 if it can’t check this repo. Use tsrs locally.
  • Format: oxfmt. Delete Prettier.
  • Install and scripts: bun. Delete npm, yarn or pnpm.
  • Tests, under 60 seconds per shard: stop reloading the app per test file (Vitest isolate: false), reset state after every file, and write the cleanup rules into AGENTS.md. Run in random order to flush out leaks. Shard by measured duration onto 8-core machines, each with its own database. Buy cores before shards, and match concurrency to cores.
  • Shape: run lint, typecheck, build and tests in parallel. Then move migration checks and other apps’ tests out of the slowest job into their own.
  • Selection: on PRs, run only what the diff can reach (nx affected or turbo affected). Then hide a real change from it on purpose and confirm CI goes red, not green.
  • Local, under 9 seconds: a pre-push hook that runs format, lint and typecheck on changed files. A hook, not a line in AGENTS.md, because agents skip steps.
  • Keep it fast: fail any job that exceeds its budget.

The tools above are defaults; you need a measured reason to keep an old one. Take anything newer that is faster on this repo. Before each switch, run old and new side by side and list anything the new one misses.

One small PR per change, with before and after numbers from real runs. Do everything you can without me first; bring anything that needs an account, a secret or a bigger bill as one list with expected monthly cost. End with total CI time and cost, before and after.

Back to Blog

Related Posts

View All Posts »
Mastering Concurrency in Kotlin

Mastering Concurrency in Kotlin

A deep dive into Kotlin concurrency using coroutines, exploring structured concurrency and efficient asynchronous programming techniques.