Skip to content

Allow the Installed Package's Own Install Scripts on Every npm Install - #4268

Merged
ptr727 merged 3 commits into
developfrom
fix/npm-allow-scripts-4264
Nov 18, 2026
Merged

ptr727 merged 3 commits into
developfrom
fix/npm-allow-scripts-4264

Conversation

@ptr727

@ptr727 ptr727 commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #4264.

From npm 12 on, now npm's latest, a global install skips a package's install scripts unless the allow-scripts config names that package. @opencode/cli and @anthropic-ai/claude-code each carry a postinstall. Without it the install still exits 0, so the installer reports a clean step, but opencode then refuses to start.

Each npm install the agent installers run names the one package it installs, as npm install -g --allow-scripts=<pkg> <pkg>@latest. That covers:

  • the Linux package_step upgrade
  • the Windows Get-PackageStep upgrade, through a new Get-NpmInstallArgument helper
  • the Windows managed opencode install and its Source string

The flag allows that package's scripts for that one run and writes no user config. bun installs are unchanged. The help texts and docs/host-setup.md say the npm install allows the one package's scripts.

The open points the issue raised

  • Older npm: the flag is harmless. Measured against the real @opencode/cli from the registry in throwaway prefixes, npm 12.2.3, 11.21.3, 10.9.11 and 9.9.4 each install a working opencode v2.3.2 with no warning. Without the flag, npm 12.2.3 prints had install scripts blocked, and opencode --version fails with @opencode/cli's postinstall script was not run.
  • npm 11's warning: under npm 11.19 to 11.21 the install-scripts warning is advisory, and the scripts still run. The skipped-script symptom is npm 12's.
  • Surfacing a remaining warning: not added. With the flag, the installed package's own scripts run and npm prints nothing. A transitive dependency's warning still reaches the step's output as npm prints it.
  • Dry run and remedies: [dry run], running: and every run: remedy print the full command, flag included, since each one is built from the same arguments.

Verification

  • tests/test_install_agents.py: the npm command expectations carry the flag, on both platforms, while the bun ones do not. 128 tests OK (1 skipped). test_cli_usage.py, test_bootstrap.py and test_host_gate.py pass, as do spec/validate.py, shellcheck, shfmt, PSScriptAnalyzer and the prose gate.
  • Native Linux: an npm-owned codex sat in a throwaway global prefix first on PATH. install-agents.sh --upgrade --yes codex ran npm install -g --allow-scripts=@openai/codex @openai/codex@latest and moved it from 0.169.1 to 0.170.0. A second run printed Nothing changed.
  • Windows is not verified natively. The tests run the .ps1 whole under pwsh on Linux against stub tools. On a Windows host with an npm-owned opencode, run host-setup\windows\install-agents.ps1 -Upgrade -DryRun opencode. Expect npm install -g --allow-scripts=@opencode/cli @opencode/cli@latest. Then run -Upgrade opencode, and expect opencode --version to answer with no install-scripts warning printed.

Local passes

Two recorded passes. The first raised four introduced findings, all fixed in af7b03b:

  • a Linux comment naming opencode, which never upgrades through npm there
  • the latest-tag rationale split away from the npm branch
  • two help sentences over the length cap

The second pass was clean.

The comments label covers the new comment lines. Each states why the flag is there, a reason the code cannot carry.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • npm-managed agent installs and upgrades now allow the selected package’s install scripts to run, including when upgrading to the latest version. This also applies to OpenCode installs on Windows.
  • Documentation

    • Updated setup guidance and command help to describe npm’s install-script behavior and the latest-tag install behavior.

ptr727 and others added 2 commits November 18, 2026 14:12
From npm 12 on, a global install skips a package's install scripts unless
allow-scripts names it. opencode's postinstall is then never run: the install
exits 0, the installer reports a clean step, and `opencode --version` fails
with "@opencode/cli's postinstall script was not run". claude-code carries a
postinstall too.

