What the agent does
The agent reads how the app is built and what ends up in it. In a React app laid out like alan2207/bulletproof-react's apps/react-vite, package.json builds with tsc && vite build --base=/ on Vite 5 and runs tests with Vitest, and vite.config.ts sets base: './', excludes fs/promises from the bundle and sets experimentalMinChunkSize: 3500 for Rollup's output. src/app/router.tsx loads every route with a dynamic import, so the build already emits one chunk per route beside the entry. .github/workflows/react-vite-ci.yml moves .env.example into place, installs with yarn, builds, tests, lints and type-checks, and nothing reads the size of what the build produced. .env.example turns VITE_APP_ENABLE_API_MOCKING on, and src/main.tsx calls enableMocking, which imports the MSW worker and the mock database only when that flag is set, so the mocks are a separate chunk that the CI build includes and a production build without the flag does not.
It measures before it sets anything. The agent runs yarn build in its sandbox and lists every file under dist/assets with its raw and gzip size, then runs the build again with VITE_APP_ENABLE_API_MOCKING=false to see which chunks exist only for the mocks, and puts both tables in the pull request. It reads the largest chunks with rollup-plugin-visualizer, added as a dev dependency and run once with its json output, to name which packages fill them; marked and dompurify behind md-preview, the Radix dialog and dropdown packages, and @tanstack/react-query are the candidates it expects from the dependency list, and the report says what it actually found.
Then the budget. It adds size-limit with the @size-limit/file preset, which measures a built file's gzip size with no second bundling, and a .size-limit.json with one entry per chunk pattern: the entry chunk, each route chunk by its name prefix, and the vendor chunks the visualizer identified. Each entry's limit is the measured size plus a margin the agent states in the description, so the budget is a line the current build is already under and not a number picked in the abstract. A size script runs size-limit, and a step after yarn build in the CI workflow runs it, so a pull request that pushes a chunk over its line fails the job with the chunk's name and the overage.
Where the measurement shows one chunk carrying a package only one route uses, the agent adds a manualChunks entry under build.rollupOptions.output to split it, rebuilds, and shows the before and after; it does not move @ngneat/falso or other test-only packages out of dependencies, since the bundle is decided by imports and not by the dependency group, and it says so. It runs yarn test, yarn lint and yarn check-types as the workflow does and keeps the output.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add a bundle size budget. Read apps/react-vite/package.json, apps/react-vite/vite.config.ts, apps/react-vite/src/app/router.tsx, apps/react-vite/src/main.tsx, apps/react-vite/src/testing/mocks/index.ts, apps/react-vite/.env.example and .github/workflows/react-vite-ci.yml first. Run yarn build with mocking on and off and list every chunk in dist/assets with raw and gzip sizes. Add rollup-plugin-visualizer as a dev dependency, run it once with JSON output, and name the packages behind the largest chunks. Add size-limit with the @size-limit/file preset and a .size-limit.json with one entry per chunk pattern, each limit set to the measured gzip size plus a margin you state, add a size script, and run it after the build step in the CI workflow. Where one route's package sits in a shared chunk, add a manualChunks entry and show the sizes before and after. Run yarn test, yarn lint and yarn check-types, and open a pull request with both size tables and the size-limit output.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request that adds .size-limit.json, two dev dependencies and a size script, changes vite.config.ts if a chunk was split, and adds one step to react-vite-ci.yml. The description carries the chunk table with and without mocking, the packages behind the largest chunks from the visualizer, each budget with the measured size it was set from and the margin, and the size-limit output passing on the current build.
The run's record keeps every build and the size tool's output, so a reviewer reads the real sizes rather than a summary. A reviewer checks that the margins are tight enough to catch a dependency that doubles a chunk and loose enough that a copy change does not fail CI, and that the CI step runs on the same build the workflow already makes rather than a second one.
Run it on every Vite app without a size budget
A team with several Vite apps starts one run per repository with one POST /o/{org}/sessions each, this prompt as input and the repository in resources. Each run measures its own build, so no two repositories get the same numbers, and an app that already runs size-limit gets only a re-measured file and a description of what grew since the limits were set.
Send a request_id that is a UUID v5 of the repository's full name so a retried call returns the run it already started. The key's webhook_url reports when each run finishes, with session_url to read the pull request from.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
A size budget is only as good as the measurement it was set from, and the measurement needs a real build with the real flags, twice, and a map of which package sits in which chunk. That is an afternoon of reading build output, which is why most apps have no budget and find out about the extra megabyte from a user. The agent does the builds in its sandbox, keeps every table, and sets each line from a number it read, so the pull request can be checked against the output instead of trusted.
The pull request is one JSON file, one script and one CI step, so review is reading the margins. A company with several front ends runs this on all of them at once, each in its own sandbox with its own pull request.
Frequently asked questions
Why size-limit rather than Vite's own chunk warning?
Vite's chunkSizeWarningLimit prints a warning and never fails the build, and it measures before gzip. size-limit with the file preset measures the gzip size of the files the build already wrote and exits non-zero over the limit, which is what a CI step needs.
Why measure with mocking off too?
Because CI builds with .env.example, which enables MSW, so the CI build carries the mock worker and database as chunks a production build never ships. The budget file names those chunks separately so a change to the mocks does not read as growth of the app.
Will moving test packages to devDependencies shrink the bundle?
No. Vite includes what the entry imports, and @ngneat/falso is imported only from src/testing, which the mocks chunk reaches when the flag is on. The group a package is listed under changes nothing in the output, which the two tables show.
What happens when a budget fails?
The CI step prints the chunk and how far over it is. The developer either splits or drops the import, or raises that line in .size-limit.json in the same pull request, where the reviewer sees the new number. The agent describes that choice in the description.