bundle-safety — Claude Code skill for bundle checks
The bundle-safety skill guides bundle minification checks, identifier preservation, and namespace re-export coverage. Use it before build changes that could rename or remove code.
MIT ★ 539 updated 2026-10-29
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a claude-codeWhat bundle-safety does
The skill sets an order for validating build transforms: create the smallest test bundle, run the consumer-constraint checks, then run build conformance tests. The project checks include grep guardrails and stack-trace readability. One failed guardrail blocks the change from being merged.
The standard minification keeps identifiers intact, using --minify-whitespace and --minify-syntax without --minify-identifiers. Renaming can break 13 checks and make runtime errors harder to trace. The skill says to enable identifier mangling only under a documented exception approved by the team.
For export-tracking changes, test both export * from './module' and export * as ns from './module'. The skill points to tests/unit/tools/repo-graph-reexports.test.ts; skipping the aliased form can leave gaps in graph and dead-export analysis. Its checks refer to this project’s specific tests and paths.
What it helps with
- choose a minification setup that keeps identifier names intact
- check proposed transforms against consumer constraints before merging
- catch unreadable stack traces after a build change
- test regular and aliased namespace re-exports
Example prompts for the agent
- Check the proposed bundle minification flags and run the required tests before merging.
- Verify that function names remain readable in stack traces after the transform.
- Test both namespace re-export forms in
tests/unit/tools/repo-graph-reexports.test.ts.
How to install bundle-safety
1Skills CLI (Vercel)
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a claude-code2Manually: put the files in place
~/.claude/skills/bundle-safety/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/bundle-safety/
1Skills CLI (Vercel)
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a codex2Manually: put the files in place
.agents/skills/bundle-safety/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a cursor2Manually: put the files in place
.cursor/skills/bundle-safety/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install ZaxbyHub/opencode-swarm .opencode/skills/generated/bundle-safety2Manually: put the files in place
.github/skills/bundle-safety/SKILL.md1Skills CLI (Vercel)
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a gemini-cli2Platform CLI
gemini skills install https://github.com/ZaxbyHub/opencode-swarm --path .opencode/skills/generated/bundle-safetyManually: put the files in place
.devin/skills/bundle-safety/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about bundle-safety
How do I install bundle-safety in Claude Code?
Run npx skills add ZaxbyHub/opencode-swarm --skill bundle-safety -a claude-code. The skill file is at ~/.claude/skills/bundle-safety/SKILL.md.
What does bundle-safety do?
It guides checks for bundle transforms, identifier preservation, and namespace re-export tracking. Before a change is merged, it requires the relevant build constraints and stack traces to pass validation.
Why does bundle-safety reject --minify-identifiers by default?
Mangling can break 13 grep guardrails and obscure function names in runtime stack traces. The skill permits it only with a documented exception approved by the team.
Source text
SKILL.md · MIT
---
name: bundle-safety
description: Bundle transform safety — minification variant selection, consumer-constraint verification, identifier preservation, and namespace re-export coverage for build output.
metadata:
triggers: '["minify","minification","bundle","esbuild","build size","re-export","identifier","namespace re-export","exportLines","exportRanges","dist/index.js"]'
generated_from_knowledge: '["5746c5c9-1330-4fbe-b62e-f564deb1ff77", "5d99affe-bdd1-4945-8cd8-fcf37abb8c84", "9323a8f0-c07e-41c2-9857-11a24c55dca2"]'
source_knowledge_ids: '["5746c5c9-1330-4fbe-b62e-f564deb1ff77", "5d99affe-bdd1-4945-8cd8-fcf37abb8c84", "9323a8f0-c07e-41c2-9857-11a24c55dca2"]'
generated_at: "2026-07-02T20:47:50.522Z"
confidence: "0.60"
status: active
version: "1"
skill_origin: generated
---
<!-- generated by opencode-swarm skill-generator. Do not edit by hand; edits will be preserved on regeneration only with controlled update mode. -->
# Bundle Safety
## Trigger
- minify / minification / bundle / esbuild / build size
- re-export / namespace re-export / exportLines / exportRanges
- dist/index.js conformance checks
- identifier preservation / stack trace readability
- consumer-constraint verification before transforms
## Required Procedure
### (a) Minification Variant Selection
The standard minification configuration for the plugin bundle is **identifier-preserving**:
```
--minify-whitespace --minify-syntax
```
This yields ~22.3% size reduction on the main bundle (~1.28 MB absolute). The reduction is below the optimistic 35–43% range because **identifier mangling is deliberately skipped**.
**Full identifier mangling (`--minify-identifiers`) is REJECTED.** It breaks two hard constraints:
1. **13 grep guardrail assertions** — split across `tests/unit/build/full-auto-toolbefore-fail-closed.test.ts` (fail-closed hook substring/wrapping checks) and `tests/unit/turbo/lean/runtime-conformance.test.ts` (Lean Turbo identifier-preservation checks). Mangling would rename these identifiers and cause all 13 assertions to fail.
2. **Stack-trace readability** — preserved identifier names are required for runtime debugging. The release-gate test `tests/unit/build/throw-and-verify-located.test.ts` asserts that thrown errors carry readable stack frames with recognizable function names (e.g. `initializeOpenCodeSwarm`).
**Decision is final:** identifier-preserving minify is the standard. Do not enable `--minify-identifiers` without a documented exception approved by the team.
### (b) Consumer-Constraint Verification Before Transforms
Before merging any minification or transform change:
1. **Build the smallest possible test bundle** with the proposed transform flags.
2. **Run the consumer's exact constraint check first** — the 13 grep guardrails are split across `tests/unit/build/full-auto-toolbefore-fail-closed.test.ts` (fail-closed hook constraints) and `tests/unit/turbo/lean/runtime-conformance.test.ts` (Lean Turbo identifier-preservation checks). Together they are the authoritative consumer constraint.
3. **Run the full build conformance suite** (`tests/unit/build/throw-and-verify-located.test.ts`, `tests/unit/turbo/lean/runtime-conformance.test.ts`) to verify runtime integrity and stack-trace readability.
4. **Only merge if all guardrail assertions pass.** A single grep guardrail failure blocks the change.
This procedure applies to any transform that could rename, inline, or remove identifiers — not just minification flags.
### (c) Identifier-Preservation Testing
Verify identifier names survive the transform via the layered test stack:
**Static (grep) layer:**
- `tests/unit/build/full-auto-toolbefore-fail-closed.test.ts` — fail-closed hook substring/wrapping checks verifying that specific identifier substrings (e.g. `fullAutoPermissionHook.toolBefore`, `guardrailsHooks.toolBefore`, `scopeGuardHook.toolBefore`, `delegationGateHooks.toolBefore`) are present and that fail-closed hooks are not wrapped in `safeHook(...)`.
- `tests/unit/turbo/lean/runtime-conformance.test.ts` — `distContains()` checks verifying that Lean Turbo integration-point identifiers (`verifyLeanTurboPhaseReady`, `verifyLeanTurboTaskCompletion`, `LEAN_TURBO_BANNER`, `enableLeanTurbo`, `hasActiveTurboMode`) survive the build.
**Runtime layer:**
- `tests/unit/build/throw-and-verify-located.test.ts` — asserts that thrown errors carry readable stack frames with preserved function names (e.g. `initializeOpenCodeSwarm`). This is the runtime complement to the static grep assertions.
**Before enabling `--minify-identifiers`, confirm ALL of the following:**
- No `eval()` or `Function('...')` dispatch in the bundle (mangled identifiers break dynamic dispatch).
- No `constructor.name` or `Function.name` introspection in production paths.
- No `@__PURE__` annotations or side-effectful top-level patterns that depend on identifier stability.
- All 13 grep guardrails still pass.
- Stack-trace readability is verified at runtime.
If any of these checks fail, `--minify-identifiers` must not be enabled.
### (d) Namespace Re-Export Coverage
When modifying re-export or export-tracking logic (e.g. `exportLines`, `exportRanges`, `parseFileImports`):
**Test both forms of namespace re-export — they are distinct AST forms that require separate tracking:**
1. **Regular namespace re-export:** `export * from './module'`
2. **Aliased namespace re-export:** `export * as ns from './module'`
The regex in `src/tools/repo-graph/builder.ts` (`parseFileImports`) handles both via the pattern `export\s+\*(?:\s+as\s+\w+)?\s+from\s+['"`]([^'"`\0\t\r\n]+)['"`]`. Both forms must be tested when modifying export tracking because:
- They produce different `importType` values in the parsed output (`namespace` for both, but the aliased form carries a local binding name).
- They require separate tracking in `exportLines`/`exportRanges` — the aliased form creates a local binding (`ns`) that must be recorded alongside the re-exported symbols.
- Missing either form causes silent graph gaps in `repo-graph` callers/dead-exports analysis.
**Test file:** `tests/unit/tools/repo-graph-reexports.test.ts` covers both forms (see test case "4. export * as ns from './bar' — TypeScript namespace re-export → importType: namespace"). Run this test alongside any export-tracking change.
## Forbidden Shortcuts
- Enabling `--minify-identifiers` without confirming all 13 grep guardrails pass and runtime stack-trace readability is verified.
- Merging a minification/transform change without first running the consumer-constraint check (the 13 grep guardrails) against the smallest possible bundle.
- Modifying re-export/export tracking without testing `export * as ns from '...'` (aliased namespace) alongside `export * from '...'` (regular namespace).
- Assuming identifier preservation is "good enough" without running the full grep guardrail stack plus runtime stack-trace inspection.
## Delegation Template
When delegating a task affected by this skill, include:
```
SKILLS: file:.opencode/skills/generated/bundle-safety/SKILL.md
```
## Reviewer Checks
- Verify the minification config in the build script matches `--minify-whitespace --minify-syntax` (no `--minify-identifiers`).
- Verify `tests/unit/build/full-auto-toolbefore-fail-closed.test.ts` passes against the built `dist/index.js` (fail-closed hook guardrails green).
- Verify `tests/unit/turbo/lean/runtime-conformance.test.ts` passes (Lean Turbo identifier-preservation guardrails green).
- Verify `tests/unit/build/throw-and-verify-located.test.ts` passes (runtime stack-trace readability).
- If re-export tracking was modified, verify `tests/unit/tools/repo-graph-reexports.test.ts` covers both `export * from '...'` and `export * as ns from '...'`.
- Verify `dist/index.js` size is under the packaging gate (`MAIN_BUNDLE_MAX_BYTES = 8.0 MiB` in `tests/smoke/packaging.test.ts`).
## Source Knowledge IDs
- 5746c5c9-1330-4fbe-b62e-f564deb1ff77 — Before enabling any minification or transform flag, verify it doesn't break a hard consumer constraint by testing the smallest possible bundle against the exact constraint check. Required actions: test build output against consumer constraints before merging minification changes; build a minimal test bundle and run the consumer's validation first.
- 5d99affe-bdd1-4945-8cd8-fcf37abb8c84 — Identifier-preserving minify (--minify-whitespace --minify-syntax) yields 22.3% on this bundle (1.28MB absolute) — substantial but below the optimistic 35-43% because identifier mangling is deliberately skipped to keep stack traces readable. The standard is identifier-preserving; full mangling is REJECTED because it breaks the 13 identifier-grepping guardrail assertions and stack-trace readability.
- 9323a8f0-c07e-41c2-9857-11a24c55dca2 — When re-export handling is modified, verify aliased namespace re-exports (`export * as ns from '...'`) are preserved alongside regular re-exports — they are distinct AST forms that require separate tracking in exportLines/exportRanges. Required: test namespace re-exports alongside regular re-exports when modifying export tracking.
© ZaxbyHub · MIT · ZaxbyHub/opencode-swarm