Each npm install the agent installers run now names the one package it
installs, `npm install -g --allow-scripts=<pkg> <pkg>@latest`: the Linux
and Windows upgrade steps and the Windows managed opencode install. It allows
that package's scripts for that run and writes no user config. bun's install
is unchanged.

Measured against the real @opencode/cli in throwaway prefixes: without the
flag npm 12.2.3 blocks the postinstall and the binary refuses to run. With
it, npm 12.2.3, 11.21.3, 10.9.11 and 9.9.4 each install a working binary
with no warning.

Closes #4264

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ntences

The Linux npm branch names claude-code, since opencode never upgrades through
npm there, and the latest-tag rationale again covers npm and bun alike. Each
help text states the npm allowance as its own sentence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings November 18, 2026 22:19
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Nov 18, 2026
@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head af7b03b01e57ae3c7051c0b6bbabcd7ade8c0b16, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Linux and Windows agent installers now pass package-scoped --allow-scripts arguments to npm installs or upgrades. The Windows OpenCode install uses the shared argument builder. Documentation, help text, and tests reflect the command changes. Bun commands and removal commands remain unchanged.

Changes: npm install and upgrade behavior

Layer / File(s) Summary
Update npm install commands
docs/host-setup.md, host-setup/linux/install-agents.sh, host-setup/windows/install-agents.ps1
Linux npm upgrades now include --allow-scripts for the selected package. Windows npm upgrades and the OpenCode install use a shared argument builder to allow scripts for the specified package. Help text and setup documentation describe the behavior.
Update command assertions
tests/test_install_agents.py
Linux and Windows assertions now expect package-scoped allowances in npm commands and related dry-run, reporting, and failure cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · previous review af7b0

The change lets npm run install scripts only for the package being installed or upgraded by the agent installers, with docs and tests updated to match. No concrete merge-blocking risk was found. Windows behavior was tested only with stub tools on Linux, so a dry-run on a Windows host is a reasonable final check.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Allow the Installed Package's Own Install Scripts on Every npm Install" matches the main change. The PR adds a package-scoped --allow-scripts=<package> flag to npm install and upgrade com…
Linked Issues check Passed Directly linked issue #4264 asks for a package-scoped --allow-scripts on each npm install or upgrade the agent installers run. The raw summary places the flag on the Linux package_step upgrade, the Wi…
Out of Scope Changes check Passed The changes described are the npm install argument change on Linux and Windows, the shared Windows argument helper, help text in both installers, docs/host-setup.md, and the matching test expectations…
Full details: Title check

Explanation

The title "Allow the Installed Package's Own Install Scripts on Every npm Install" matches the main change. The PR adds a package-scoped --allow-scripts=&lt;package&gt; flag to npm install and upgrade commands in the Linux and Windows agent installers, and updates tests and docs to match. The title is specific and concise. It does not mention the Windows opencode install or the bun exclusion, but those are secondary details.

Full details: Linked Issues check

Explanation

Directly linked issue #4264 asks for a package-scoped --allow-scripts on each npm install or upgrade the agent installers run. The raw summary places the flag on the Linux package_step upgrade, the Windows Get-PackageStep upgrade (via the new Get-NpmInstallArgument helper), and the Windows managed opencode install and its Source string. Bun paths and removals are unchanged, which matches the issue's scope. The reviewed head's host-setup/linux/install-agents.sh --help text states that npm installs allow the one package's install scripts, which npm 12 otherwise skips. The raw summary says tests/test_install_agents.py expects the flag on npm commands on both platforms and not on bun commands, which covers the issue's test requirement and its dry-run and remedy consistency point. The issue's open point on surfacing remaining install-scripts warnings is answered in the PR description: no warning surfacing was added, with the reasoning given. Older npm behavior is reported as measured in the PR description; this assessment did not re-run those measurements. Limitation: repository diff reads were unavailable in this review (changed blobs missing from the checkout), so the Windows and Linux code changes rest on the supplied summary and PR description, plus the partially readable Linux file help text. Windows behavior is not verified natively, as the PR author states.

Full details: Out of Scope Changes check

Explanation

