一键导入
codex-npm-block
// Use when setting up or maintaining a project-local Codex demo that blocks npm by placing a repo-local executable shim earlier in PATH, with Codex execpolicy covering agent/model absolute npm invocations.
// Use when setting up or maintaining a project-local Codex demo that blocks npm by placing a repo-local executable shim earlier in PATH, with Codex execpolicy covering agent/model absolute npm invocations.
| name | codex-npm-block |
| description | Use when setting up or maintaining a project-local Codex demo that blocks npm by placing a repo-local executable shim earlier in PATH, with Codex execpolicy covering agent/model absolute npm invocations. |
Use this skill when a project should block accidental npm use for Codex-run
commands without becoming an npm project.
package.json, lockfiles, or a real install path..codex/bin/..codex/zsh/..codex/zsh/.zshenv and
.codex/zsh/.zprofile; do not factor it into a shared zsh file for this
lesson..zshrc; Codex shell commands are non-interactive shells.Create or maintain these files:
.codex/config.toml
[shell_environment_policy.set].ZDOTDIR = ".codex/zsh".allow_login_shell, features.shell_snapshot, or
[shell_environment_policy] inherit..codex/zsh/.zshenv
export PATH="$PWD/.codex/bin:$PATH"..zshenv runs for every zsh invocation unless zsh uses -f..codex/zsh/.zprofile
export PATH="$PWD/.codex/bin:$PATH"..zshenv..codex/bin/npm
127..codex/rules/no-npm.rules
prefix_rule for pattern = ["npm"].decision = "forbidden".pnpm, bun, or another package
manager instead.The npm shim should be a real executable, not a shell function. Child processes
such as node with child_process.spawn("npm", ...) do not see shell
functions, but they do resolve executables through PATH.
Use this behavior:
#!/usr/bin/env sh
cat >&2 <<'EOF'
npm is disabled inside this Codex project environment.
Do not choose a replacement automatically. Ask the user whether they want pnpm, bun, or another approach.
Common replacements: pnpm install/add/run, bun install/add/run.
EOF
exit 127
Run the local proof from the project root:
ZDOTDIR="$PWD/.codex/zsh" \
zsh -lc 'command -v npm; node ./test-npm.js; echo script-exit=$?'
Expected:
npm resolves to .codex/bin/npm.127.For the execpolicy layer, check an absolute npm path when one exists:
codex execpolicy check \
--rules .codex/rules/no-npm.rules \
--resolve-host-executables \
--pretty \
/usr/local/bin/npm --version
Expected: the decision is forbidden, with the npm executable resolved by
Codex host executable resolution.