`npm ci` Doesn't Fix the .npmrc Override. It Just Hides It Better.
Ana cloned the repo on a Friday afternoon, the way everyone on her team does it now. Clean folder, fresh clone, one command she trusts more than the old one, because the team switched to it months ago for exactly this re
Ana cloned the repo on a Friday afternoon, the way everyone on her team does it now. Clean folder, fresh clone, one command she trusts more than the old one, because the team switched to it months ago for exactly this reason: no surprises. The output said one line, added 1 package, and she moved on. Monday morning she found a file in the package folder that should not have been there, stamped Friday afternoon, written by a hook she believed she had switched off years ago in her own config file. Nothing had warned her. Nothing had even whispered. The install had done exactly what it was told to do by a file she had never opened, and the one line of output had hidden all of it.
That is the part people keep getting wrong about npm ci. It feels safer than npm install. It wipes the folder, it reads the lockfile, it refuses to improvise. All of that is true, and none of it touches the question that actually bit Ana. The question is not whether the install is clean. The question is whose word it takes when two config files disagree, and whether you would ever find out.
maxbuildsdev asked me that in the comments on my last piece: does the layering hold the same way under npm ci, with a lockfile in play, and does the foreground flag show a hook running instead of swallowing it? Same trap, same two config files, same tiny test package with one install hook that leaves a marker file behind. Fourteen installs, two runs per shape, and I wrote down what actually happened.
1. The lockfile changes nothing about who wins
This was the question, and the answer is blunt: the repo still wins. Plain npm ci inside the repo ran the hook both times, markers stamped 00:09:25 and 00:09:35 UTC. Plain npm ci in the clean folder, the same package with no repo file of its own, ran it neither time. The CLI flag kept it off both times in the repo. Twelve installs in the main matrix, two repeats per shape, and not one repeat disagreed with its twin.
I had half expected the lockfile to matter. It is the whole point of ci, after all: the install is supposed to follow the lockfile and nothing else. But the lockfile only pins which packages and versions get installed. It says nothing about whether their install hooks are allowed to run. That decision still comes from the config layers, and the layers still stack the same way they did under plain npm install: the file sitting in the repo beats the file sitting in your home folder, every time, without a word about it. If you switched to ci because you thought the lockfile closed this hole, you switched to a stricter installer for a problem it was never built to solve.
2. Silence is not proof, and ci is quieter than most
Here is the part that should bother you more than the override itself. In both repo installs, the hook ran and the output said nothing at all. One line: added 1 package. No hook name, no hook output, no hint that anything besides the install had happened. The only proof was the marker file sitting in the package folder afterwards, which nobody looks for on a normal Friday.
That is the same silence plain npm install gave me in November, and it lands harder under ci for a simple reason: ci is the command people reach for when they want certainty. The whole pitch is that nothing unexpected happens. So when the output comes back clean, people read it as confirmation that nothing unexpected happened. It is not confirmation. It is just a quiet log. A hook can run, write files, print nothing, and leave you with an output line that reads like a clean bill of health. If your evidence that hooks are off is "the install looked fine," you have no evidence.
3. The foreground flag is a witness, not a guard
This is the one piece of good news, and it comes with a catch worth naming plainly. Run the same install with the foreground flag and the hook stops being invisible. Both repo runs printed the hook out in the open:
> [email protected] preinstall
> node -e "require('fs').writeFileSync('HOOK-RAN.txt', ...); console.log('HOOK-RAN-MARKER preinstall executed')"
HOOK-RAN-MARKER preinstall executed
There it is, the hook's own printed line, in the output where you can actually see it. After two rounds of installs where the hook ran in total silence, watching it finally announce itself felt like the tool apologising. But a witness is all it is. The flag never stopped a hook. In the clean folder, where my user setting already blocks hooks, the flag changed nothing, both times. And with both flags together in the repo, the hook stayed off both times: the ignore flag still beats the foreground flag. So the foreground flag answers one question, did a hook run and what did it say, and no other. If you add it hoping it will protect you, you have bought a window, not a lock, and a window helps only if someone is looking through it at the exact moment the install runs.
4. The check lies unless it stands next to the install
cryptostrapon added the edge that makes the other three problems actually dangerous, and it is the one I keep thinking about. The check I have been recommending, npm config list inside the repo, tells the truth. Run it from the folder above the repo and it tells you something else entirely: my user value, true, with no project section at all, no mention that a repo file even exists. Same machine, seconds apart, two opposite answers, and both are correct about the folder they were asked in.
Then I split the check and the install apart on purpose, the way a build job does when the check lives in one step and the install in a later one. Check at the root said true, safe. The later install in the repo ran the hook anyway, marker stamped 00:11:13 UTC. And the mirror image: check inside the repo said false, hook will run, and the later install in the clean folder ran nothing at all.
That is how this trap actually gets built in real teams. Nobody skips the check. They run it in the wrong folder, or in an earlier step with its own working directory, read the green answer, and walk into an install that answers to a different file. The fix is not a better check. It is a check that refuses to live anywhere except right next to the install: same folder, same step, immediately before npm ci. Anything further away is a reading about a different place.
So here is where I land. npm ci does not fix the override. It just hides it better, behind a lockfile and a one-line summary that both feel like safety and neither is. The repo file still wins, the hook still runs in silence, and the only flag that shows it is a witness that cannot stop it. The CLI flag still wins when you type it, and the check still tells the truth when it stands in the right folder at the right moment.
What do you run before you install a repo you did not write? The check in the repo folder, the CLI flag every time, or do you trust the lockfile and the one-line output like Ana did on that Friday? Tell me what your setup actually does, not what it is supposed to do. I want to know which of these four problems has bitten you, and whether the bite came from the override, the silence, or a check that was read in the wrong folder.
P.S. Everything I write stays free — that part doesn't change. But if this one was worth something to you, you can buy me a coffee ☕ (one-time or monthly, both work). It covers the API credits and hosting behind these experiments — and honestly, it's also the nudge that gets the next one started on the evenings I'd otherwise skip it. — Salam
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.
