mcpField
L
ln-832-bundle-optimizer

ln-832-bundle-optimizer

github.com/levnikolaevichDevelopment584225 installsUpdated 2d ago
Repository

About ln-832-bundle-optimizer

A skill for optimizing JavaScript and TypeScript bundles by measuring build output and keeping only changes that reduce its size. It reports the resulting size delta and optimization attempts.

Key features

  1. 01Builds and measures a baseline bundle
  2. 02Finds unused dependencies and large packages
  3. 03Evaluates changes with keep-or-discard builds
  4. 04Reports size changes and removed dependencies

Use cases

  1. 01Reducing a JS/TS project's build output
  2. 02Checking whether a proposed optimization lowers bundle size

MCP support

The skill can use hex-graph and hex-line MCP tools when available for hotspot discovery and local reads; otherwise it falls back to built-in tools.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-832-bundle-optimizer

After installing, type/ln-832-bundle-optimizerin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
ci_tool_detection.md
coordinator_summary_contract.md
mcp_integration_patterns.md
mcp_tool_preferences.md
optimization_categories.md

Details

From the project README

Paths: File paths (references/, ../ln-*) are relative to this skill directory.

ln-832-bundle-optimizer

Type: L3 Worker Category: 8XX Optimization

Reduces JavaScript or TypeScript bundle size using keep/discard verification. JS/TS projects only.


Overview

AspectDetails
InputJS/TS project path plus optional optimization scope
OutputSmaller bundle plus a machine-readable modernization summary
ScopeJS/TS only

Workflow

Phases: Pre-flight -> Baseline -> Analyze -> Optimize Loop -> Report


Phase 0: Pre-flight Checks

CheckRequiredAction if Missing
package.json existsYesBlock optimization
Build command availableYesBlock optimization
Output directory (dist/ or build/) detectableYesBuild once to establish baseline
Workspace baseline safeYesIn managed runs coordinator already prepared it; in standalone runs protect rollback locally

MANDATORY READ: Load references/ci_tool_detection.md for build detection. Tool policy: follow host AGENTS.md MCP preferences; load references/mcp_tool_preferences.md and references/mcp_integration_patterns.md only when host policy is absent or MCP behavior is unclear.

Use hex-graph first when hotspots or clone groups materially improve optimization targeting. Use hex-line first for local code and config reads when available. If MCP is unavailable, unsupported, or not indexed, continue with built-in Read/Grep/Glob/Bash and state the fallback in the summary.

Runtime Coordination

Managed runs receive deterministic runId and exact summaryArtifactPath from ln-830. Standalone runs remain supported; if runtime arguments are omitted, generate a standalone run-scoped artifact before returning.


Phase 1: Establish Baseline

1. Run the detected build command.
2. Measure total size of the output directory.
3. Record baseline bytes and per-chunk sizes.
MetricHow
Total sizeSum all bundle output files except source maps
Per-chunk sizesMeasure individual JS and CSS files
Source map handlingExclude .map files

Phase 2: Analyze Opportunities

CheckToolWhat It Finds
Unused dependenciesdepcheck or equivalentPackages not imported anywhere
Bundle compositionBundle analyzerLarge dependencies or duplicates
Tree-shaking gapsManual scanNamespace imports or heavy entrypoints
Code splitting gapsRoute analysisLazy-load candidates

Optimization categories:

CategoryExampleTypical Savings
Remove unused depsdead dependencies10-50KB per package
Named importslodash-es named imports50-200KB
Lighter alternativesreplace heavy date or utility libs50-300KB
Dynamic importslazy-load heavy componentslower initial bundle
CSS optimizationremove unused CSS, minify10-100KB

Phase 3: Optimize Loop (Keep/Discard)

Per-optimization cycle:

FOR each optimization:
  1. APPLY the change
  2. BUILD
     IF build fails -> DISCARD and revert
  3. MEASURE new bundle size
  4. KEEP only if the bundle is smaller than the current baseline
  5. LOG the result

Stop conditions:

ConditionAction
All optimizations processedStop and report
3 consecutive discardsStop for plateau
Build infrastructure breaksRevert to last keep and stop
Bundle already below targetStop and report

Optimization order:

  1. remove unused dependencies
  2. improve tree-shaking and imports
  3. replace heavy libraries
  4. introduce code splitting
  5. optimize CSS

Phase 4: Report Results

FieldDescription
projectProject path
baseline_bytesOriginal bundle size
final_bytesFinal bundle size
reduction_bytesBytes saved
reduction_percentPercentage reduction
optimizations_appliedCount of kept optimizations
optimizations_discardedCount plus reasons
deps_removed[]Dependencies removed
details[]Per-optimization savings
artifact_pathDurable worker report path, if written

Configuration

Options:
  build_command: ""             # Auto-detect
  output_dir: ""                # Auto-detect
  run_depcheck: true
  run_bundle_analyzer: false
  remove_unused_deps: true
  fix_tree_shaking: true
  replace_heavy_libraries: true
  enable_code_splitting: true

Error Handling

ErrorCauseSolution
Build fails after optimizationInvalid code or config changeRevert that optimization
No size reductionOptimization ineffectiveDiscard it
Analyzer unavailableTooling missingContinue with manual inspection

References


Runtime Summary Artifact

MANDATORY READ: Load references/coordinator_summary_contract.md

Emit a modernization-worker summary envelope.

Managed mode:

  • ln-830 passes deterministic runId and exact summaryArtifactPath
  • write the summary to the provided summaryArtifactPath

Standalone mode:

  • omit runId and summaryArtifactPath
  • write .hex-skills/runtime-artifacts/runs/{run_id}/modernization-worker/ln-832--{identifier}.json

Monitor (2.1.98+): For build commands in keep/discard loop expected >30s, use Monitor. Fallback: Bash(run_in_background=true).

Definition of Done

  • Baseline bundle size established from real build output
  • Optimization opportunities analyzed from bundle composition and project usage
  • Each optimization evaluated with keep/discard verification
  • Only size-reducing optimizations kept
  • Final report captures bundle delta, discarded attempts, and removed dependencies
  • modernization-worker summary artifact written to the managed or standalone path

Version: 1.0.0 Last Updated: 2026-03-08

Comments

Markdown supported