Skip to main content
Glama

Binary Diet gives coding agents and developers a clear view of release size and memory. Find the files and dependencies taking up space, trace native libraries, set a budget, and compare builds after a change.

Use this MCP server for binary size analysis to shrink executable size, investigate how to cut idle RAM usage, and remove unused dependencies after checking their runtime use. It also acts as a bundle size analyzer for MCP clients working on web output.

It runs locally as a CLI and MCP server for builds from C, C++, C#, Rust, Go, JavaScript, TypeScript, and more, including .NET Native AOT, WebAssembly, and web bundles. Works on Windows, macOS, and Linux with Node.js 22 or newer and no runtime npm dependencies. The available breakdown depends on the build format and reports supplied.

  • Find the weight in build folders, executable sections, archives, and web bundles.

  • Trace the cause with native import graphs, linker maps, esbuild metafiles, and .NET publish plans.

  • Measure the result with size comparisons, RSS samples, and CI budgets.

Install

Use Node.js 22 or newer on Windows, macOS, or Linux. Install the CLI globally:

npm install --global binary-diet-mcp
binary-diet --help

Profile a build with binary-diet profile ./publish --duplicates. Replace ./publish with your build output.

Alternatively, install from a checkout:

git clone https://github.com/noksfluxa/binary-diet-mcp.git
cd binary-diet-mcp
npm install --global .

From a checkout, use node bin/binary-diet.mjs in place of binary-diet. If Windows PowerShell blocks the script shims, use npm.cmd and binary-diet.cmd.

Related MCP server: io.github.morluto/flameox

Connect an AI agent to the binary size MCP server

After the global npm install, add the server to Codex or Claude Code. Install the corresponding Codex CLI or Claude Code CLI first.

On macOS and Linux:

codex mcp add binary-diet -- binary-diet serve
claude mcp add --transport stdio --scope user binary-diet -- binary-diet serve

On Windows:

codex mcp add binary-diet -- cmd /c binary-diet.cmd serve
claude mcp add --transport stdio --scope user binary-diet -- cmd /c binary-diet.cmd serve

For clients that use an mcpServers JSON configuration, merge this entry into the existing configuration. On macOS and Linux:

{
  "mcpServers": {
    "binary-diet": {
      "command": "binary-diet",
      "args": ["serve"]
    }
  }
}

On Windows, use "command": "cmd" and "args": ["/c", "binary-diet.cmd", "serve"]. Grok Build also requires "type": "stdio" in the server entry. VS Code uses a different configuration format.

The agent must have the global npm executable directory in its PATH. See MCP client setup for client-specific instructions and an absolute-path alternative. Start a new agent session after registering the server.

Profile my publish folder. Show me the largest dependencies and any duplicate or out-of-target runtime files. Save a baseline, then suggest one change I can verify by rebuilding and running the release smoke tests.

MCP tool

Use it to

weigh_artifact

Rank bytes in a file, bundle, or build folder

profile_release

Group bytes by directory and purpose, find identical files, and estimate web transfer size

check_size_budget

Enforce total, category, duplicate, and compressed size limits

attribute_esbuild

Rank input modules and packages by emitted bundle bytes

plan_target_publish

Identify package owners and measure runtime assets outside a .NET publish target

trace_native_imports

Trace packaged native libraries from an entry point and inspect unresolved imports

attribute_link_map

Attribute native linker layout to object files and symbols

compare_artifacts

Diff build outputs kept at separate paths

compare_reports

Compare saved size snapshots or RSS measurements

sample_memory

Sample RSS for a running local process

memory_mappings

Attribute resident and proportional memory to mappings on Linux

strip_debug_copy

Strip debug data into a new file and measure the delta

Reduce binary size and compare builds

Start with a baseline, make a build change, and compare the result. For a smaller Wasm bundle, inspect custom sections and measure the output after rebuilding. The build recipes cover native AOT trimming and other compiler settings.

binary-diet weigh dist --limit 12
binary-diet diff release-before release-after
binary-diet weigh release-after --max-bytes 5000000
binary-diet strip app.wasm --out app.release.wasm

For builds that reuse the same output path, run the before.json command before rebuilding. Place both reports outside the measured folder.

binary-diet weigh dist --limit 1000 --json > before.json
binary-diet weigh dist --limit 1000 --json > after.json
binary-diet compare before.json after.json

--max-bytes exits with code 3 if the total exceeds the budget. Totals stay exact when the contributor list is truncated. Diffs mark partial results and avoid reporting a row missing from a truncated snapshot as an addition or removal.

Analyze executable, WebAssembly, and web bundle size

binary-diet profile publish --depth 2 --duplicates
binary-diet profile release.msix --json
binary-diet profile dist --web
binary-diet metafile meta.json --output dist/app.js

The profiler groups files by directory and classifies symbols, binaries, legal material, assets, and other content. ZIP-based packages show packed bytes alongside unpacked entry sizes in JSON. --duplicates hashes same-size candidates of at least 4 KiB in build folders. An identical file can still serve a distinct runtime path or license obligation. Legal files have their own category so their size stays visible during optimization.

--web compresses eligible HTML, CSS, JS, JSON, SVG, and Wasm files individually using gzip level 9 and Brotli quality 5. Results estimate transfer size before server settings, HTTP overhead, caching, and the requests each route actually makes. metafile reads an existing esbuild --metafile=meta.json report and ranks modules and packages by their emitted contribution. esbuild metafile reference

Enforce release budgets

Save a policy outside the measured folder and run binary-diet budget publish budget.json. Each key except version is optional. Add --json for CI and release reports.

