As of today I have a family of 19 WireCat CLIs that an AI agent uses to work with Telegram, mail, Notion etc. Installing each one takes a long time, and when a new user comes and installs several at once, it is pretty painful.
I started looking into why, and saw that the CLIs barely share packages, because they install through npm. They all sit on one library, cli-core, but each one bundled its own copy, and npm i -g also gives every tool its own dependency tree. Install 5 CLIs and you get 5 copies of the same thing. And cli-core itself weighed almost 300 MB, because it pulled in everything anyone had ever put into it: charts, voice, semantic search, document readers.
In the end the cli-core install went from 280.4 MB to 48.8 MB on disk. No feature was lost, and only one command got renamed: account sessions is now account devices.
In this post:
- where the 280 MB went, when almost none of it is needed to start
- what was easy to remove, and what had to move to install on first use
- the step after which the install got bigger, not smaller
- what is left in the 48.8 MB and what I did not measure
I did not do this by hand but with several Claude Code sessions in parallel. I set the tasks, made the decisions on the plan and looked at the measurements, and the agents wrote the code and the PRs. Most of the work fit into 1 day.
How I measured and where the 280 MB went
The script scripts/install-size.ts uses npm to install into an empty folder exactly the cli-core archive that users get, and counts how much disk space node_modules takes. I measured on Linux x64. Most measurements were made on a GitHub runner, and the first 280.4 MB and 152.6 MB locally, with the same script. A release now fails if the install is bigger than the ceiling, and the ceiling is the last measurement plus 5%. Right now it is 52 MB.
There was another measurement, the one that started it all. In October I ran npm i @wirecat/max-cli and got 244 MB and 130 packages. That is the install of a whole CLI, not of cli-core alone, and its numbers must not be mixed with the 280.4. The goal in the plan was under 100 MB, and it is about max-cli too.
Step by step it went like this:
| What we did | cli-core install |
|---|---|
| Before the start | 280.4 MB |
Charts into the bundle, Anthropic through fetch, our own Word reader | 178.3 MB |
| MCP SDK, zod and a couple more libraries into the bundle, Russian dictionary in gzip | 152.6 MB |
Voice, semantic search and readers install on first use, types and maps only in -dev, one shared cli-core | 58.0 MB |
| SQLite only for your own system | 48.8 MB |
And here is how it looks for a person, with tg-cli as the example. I installed it through npm into an empty folder with an empty cache, as if installing for the first time, 3-4 times per version:
| tg-cli | Install time | On disk |
|---|---|---|
| Before (cli-core 1.3) | 13-19 s, usually about 15 | 342 MB |
| After (cli-core 3.0, without the SQLite step) | 10-14 s, usually about 10 | 105 MB |
Disk space dropped more than 3 times, but time only by about a third, because after that you hit the network and the fact that npm is not fast by itself.
Speed was never the problem here. Every heavy library was already loaded only when its feature ran, charts on the first chart, voice on the first transcription. The only problem was the disk, because npm installs all of it for everyone who installs any CLI.
Here are some of the biggest pieces from the October max-cli measurement (that is the other set, the 244 MB one):
| What | How much |
|---|---|
| Charts: echarts with zrender and tslib | 67 MB |
| Voice: sherpa-onnx and the Opus decoder | 33 MB |
| Anthropic SDK with dependencies | 21 MB |
| MCP server with zod | 16 MB |
| Semantic search: ONNX and the tokenizer | 15 MB |
| Web page and HTML readers | 15 + 10 MB |
cli-core source maps, 1,635 .map files | 9.7 MB |
| mammoth, the Word reader | 8 MB |
From echarts we only draw bars and lines through SVG, and 51 MB of the package are its prebuilt browser builds, which nobody here has ever loaded. The source maps were useless anyway, because each one points to ../src, src never made it into the package, and the maps have no sourcesContent.
What was easy to remove
esbuild bundled the charts into one file from the parts we actually use, and it came out at 567 KB instead of about 65 MB (this is already measured on cli-core, not on max-cli). echarts moved to dev dependencies, and its license is in THIRD_PARTY_NOTICES.
The Anthropic SDK was there for one call, streaming the response. The OpenAI adapter next to it had always run on plain fetch in 63 lines, so I decided to do Anthropic the same way, and both providers now work the same. But now we have to parse the stream ourselves, so it comes with 16 tests on a fake fetch, for example with a response cut in the middle of a UTF-8 character and with a broken stream. Before the release there was also a live call: the adapter answered OK for 25 tokens, and a request with temperature was rejected by the API with a 400 and the text "temperature: Extra inputs are not permitted". So for this API version temperature is extra input. The adapter does not send it anyway, but before that rested on a comment in the code, and now it is checked live.
I replaced mammoth (8 MB and 23 packages) with our own reader. A .docx is a zip with word/document.xml inside, and the store only needs paragraphs, lists and table cells. We already had an unzipper and an XML parser. The text is compared with what mammoth gave, on test files made in LibreOffice and pandoc. There are 2 differences: a line break inside a paragraph is now a new line (mammoth glued the words together), and the value of a simple field is kept, a page number for example. In October npm audit on the max-cli install complained exactly because of mammoth (sprintf-js through argparse, and mammoth needs argparse only for its own command line). On the cli-core archive we measured now, npm audit showed 0 both before and after the replacement, so the warning had gone earlier and not thanks to this step.
These 3 steps gave 178.3 MB.
The next step, to 152.6, was about libraries that almost everyone needs: the MCP SDK together with zod, LiquidJS and a couple more. They went into the bundle too, and the Russian dictionary for search was compressed with gzip, 3.5 MB became 0.6. By the way, in the plan zod was in the section "what will not get smaller", because the MCP SDK pulls it in, and MCP is needed for mcp. In the end it got smaller together with the SDK.
Voice and semantic search install on first use
Voice (33 MB on disk), semantic search (about 17 MB) and the PDF/HTML readers no longer install with the package. The first command that needs them downloads them itself into <WireCat data folder>/engines/<name>/<version>/, with the exact version and hash from npm, through a temporary folder so that no half-installed files are left behind. There is one copy for all CLIs, however they were installed.
I wanted install on first use to never break a command. So no command disappears from --help or from the list of MCP tools, whether the engine is there or not. Without a network the person gets a clear error and the exact command to repeat, and the rest of the command still works, search, for example, just searches by words. If 2 CLIs install the same engine at the same time, one installs and the other waits and takes the finished one. And all of this happens quietly, progress goes only to stderr, so --json and MCP get exactly what they got before.
Of course those megabytes did not go anywhere, they are just downloaded by whoever needs them. The download is smaller than the space on disk (the web page and HTML readers, for example, free 22.9 MB of disk and download as 3.1 MB), and voice still needs a model of hundreds of MB on top. And max-cli still keeps the voice engines in its own dependencies, so its users get them right away, as before.
While the agents were doing this, test runs downloaded engines not into a temporary folder but into my real WireCat data folder: resvg, huggingface and the wirecat engine are there, about 22 MB. Only packages were downloaded, nobody touched my data, but it is still a bug in the test, it should not write to the real folder.
One cli-core for all, and the step that made it worse
A user does not need .d.ts files, maps and src. That is 12.3 MB and 1,676 files in every install. I did not want a separate types package, so every release now comes out in 2 versions from one build: X.Y.Z for users without types and X.Y.Z-dev with everything, and the release checks that the JavaScript in them matches byte for byte. A CLI repository pulls in -dev with one override line in pnpm-workspace.yaml, and users never see that version. The agents checked that the light version really installs under npm, pnpm and Bun, locally and globally.
Before, every CLI bundled its own copy of cli-core, and in tg almost all of the 14.7 MB bundle was cli-core. Now cli-core itself ships already built, the CLI takes it from the installed package, and there is one copy on disk. Under pnpm and Bun that is exactly how it works, while npm -g still keeps a copy per tool. The tg bundle became 1.7 MB. While at it, the 51 cli-core entry points became 7, since the release was breaking anyway.
The prototype was 70-130 ms slower on a warm tg --help. I set a ceiling of +50 ms, slower means we do not ship. esbuild with 51 entry points produced 325 small files, and --help touched 182 of them. 2 things helped together, fewer entry points and merging small chunks into bigger ones, and it came out at +27-31 ms. To be fair, the prototype was measured on a machine under load and the final version on a quiet one, so the absolute numbers should not be compared with each other, what is compared is the difference from the current build in the same run.
Before the release we caught one more thing: an MCP server started before an update broke after it, because the update replaced bundle files under the live process, and the next lazy import failed. Now cli-core has a preload that loads all bundle files 2 seconds after the server starts, and a real update under a running server goes through.
And now the step that made it worse. The PR with the shared cli-core also left all the unbundled .js files in the package next to the bundle, because it seemed they were needed for import.meta.url. So the user got cli-core twice, bundled and unbundled, and cli-core itself weighed 34.5 MB in the install. If you add up the neighbouring measurements, the install grew by about 15 MB at this step. In the next PR this was checked, and it turned out that only 2 files are launched by path (the embeddings child process and the compatibility check binary) plus what they import, 12 files of 49 KB. The other 1,678 files, about 17 MB, went away, and cli-core became 17.1 MB. Together with semantic search and the readers, which moved to install on first use in the same hours, the runner showed 58.0 MB.
SQLite for your own system, and a publish that took half a day
The last 9 MB were boring but took the most time. The SQLite package carried libraries for all systems at once, 12 MB in every install, when only one is needed. In 1.2.0 it is split into per-platform packages (darwin, linux gnu/musl, win32), and npm, pnpm and Bun install only their own by os, cpu and libc. On linux-x64 that is 1.8 MB. The plan, by the way, said that optionalDependencies do not help, because npm installs them by default. For packages with os/cpu/libc fields they do help, and the plan was corrected later.
The code took little time, the publish took half a day. For trusted publishing from GitHub Actions npm wants every new package name confirmed in the browser, and there are 6 new names. 3 of the 6 answered 409 "already exists" (in the end they turned out fine), and the publish script failed on a name that had already been published from Actions, so it was fixed to skip what is already done and not drop the rest. Then in the middle of all this GitHub removed the macos-14 runner, the job on it got cancelled, and because of it the first publish run published nothing at all. And when 1.2.0 finally came out, npm only showed it a few minutes later.
While I was busy with SQLite, another session was moving all CLIs to cli-core 3.0, so that half day was not wasted.
cli-core has a compatibility check (parity) that builds the CLIs from its list against the new cli-core before releasing it. When the CLIs moved to cli-base 2.x, it stopped checking anything at all. cli-dev bundle refused to build with a file: dependency and asked for an exact version, so every CLI build failed before compiling. And it did not fail loudly, because after the breaking release all CLIs were on the list of known breakages, and for them the job only warns. This lasted a few hours in the evening, until the fix the same night. After the fix 6 CLIs out of 7 built, cli-memo and the template fail for their own reasons.
What is left in the 48.8 MB and what I did not measure
| Package | How much |
|---|---|
@wirecat/cli-core | 17.2 MB |
@wirecat/cli-base | 4.1 MB |
| keyring native part | 3.3 MB |
| valibot | 1.8 MB |
| SQLite for linux-x64 | 1.8 MB |
The rest is 142 small packages, 147 top-level packages in total. The biggest piece now is cli-core itself, and from here I would look at it, not at the dependencies.
What I did not measure:
- the size under pnpm, Bun and npx, the script installs only through npm (pnpm and Bun were checked for installing and keeping one copy, but not for size)
- macOS and Windows by hand, CI builds and runs the tests there, but I looked at the install size only on Linux x64
- how long downloading the engines on first use takes on a slow network
- the full install of a specific CLI after all the steps, all the numbers above are about cli-core, a CLI adds its own
- the savings on the full WireCat Desktop, the roughly 190 MB in the plan is an estimate, not a measurement
The plan with the dependency table and the decisions is in cli-core, and the shared cli-core with the startup time measurements has a separate plan. If the install on your macOS or Windows comes out noticeably bigger, write to me, I am curious where I missed.