Quick answer: A Redocly bundle grows mostly from full dereference, which copies the same schema into every place it is referenced, plus unused components and internal content left in the public file. Keep $ref pointers instead of passing --dereferenced, run with --remove-unused-components, and use the remove-x-internal decorator to cut flagged internal nodes; use --keep-url-references so external URLs stay as pointers rather than getting inlined.

Why a Redocly bundle grows

The bundle command exists because most OpenAPI consumers want one file, while authoring is easier when reusable schemas and parameters live in separate files and are pulled in through $ref. During that merge, a few choices quietly inflate the output.

The biggest one is --dereferenced, or -d. A fully dereferenced bundle replaces every $ref with a literal copy of the target, so a schema used by ten operations appears ten times. The openapi-core docs also warn this can produce circular objects. The file is self-contained, but it is no longer deduplicating anything.

The rest is accumulation. Components that no operation points to still travel in the bundle unless you remove them. Internal endpoints and fields meant for your own teams sit next to public ones when nothing strips them. Absolute URL references get fetched and inlined by default, and long examples or descriptions add weight on top. None of these are errors in the source; they are just content the published artifact does not need to carry.

The moves that actually shrink it

Cause of bloat What to do Flag or decorator
Same schema copied at every reference Keep $ref pointers, do not fully dereference Avoid -d
Schemas and parameters nothing references Drop dead components from output --remove-unused-components
Internal endpoints and fields in a public bundle Mark them, then remove flagged nodes remove-x-internal with x-internal
External URL content pulled in and inlined Preserve the URL as a pointer --keep-url-references, -k
Heavy examples and descriptions Trim or split them, apply an overlay --overlay before decorators

remove-x-internal is worth understanding on its own. It removes any node carrying the flag property, which defaults to x-internal and can be renamed to something such as x-private. Nodes without the flag are untouched. This lets one source of truth serve both internal and public audiences: you maintain a single description, and the public build simply drops the flagged parts. Redocly recommends pairing it with --remove-unused-components, because deleting a flagged node can leave component definitions that nothing references anymore.

Apply it without breaking the contract

Keep the source and the bundled artifact as separate concerns. The multi-file repository stays readable and deduplicated; the bundle is the thing you publish. Decorators only rewrite at bundle time, so lint still checks the source as written while bundle, build-docs, and push see the decorated output. Overlays apply before decorators, which matters when an overlay adds a node you then expect a decorator to remove.

After trimming, treat the result as a new contract, not just a smaller file. Run lint against the bundle, confirm every remaining $ref still resolves, and verify a consumer that expects one file can open it. Removing a component that a hidden operation still points to produces a dangling reference, and -k only helps when the runtime can reach those external URLs. Measure before and after so you know which change did the work, and keep the flags in version control rather than passing ad hoc options on a release machine.

Frequently asked questions

Does --dereferenced always make the bundle bigger? It usually does, because each $ref becomes a separate copy and a shared schema repeats across operations, with circular objects as an added risk. Use it only when a consumer genuinely needs a file with no references, and keep the referenced build for normal publishing.

What is the difference between remove-x-internal and remove-unused-components? The first removes nodes you actively flag as internal, even if something references them. The second removes components that nothing references at all. They solve different problems and are commonly run together.

Will --keep-url-references work offline? No. It keeps external URLs as pointers instead of inlining them, so the consumer must be able to reach those URLs. A fully offline, self-contained file cannot retain external pointers.

The bottom line

Bundle size is a design choice, not a fixed cost of using Redocly: preserve $ref reuse, delete dead components, flag internal content for removal, and keep external URLs as pointers, then lint the trimmed output so a smaller file never becomes a broken contract. A lean bundle makes the docs load fast, but trimming and reusing schemas does not verify what the API does at runtime; running an ordered sequence of real requests with a tool such as Powerduck confirms the behavior those published schemas describe. The broader comparison hub covers the rest of this choice.