fix(postinstall): do not install skills as another package's dependency - #12
Merged
Merged
Conversation
`npm_config_global` is set for the whole of a global install, including the lifecycle scripts of its dependencies. So a package that merely depends on Context Tree triggered the auto-install: `npm i -g some-tool` wrote six skill directories into the user's own ~/.claude and ~/.codex as an invisible side effect of installing an unrelated tool. Also require that this package is the install target rather than a nested copy. A directly installed package sits in npm's prefix, whose parent is not a package; a dependency sits inside the owning package's node_modules. `scripts/package-e2e.mjs` simulated a global install by forcing npm_config_global on the locally installed copy, which is precisely the layout this change now refuses. That shortcut was sound when the flag was the only signal, but it no longer models a global install, so the e2e installs for real into a temporary prefix instead — the layout npm produces is the whole basis of the distinction. The nested case it used to stand in for is now asserted explicitly, in the direction we actually guarantee. Verified with `npm run check:package`, and separately against a packed tarball installed into an isolated prefix: a direct global install still installs the skills, a global install of a dependent package prints the hint and writes nothing, and removing the guard reproduces the original behaviour from the same nested layout. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ggordonhall
force-pushed
the
fix/postinstall-nested-dependency-guard
branch
from
September 1, 2026 18:02
d1da71e to
56b7333
Compare
The unit test added with the guard copied the script into fabricated install layouts and re-asserted the three cases `scripts/package-e2e.mjs` already covers against a real `npm install -g` of the packed tarball. The e2e run is the higher-fidelity check — the layout npm produces is the whole basis of the distinction — so keep only that one. Also fold the duplicated explanation into a single comment at the guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
scripts/postinstall.mjsauto-installs the packaged skills whenevernpm_config_globalis"true". npm sets that variable for the entire global install, including the lifecycle scripts of dependencies — so a package that merely depends on Context Tree triggers the auto-install.The effect:
npm i -g some-toolwrites six skill directories into the user's own~/.claudeand~/.codexas an invisible side effect of installing an unrelated tool. It is also why OpenTag could not take Context Tree as an ordinary dependency.Fix
Also require that this package is the install target, not a nested copy. The distinction is structural:
Six lines in the script.
The e2e fixture had to change too, and that is worth a look
scripts/package-e2e.mjssimulated a global install by forcingnpm_config_global=trueon the locally installed copy underconsumer/node_modules/. That is precisely the layout this change now refuses, so the fixture failed — correctly.That shortcut was sound when the flag was the only signal, but it no longer models a global install. The e2e now installs for real into a temporary prefix (
npm install -g --prefix), since the layout npm produces is the whole basis of the distinction. The nested case it used to stand in for is now asserted explicitly, in the direction we actually guarantee: hint printed, nothing written to the home directory.Verification
npm run check,npm run typecheck,npm test(136 tests), andnpm run check:packageall pass.Separately, against a packed tarball installed into an isolated prefix with
HOMEredirected:pnpm installThe real
~/.claudeand~/.codexwere fingerprinted before and after and are byte-identical.The new unit test in
tests/install.test.tsruns the script from both layouts rather than asserting on the guard's internals.Note
This unblocks OpenTag taking
@first-tree-ai/context-treeas a runtime dependency instead of vendoring it at build time (first-tree-ai/opentag#455).🤖 Generated with Claude Code