The changes described are the npm install argument change on Linux and Windows, the shared Windows argument helper, help text in both installers, docs/host-setup.md, and the matching test expectations in tests/test_install_agents.py. Each traces to an objective in #4264: the npm command construction, the help and remedy text that shows the same command, and the tests that check it. The docs change describes the same npm behavior. No unrelated functional change appears in the supplied summary. Diff reads were unavailable, so this rests on the summary and PR description rather than a full diff read.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e956a7 and af7b03b.

Files selected for processing: 4

  • docs/host-setup.md
  • host-setup/linux/install-agents.sh
  • host-setup/windows/install-agents.ps1
  • tests/test_install_agents.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still has an active verification gap: the new managed opencode install path is tested only in dry-run mode, leaving real npm execution and argument handling unverified.

1 open issue
What changed in this PR

This pull request updates the agent installers so npm global installs allow the installed package's own scripts, preventing required postinstall scripts from being skipped while leaving bun behavior unchanged.

Changes:

  • Adds package-scoped --allow-scripts arguments to Linux and Windows npm installs.
  • Centralizes Windows npm argument construction for upgrades and managed opencode installation.
  • Updates command expectations and documentation for the new npm behavior.
File Description
tests/​test_install_agents.py Updates Linux and Windows test expectations for package-scoped npm script allowances.
host-setup/​windows/​install-agents.ps1 Adds reusable npm argument construction for Windows upgrades and managed opencode installation.
host-setup/​linux/​install-agents.sh Adds the package-scoped npm script allowance to Linux package upgrades.
docs/​host-setup.md Documents that npm permits install scripts for the package being installed.

Review effort: Lite

Comment thread host-setup/windows/install-agents.ps1 Resolved
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.46%. Comparing base (b38e084) to head (d7a45c4).
⚠️ Report is 244 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4268      +/-   ##
===========================================
- Coverage    81.60%   78.46%   -3.15%     
===========================================
  Files           26       42      +16     
  Lines         9070    15434    +6364     
===========================================
+ Hits          7402    12110    +4708     
- Misses        1668     3324    +1656     
Flag Coverage Δ
python-3.13 78.46% <ø> (-3.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

The managed install was covered only by a dry run, so a real run now asserts
npm receives the helper's arguments whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head d7a45c452b38514a6e86e71eedd6f72b0b1d8bfb, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit c76e275 into develop Nov 18, 2026
13 checks passed
@ptr727
ptr727 deleted the fix/npm-allow-scripts-4264 branch November 18, 2026 22:55
ptr727 added a commit that referenced this pull request Nov 18, 2026
…a pre-test Hook (#4270)

## Summary

Promotes three changes from develop to main:

- #4267: every ruff call that can reach a downstream repository's root
`hub_fetch_run.py` passes `--extend-exclude ./hub_fetch_run.py
--force-exclude`. That covers the hook snippets, the Python VS Code
tasks, `validate-task.yml`, the `pypi-build-default` action and the
`python-codestyle` skill. No repository adds the helper to its own ruff
config.
- #4268: each npm install the agent installers run passes
`--allow-scripts=<pkg>` for the one package it installs. npm 12
otherwise skips the package's `postinstall`, which leaves opencode
unable to start while the step reports clean.
- #4269: a new opt-in caller hook, `.github/actions/pre-test`, runs in
each `unit-test` leg before the .NET SDK setup, where a .NET test
project exists and the caller carries the hook. ptr727/PhotoCleaner#277
is waiting on it.

## Open after release

- **Native Windows check of #4268.** On a Windows host with an npm-owned
opencode, run `host-setup\windows\install-agents.ps1 -Upgrade -DryRun
opencode`. Expect `npm install -g --allow-scripts=@opencode/cli
@opencode/cli@latest`. Then run `-Upgrade opencode`, and expect
`opencode --version` to answer with no `install-scripts` warning. Linux
was verified natively, and the flag was measured against the real
package on npm 9 through 12.
- **Downstream proof of #4269.** ptr727/PhotoCleaner#277 adds the hook
and bumps its pin once this is released.

Closes #4263
Closes #4264
Closes #4265

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants