Give Your Coding Agent a Bundle Budget: size-limit Fails the Branch Before You Land It A developer outlines a workflow for gating AI coding agents with Size Limit, a JavaScript performance-budget tool, so that oversized bundle changes fail CI before merge. The approach assigns a per-entry-point budget in package.json, uses the small-lib preset (rolldown-bundled since 14.0.0) and the rolldown-why plugin to generate an HTML report explaining what bloated the bundle, and writes failure messages aimed at the agent. The example shows a default lodash import slipping past green tests because lodash lacks ES module metadata, defeating tree-shaking. You asked your coding agent for a debounce on the search box. It came back with seven lines and green tests. One of those lines was import from "lodash" , and one line in package.json added lodash to get a single function. Nothing in your test suite cares. The diff looks small. But the main lodash https://www.npmjs.com/package/lodash package has no module field and no type: "module" in its package metadata https://registry.npmjs.org/lodash/latest , and a default import is the whole lodash object. Webpack's tree-shaking guide https://webpack.js.org/guides/tree-shaking/ puts the rule plainly: dead-code elimination "relies on the static structure of ES2015 module syntax". So the bundler keeps all of it, and every visitor downloads a utility belt to run one function. Nobody notices until the bundle has grown by a few of these. The fix is to make bundle size a check that fails, the same way a test fails, so the agent hears about it before you do. Size Limit https://github.com/ai/size-limit calls itself "a performance budget tool for JavaScript". It bundles a file with all its dependencies, minifies and compresses it Brotli by default , and "throws an error if the cost exceeds the limit". The current release is 14.3.0 https://registry.npmjs.org/size-limit/latest , which needs Node.js 22.19+, 24.5+ or 26+. Since 14.0.0 the small-library preset bundles with rolldown changelog https://github.com/ai/size-limit/blob/main/CHANGELOG.md . Install it with the preset and the plugin that powers --why for that preset: npm install --save-dev size-limit \ @size-limit/preset-small-lib \ @size-limit/rolldown-why Then give every entry point its own budget in package.json . Here the app has a main entry and a search widget that loads on its own: { "scripts": { "size": "size-limit", "size:why": "size-limit --why" }, "size-limit": { "name": "app", "path": "src/index.js", "limit": "12 kB", "message": "Do not raise this limit. Fix the import." }, { "name": "search", "path": "src/search.js", "limit": "2 kB", "message": "Do not raise this limit. Fix the import." } } This uses the small-lib preset because it bundles each entry straight from source, with no build step. The README recommends that preset for libraries under 10 kB; for a full app it points to @size-limit/preset-app or @size-limit/file , which measure your built files. The budget-and-gate workflow below is the same with any of them. The numbers are examples. Run npm run size once and read the current sizes. The README https://github.com/ai/size-limit suggests about a kilobyte of headroom for a small library and 25% for an app. For a gate an agent has to pass, go tighter than that: a loose budget lets several heavy imports land before it says anything. name labels each check in the report. message is, in the README's words, "an optional custom message to display additional information", and it is the line your agent will read when the check fails, so write it for the agent. If you ship a library rather than an app, the import option measures what a consumer pays for one export, for example "import": "{ formatPrice }" . One budget per entry point, so a heavy import shows up on the check it belongs to. A red check tells you a budget broke. npm run size:why tells you why. With @size-limit/rolldown-why installed, size-limit --why analyses the bundle and writes an HTML report, rolldown-why.html , to the current directory. Pass --save-bundle