/SKILL.md
Analyzes and migrates barrel export patterns in TypeScript/React projects to reduce bundle size. Detects barrel files (index.ts re-exports), checks for side effects, measures bundle impact, and safely rewrites imports to direct paths. Proven to reduce page chunks by up to 19x in Next.js apps. Use when user mentions "analyze barrels", "check barrel exports", "migrate barrels", "fix barrel exports", "bundle size too big", "tree-shaking not working", "index.ts re-exports", or "optimize imports". Do NOT use for general import/export questions or ESM/CJS migration.
npx skillsauth add alexismunoz1/barrel-exports barrel-exportsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Detects barrel export anti-patterns and safely migrates to direct imports. Every recommendation is backed by real experiment data: barrel imports produced a 224 KB page chunk vs 11.7 KB with direct imports — a 19x difference in a controlled Next.js monorepo test. When presenting results, always include both your own measurements from the user's project and this 19x reference data point for context.
This skill operates in two phases:
You can run analysis alone (read-only, always safe) or follow up with migration.
When the user asks to analyze barrels, check barrel exports, or investigate bundle size, follow these four steps.
Search for index.ts and index.tsx files that primarily re-export from other modules:
# Find all index files
find src/ -name "index.ts" -o -name "index.tsx" | head -50
For each file found, read it and classify using exactly these terms in your report:
export * from or export { X } from statementsAlways use this taxonomy when reporting — it helps users understand the severity and gives them a shared vocabulary for discussing barrel patterns.
For the complete classification algorithm and side-effect taxonomy, see
references/analysis-guide.md
Inspect the project's bundler and package configuration. Go through every item in this checklist — don't skip any:
"exports" — subpath exports enable direct imports. If missing, this is a key recommendation."sideEffects" — tells the bundler what can be safely tree-shaken. If missing and barrels have no side effects, recommend adding "sideEffects": false."type": "module" — ESM enables better tree-shakingoptimizePackageImports (if Next.js) — Next.js's built-in barrel optimization. Always check for this explicitly and report whether it's present or missing.transpilePackages — required for monorepo internal packages"moduleResolution" — must be "bundler" or "node16" for subpath exportsIf the project uses Next.js, measure the current bundle:
npx next build 2>&1
Parse the route table from build output. Look for the First Load JS column — this is the total JS sent to the browser for each route. Record the baseline values.
Key metrics to capture:
+ First Load JS shared by all)Present findings in this format:
## Barrel Export Analysis
### Barrel Files Found: N
| File | Type | Exports | Side Effects | Risk |
|------|------|---------|-------------|------|
| src/index.ts | Pure barrel | 45 | None | High |
| src/components/index.ts | Pure barrel | 20 | None | Medium |
| src/utils/index.ts | Mixed | 12 | console.log | Critical |
### Configuration Issues
- ⚠️ No subpath exports configured
- ✅ `transpilePackages` includes internal packages
### Bundle Impact (if measured)
- Current First Load JS: 155 kB
- Estimated savings: 30-50% (based on barrel depth and export count)
### Recommendations
1. [Specific actions based on findings]
Risk levels:
When the user asks to migrate barrels, fix barrel exports, or optimize imports, follow these six steps. Always run Phase 1 first if analysis hasn't been done.
Always run a build and record baseline metrics BEFORE touching any imports. Without a baseline, you cannot prove the impact of the migration. This step is not optional.
npx next build 2>&1
Save the First Load JS values and page chunk sizes. You will compare against these numbers after migration to show the user concrete before/after improvement.
For each barrel file identified in analysis, find all files that import from it:
# Find all imports from a barrel path
grep -rn "from ['\"]@repo/ui['\"]" src/ --include="*.ts" --include="*.tsx"
grep -rn "from ['\"]./components['\"]" src/ --include="*.ts" --include="*.tsx"
Build a mapping: { consumer_file → [imported_names] → barrel_path → direct_path }.
Before rewriting any imports, verify that each target module file exists:
@repo/ui → @repo/ui/components/Button → packages/ui/src/components/Button.tsx ✓
@repo/ui → @repo/ui/hooks/useDebounce → packages/ui/src/hooks/useDebounce.ts ✓
If subpath exports are configured in the package's package.json, use those paths. Otherwise, use relative paths.
CRITICAL: Never auto-apply all changes. Process file by file.
For each consumer file, show the user the proposed change:
File: src/app/page.tsx
BEFORE:
import { Button, Card, Badge, IconHome, useDebounce, formatDate, cn } from "@repo/ui";
AFTER:
import { Button } from "@repo/ui/components/Button";
import { Card } from "@repo/ui/components/Card";
import { Badge } from "@repo/ui/components/Badge";
import { IconHome } from "@repo/ui/icons/IconHome";
import { useDebounce } from "@repo/ui/hooks/useDebounce";
import { formatDate } from "@repo/ui/utils/formatDate";
import { cn } from "@repo/ui/utils/cn";
Wait for user confirmation before applying each file. Group related files if the user prefers batch mode.
For detailed transformation rules covering type imports, namespace imports, re-exports, and edge cases, see
references/migration-guide.md
After import migration, review and update configuration. Even if some fields already exist, verify they cover all the direct paths you need:
package.json exports (of the library being imported):
{
"exports": {
".": "./src/index.ts",
"./components/*": "./src/components/*.tsx",
"./hooks/*": "./src/hooks/*.ts",
"./utils/*": "./src/utils/*.ts"
}
}
./components/*), verify the source files follow the expected naming convention.next.config.js (if Next.js, for external packages):
experimental: {
optimizePackageImports: ["@repo/ui"]
}
Run the build again and compare:
## Migration Results
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| First Load JS (/) | 155 kB | 106 kB | -31.6% |
| Page chunk (/) | 224 kB | 11.7 kB | -94.8% |
Verify:
npx tsc --noEmit| Scenario | Handling |
|----------|----------|
| Type-only imports (import type { X }) | Keep or convert to direct — types are erased at build, low impact |
| Dynamic imports (import("./barrel")) | Flag as high-risk — dynamic imports pull the entire barrel at runtime |
| Side-effect imports (import "./init") | Never remove — these run code on import, flag for manual review |
| Circular dependencies | Detect and warn — migration may expose hidden circular deps |
| External packages (lodash, etc.) | Use optimizePackageImports instead of rewriting — don't modify node_modules |
| Monorepo internal packages | Prefer subpath exports in package.json exports field |
| CSS/asset imports in barrels | Preserve as-is — these are side-effect imports |
| Default exports | Use import X from "./path" not import { default as X } |
import type has zero runtime cost, migration is optionaloptimizePackageImports for third-party, rewrite for internalreferences/analysis-guide.md — Detection methodology, side-effect taxonomy, and reporting formatreferences/migration-guide.md — Import transformation rules, edge cases, and rollback proceduresreferences/barrel-patterns.md — 7 anti-patterns catalog with experiment data and decision matrixdevelopment
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.