Subchapter 6.11
references/features-global-virtual-store.mdMarkdown5 KBView on GitHub
By default each project has its own node_modules/.pnpm virtual store containing hard links to the content-addressable store. With the global virtual store enabled, pnpm keeps one shared virtual store at <store-path>/links/ (find it via pnpm store path), and each project’s node_modules contains only symlinks into it.
enableGlobalVirtualStore: true# Default (per-project .pnpm with hard links)
project-a/node_modules/lodash -> .pnpm/lodash@4.17.21/node_modules/lodash
# Global virtual store (symlink to shared location)
project-a/node_modules/lodash -> <store>/links/@/lodash/4.17.21/<hash>/node_modules/lodash
project-b/node_modules/lodash -> <store>/links/@/lodash/4.17.21/<hash>/node_modules/lodash # same targetlodash@4.17.21 and the same transitive tree point at the exact same directory (NixOS-style). Different peers ⇒ separate entries.pnpm dlx/pnx and global installs; for project installs it is still opt-in/experimental.NODE_PATH, which Node ignores for ESM imports. If ESM deps import undeclared packages, resolution fails. Fix with packageExtensions or the @pnpm/plugin-esm-node-path config dependency.Git worktrees let you check out many branches simultaneously, each in its own directory, sharing one .git object store. Combined with the global virtual store, every worktree gets a fully functional node_modules that is almost free on disk — ideal for running multiple AI agents in parallel.
# Bare repo as the hub, one worktree per branch/agent
git clone --bare https://github.com/your-org/your-monorepo.git your-monorepo
cd your-monorepo
git worktree add ./main main
git worktree add ./feature-auth feat/auth
git worktree add ./fix-api fix/api-errorpackages:
- 'packages/*'
enableGlobalVirtualStore: truecd main && pnpm install # first install fills the global store
cd ../feature-auth && pnpm install # subsequent worktrees: nearly instant, just symlinksEach worktree has its own node_modules tree (so agents can install different versions on different branches without conflict), but all package contents come from the one shared store. Remove a worktree with git worktree remove ./feature-auth.
The pnpm repo itself uses this setup and ships helper scripts (
pnpm worktree:new <branch|pr>). Assumes all worktrees/agents share the same trust boundary.
pnpm add -g was redesigned in v11 for isolation. Each globally installed package (or group) gets its own install directory with its own package.json, node_modules/, and lockfile, so global tools can’t break each other via peer/hoisting conflicts. Installs are stored at {pnpmHomeDir}/global/v11/{hash}/ and share the global virtual store.
pnpm add -g typescript prettier # space-separated = separate isolated installs each
pnpm add -g eslint,prettier # comma-separated = ONE shared install group
pnpm remove -g eslint # removes only eslint's group
pnpm add -g --allow-build=esbuild esbuild # pre-approve build scripts
pnpm list -g # always works at depth 0
pnpm bin -g # global bin dir = $PNPM_HOME/binpnpm install -g (no args) is not supported — use pnpm add -g <pkg>.$PNPM_HOME/bin (not $PNPM_HOME directly). Run pnpm setup after upgrading to put it on PATH.pnpm add -g . (replaces pnpm link --global).pnpm list -g --depth=<n> (n>0) only works for a single install group.enableGlobalVirtualStore: true ⇒ node_modules is symlinks into one shared, hash-addressed store.$PNPM_HOME/bin.