Repository navigation
Description
What is slow
Each time the server starts, it checks whether each npm-installed provider CLI has an update by running npm outdated -g <package> and then, when nothing is outdated, npm ls -g <package>. It does this separately for every provider. On Windows each npm.cmd run is a cmd.exe plus a node.exe (and a console host), and takes 0.6–1.4 s. These runs land in the first seconds after the server starts listening, when the client is connecting and the server is busy with its own start work. Two providers installed with npm cost 4 npm runs. Every further npm-installed provider (OpenCode, Pi, Grok, …) adds 2 more, all against the same npm prefix.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit
285558eb10. - Installed with
npm i -g @openai/codex @anthropic-ai/claude-code opencode-aiinto the default global prefix (Codex 0.171.0, Claude Code 2.1.330). 6 projects, 18 threads. - 5 production server starts (
node src/bin.ts serve, no client). Every child process was logged with achild_processhook.
Every start ran exactly 4 npm processes for version checks:
| command | time per run (4 warm starts) |
|---|---|
npm outdated -g --prefix <p> --json @openai/codex |
1283–1416 ms |
npm outdated -g --prefix <p> --json @anthropic-ai/claude-code |
935–1123 ms |
npm ls -g --prefix <p> --depth 0 --json @openai/codex |
811–832 ms |
npm ls -g --prefix <p> --depth 0 --json @anthropic-ai/claude-code |
808–818 ms |
Total: 3.6–4.2 s of npm process time per start. The server trace shows resolveNpmGlobalLatestVersion spans of about 1.9 s each, beginning about 2 s after listen.
Run standalone on the same machine (n=5 each, PowerShell Measure-Command):
| command | time |
|---|---|
one npm outdated with one package |
661–765 ms |
one npm outdated -g --json @openai/codex @anthropic-ai/claude-code |
689–733 ms, answers both ({} when neither is outdated) |
one npm ls -g --depth 0 --json naming both packages |
585–618 ms, returns both versions |
Linux comparison: the same 4 npm runs per start (~400 ms per outdated and ~220 ms per ls).
Where the time goes
packages/provider-core/src/server/maintenanceResolver.ts: resolveNpmGlobalLatestVersion (an outdated run, then an ls fallback, through runProbe). Each provider's resolvePackageManagedProviderMaintenance passes it as lookupLatestVersion, and resolveLatestProviderVersion / enrichProviderSnapshotWithVersionAdvisory call it once per provider at start. The cache key includes the package name, so two providers on the same prefix never share a run.
Why it is avoidable
Both providers live in the same npm prefix. npm outdated and npm ls take several package names and answer for all of them in the time of one. The per-provider runs repeat the same npm start-up and read of the same global tree.
What a fix has to show
The same start measurement, before and after, counting npm processes during start. Expected: with Codex and Claude Code installed by npm, a start runs at most 2 npm processes for version checks (from 4), with about 1.3–1.5 s of npm process time instead of 3.6–4.2 s. The count must not grow with the number of npm-installed providers on one prefix. What stays: one npm outdated per prefix (about 0.7 s), and the npm ls fallback per prefix when nothing is outdated (about 0.6 s). Each provider must still show the same latest version and update advisory as before.
How to measure it again
- On a Windows machine, check out the commit and run
vp i. Then runnpm i -g @openai/codex @anthropic-ai/claude-codeand make sure the global prefix is on PATH (codex --versionandclaude --versionwork). - Save the hook below as
spawnlog.cjs. Then, five times: fromapps/server, startset SPAWNLOG=start<k>.ndjsonandset T3CODE_DEV_SEED=0, thennode --require spawnlog.cjs src\bin.ts serve --base-dir H --port 4800 --host 127.0.0.1. Wait 45 s, then stop the process that owns port 4800. - Count the npm lines:
node -e "const r=require('fs').readFileSync(process.argv[1],'utf8').trim().split('\n').map(JSON.parse).filter(x=>/npm/i.test(x.cmd));for(const x of r)console.log(x.ms,x.cmd.slice(0,200))" start<k>.ndjson. On Windows the npm runs are logged as acmdline that holds the wholenpm.CMD ... outdated/lscommand.
// spawnlog.cjs: logs every child process with its start epoch and duration
const cp = require('child_process'); const fs = require('fs'); const out = process.env.SPAWNLOG || 'spawn.ndjson';
const log = (o) => { try { fs.appendFileSync(out, JSON.stringify(o) + '\n'); } catch {} };
for (const name of ['spawn', 'execFile', 'exec', 'fork']) { const orig = cp[name]; cp[name] = function (...a) { const t0 = Date.now(); const c = orig.apply(this, a);
c.once && c.once('exit', (code) => log({ k: name, cmd: String(a[0]), args: Array.isArray(a[1]) ? a[1].map(String) : [], at: t0, ms: Date.now() - t0, code })); return c; }; }
require('module').syncBuiltinESMExports();The standalone check, as npmtest.ps1 (replace $pfx with npm prefix -g):
$pfx = (npm prefix -g).Trim(); $npm = "$pfx\npm.cmd"
foreach ($k in 1..5) {
$a = Measure-Command { & $npm outdated -g --prefix $pfx --json '@openai/codex' | Out-Null }
$c = Measure-Command { & $npm outdated -g --prefix $pfx --json '@openai/codex' '@anthropic-ai/claude-code' | Out-Null }
$d = Measure-Command { & $npm ls -g --prefix $pfx --depth 0 --json '@openai/codex' '@anthropic-ai/claude-code' | Out-Null }
"single=$([int]$a.TotalMilliseconds) both=$([int]$c.TotalMilliseconds) ls-both=$([int]$d.TotalMilliseconds)" }Found by the automated Windows performance sweep on 285558e.
Activity