{
  "version": 1,
  "maxTotalBytes": 50000000,
  "maxCategoryBytes": {"symbols": 0, "binaries": 40000000},
  "maxDuplicateBytes": 0,
  "maxBrotliBytes": 1000000
}

The command exits 3 for an exceeded cap or incomplete measurement. Duplicate and Brotli budgets apply to build folders. Category names are legal, symbols, binaries, code, images, media, fonts, archives, data, and other. If a category is absent, its byte count is zero.

Optimize native AOT size and trace dependencies

binary-diet publish-plan publish --rid win-x64 --deps publish/App.deps.json --json
binary-diet graph publish bin/app.exe --json
binary-diet link-map release.map --limit 20
  • publish-plan joins the inventory with a .NET dependency manifest. It identifies package owners, quantifies incompatible runtime assets, and reports non-symbol savings separately. It keeps legal files and assets with uncertain provenance out of the candidate list. The command discovers a lone root-level .deps.json automatically. Set --keep to a comma-separated list of extra RIDs your distribution requires. Verify a projection with a matching publish and smoke test. .NET runtime identifiers · .NET host probing

  • graph follows declared native imports and counts each packaged image once. It checks architecture, reads delay-loaded PE imports, and groups unresolved names across importers. Supply extra package directories with --search and select --architecture for a universal Mach-O entry. Runtime plugin discovery, CLR interop, and OS loader search behavior need separate evidence. Windows DLL search order

  • link-map ranks object files and individual symbols from LLD ELF and Apple-style maps. Cross-owner overlaps stay unassigned, and Apple's dead-stripped section is excluded. Use weigh for disk bytes. LLD ELF map format · Xcode build settings

Measure idle RAM and process memory

Run the before and after builds on the same host with the same workload and comparable warm-up. Replace the sample PIDs below with the actual process IDs.

binary-diet memory 1234 --samples 10 --interval-ms 500 --json > before-rss.json
binary-diet memory 5678 --samples 10 --interval-ms 500 --json > after-rss.json
binary-diet compare before-rss.json after-rss.json --memory
binary-diet mappings 5678 --limit 10

The memory comparison uses sampled peak RSS. On Windows the command samples the working set. Windows and Linux also report the lifetime peak supplied by the OS. Linux mappings uses /proc/PID/smaps to rank mapped libraries, executable pages, the heap, and anonymous memory. PSS splits shared pages proportionally among processes. RSS covers one PID, excludes child processes and GPU memory, and can miss short-lived peaks.

What it can explain

Input

Breakdown

ELF

32-bit and 64-bit sections, separate zero-fill data, and DT_NEEDED libraries when section metadata is present

Windows PE

Raw and virtual section sizes, CLR header detection, and direct and delay-loaded import names

Mach-O

Thin and universal sections and direct dylib load commands

Core WebAssembly

Standard and custom sections, including debug sections

ZIP and ZIP64, APK, AAB, IPA, JAR

Packed and unpacked entry sizes from the central directory

Build folder, app bundle, or web output

Ranked paths and logical file bytes

Other files

Total logical bytes

Sections, file sizes, and declared library names provide the starting point. Attribute compiled code to symbols with a linker map and measure runtime-loaded libraries with a profiler. Removing unused code or libraries requires rebuilding and retesting. See Build recipes for ways to turn findings into smaller releases.

Debug stripping

Wasm stripping removes .debug_* and .zdebug_* custom sections locally. Native stripping uses a trusted tool on your PATH: llvm-strip for ELF and PE, with GNU strip as an ELF fallback on Linux, and Apple's /usr/bin/strip for Mach-O on macOS. On other hosts, Mach-O uses llvm-strip. Signed PE and Mach-O files are rejected. Keep a separate symbol artifact, test the new copy, and sign the finished release where required.

Development

Run npm test for parser fixtures, CLI and MCP checks, and comparisons with .NET PEReader, GNU readelf, or Apple otool where available. npm run test:package installs the tarball offline in an isolated prefix and checks the installed CLI and MCP server. CI runs both checks on Windows, macOS, and Linux with Node.js 22, 24, and 26. A version tag triggers those checks before GitHub publishes the tarball and checksum. npm run demo builds and strips a generated Wasm fixture. See validation and measurement definitions.

For a parser issue, include the input format, toolchain version, expected measurement, and a small shareable artifact or linker map.

Copyright © 2026 NoksFluxa™. Licensed under Apache-2.0. See NOTICE.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Local-first CLI and MCP server for turning Xcode Instruments artifacts into bounded, agent-sized evidence, with support for analyses like Time Profiler, Allocations, Network, and more.
      2
      MIT
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables coding agents to coordinate local profilers, benchmark tools, trace processors, and direct targets, turning explicit artifacts or commands into bounded runtime evidence with provenance, coverage, and limitations. It exposes analysis and capture tools that help trace, profile, and burn down hotspots in application and native code, GPU kernels, and inference stacks without workspace setup or a hosted service.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI coding agents and developers to search code by meaning and exact text, map symbols, dependencies, blast radius and context, inspect git-change impacts, and trace live Python or JavaScript execution from a local air-gapped SQLite index.
      Apache 2.0
    • A
      license
      B
      quality
      C
      maintenance
      Enables local, evidence-first triage of native binaries by extracting bounded symbols, strings, sections, call sites, gadget candidates, and mitigation signals as MCP tools for agent-guided manual review. It also provides metadata-only inspection for carriers such as archives, WebAssembly, firmware, and scripts without claiming verified vulnerabilities.
      12
      5
      MIT