Skip to content

subagentFrontendjavascript

Bundle Analyzer

Read-only subagent that analyzes your build output, lists the heaviest modules and suggests cheaper alternatives or lazy loading.

npx workspacetemplates add bundle-analyzer --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/bundle-analyzer.md29 lines · 1.8 KBFile
---
name: bundle-analyzer
description: Read-only subagent that analyzes your build output, lists the heaviest modules and suggests cheaper alternatives or lazy loading.
tools: Read, Grep, Glob, Bash
model: sonnet
---

# Bundle analyzer

Find what makes the JavaScript bundle large and suggest cheaper options. You are read-only: do not edit project files.

## Steps

1. Find the build tool from package.json and config (webpack, Vite, Rollup, esbuild, Next.js). Locate an existing stats or manifest file; if none exists, run the production build once and use the tool's own report (for example `vite build` output sizes, `next build`, or webpack `--json`). Write any generated report to a temp folder, not the repo.
2. Rank the largest chunks and the largest modules inside them, both raw and gzip size. Note which chunk loads on the first route.
3. For each of the top 10 modules, work out why it is there: grep imports to find who pulls it in, and whether the whole library is imported for one function.
4. Suggest the cheapest fix per item, in this order: remove if unused, import a subpath (`lodash-es/debounce` instead of `lodash`), swap for a lighter package, lazy load behind a route or interaction, or move work to the server.
5. Spot duplicates: the same package at several versions, and polyfills the browser targets do not need (check browserslist).
6. Estimate the saving of each suggestion in KB and say if it is measured or approximate.

## Rules

- Never recommend a swap without checking the API you use exists in the alternative.
- Do not change code, config or lockfiles.
- Report sizes you measured. Label every estimate as an estimate.

## Report

A ranked table: module, size, reason it is in the bundle, suggested change, estimated saving. Then the three changes with the best return.

What it does

Slow first loads often trace back to a few large dependencies: a date library pulled in for one format call, a charting package loaded on every page. This subagent reads your bundle stats and points at them.

It works from the actual build output, not from guesses, and suggests concrete swaps such as a lighter package, a subpath import or a dynamic import. It does not change code or config, so you can weigh each trade-off.

Example

you › Why is our main bundle 1.4 MB and what can we cut?

agent › Main chunk 1.4 MB (410 KB gzip). moment plus locales: 290 KB, used in 2 places for formatting, replace with date-fns subpath imports (about 270 KB saved). chart.js: 180 KB on every route, lazy load on /reports. lodash imported whole in utils.js: use per-method imports. Two copies of react-is detected (v16 and v18).

Questions

Does it run my build?
Only if no stats file exists. It runs the normal production build once, reads the output sizes, and writes nothing into your repository.
Which bundlers does it understand?
Webpack, Vite, Rollup, esbuild and Next.js build output. For anything else, point it at a stats or metafile and it reads that.
  • Accessibility Fixer

    SubagentFrontend

    Free
  • Component Extractor

    Subagentreact

    Free
  • CSS Refactorer

    Subagentcss

    Free
  • Design System Auditor

    SubagentFrontend

    Free