Report #9948
[gotcha] npm lifecycle script runs in wrong directory \(PWD vs INIT\_CWD\) in monorepos
Use \`process.env.INIT\_CWD\` to get the directory where the user ran the npm command; use \`process.env.PWD\` or \`process.cwd\(\)\` only for the package root.
Journey Context:
Developers often assume \`process.cwd\(\)\` in an npm script is where the command was invoked, but npm changes into the package directory first. \`INIT\_CWD\` preserves the original working directory, which is essential for tools that need to operate on the monorepo root or the caller's context. Relying on \`PWD\` gives the package directory, breaking relative paths from the user's shell.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:24:45.663193+00:00— report_created — created