@asmadsen/opencode-node-package-manager
v0.1.0
Published
Opencode plugin that intercepts package manager commands and rewrites them to use the correct package manager
Maintainers
Readme
@asmadsen/opencode-node-package-manager
An opencode plugin that intercepts package manager commands and validates they match the project's configured package manager.
What it does
When opencode (or an AI agent using opencode) attempts to run a package manager command (npm, yarn, pnpm, bun), this plugin:
Detects the project's package manager from:
packageManagerfield inpackage.jsondevEngines.packageManagerfield inpackage.json- Lockfile presence (
package-lock.json,yarn.lock,pnpm-lock.yaml,bun.lock,bun.lockb)
Validates that commands use the correct package manager
Blocks commands that use a different package manager with a helpful error message
Installation
From npm
Add to your opencode.json:
{
"plugin": ["@asmadsen/opencode-node-package-manager"]
}Local development
Place the compiled file in .opencode/plugins/ directory or reference a local path.
Detection Priority
The plugin detects the package manager in this order:
packageManagerfield inpackage.json(e.g.,"[email protected]")devEngines.packageManagerfield inpackage.json- Lockfile detection:
bun.lockorbun.lockb→ bunyarn.lock→ yarnpnpm-lock.yaml→ pnpmpackage-lock.json→npm
Supported Commands
npm,yarn,pnpm,bunwith any subcommandnpx,bunx,pnpx,yarn dlx
Example
If your project uses bun (detected via packageManager: "[email protected]"), and opencode attempts:
npm install lodashThe plugin will block it with:
Use bun instead of npmWIP /TODO
- [ ] Auto-rewrite commands to use correct package manager instead of just blocking
- [ ] Handle command translation (e.g.,
npm install→bun add) - [ ] Add configuration for allowed package managers
- [ ] Handle monorepo scenarios with multiple package managers
Development
bun install
bun test
bun run build