CodePanel

Fresh git worktrees have no node_modules: why bun install beat cp -cR

Measured on a 414-package repository on macOS: sandboxed bun install finished in 2.2 to 3.0 seconds while copy-on-write cp -cR took 6.6 seconds.

The CodePanel teamcoding-agentsperformanceworktrees

When a coding agent starts in a fresh git worktree, node_modules is not there, so the very first bun test or npm test fails on its first import. The obvious optimization on macOS APFS is a copy-on-write clone (cp -cR) of the main checkout's node_modules. We benchmarked both on a 414-package repository on an Apple M1 Pro (2026-11-20), and bun install --frozen-lockfile won by more than 2x: 2.2 to 3.0 seconds warm versus 6.6 seconds for cp -cR.

Why copy-on-write lost to Bun's isolated store

Even though APFS copy-on-write does not copy file data blocks, cp -cR still walks and creates directory entries for every single file inside a 1 GB node_modules tree. With Bun's isolated linker (bunfig.toml), bun install --frozen-lockfile reads the lockfile and links only what the global store holds, avoiding the full directory walk.

Measured on CodePanel's own repository (Apple M1 Pro, 414 packages, 2026-11-20):

Strategy Time Environment
cp -cR of main checkout's node_modules 6.6 s APFS copy-on-write clone.
Sandboxed bun install --frozen-lockfile (cold cache) 6.6 s Empty Bun cache inside OS sandbox.
Sandboxed bun install --frozen-lockfile (warm cache) 2.2 s, 2.3 s, 3.0 s Three runs against warm global store.
Unsandboxed bun install --frozen-lockfile (warm cache) 2.25 s to 2.34 s Near-zero sandbox overhead on install.

What we shipped in the local runner

Based on those numbers, CodePanel's local runner picks the install strategy by package manager instead of assuming one fast path fits all:

  • Bun repositories: Run bun install --frozen-lockfile directly against the owner's Bun store inside the OS sandbox.
  • npm, pnpm, and yarn repositories: Keep a lockfile-hashed copy-on-write clone path where a frozen install is slower than cloning.
  • Cache wiring inside an isolated HOME: Every run gets its own HOME directory inside the sandbox so commands cannot read credentials. Without pointing the package manager explicitly at the owner's cache directory (and making only that cache writable when network is allowed), every fresh worktree would re-download the entire dependency tree from scratch.
  • Offline installs for Autopilot: Rule-started runs have network denied by default and install strictly from the local cache in read-only mode. If the cache lacks a package, the run stops cleanly and asks in the Inbox instead of opening the network silently.

See Coding agents for how the local runner prepares worktrees, and Sandboxing a coding agent's shell on a laptop for the sandbox profile behind it.