What this thread does
The problem
You (and your coding agent) wrote a Node command-line tool that works with node cli.js. Now you want npx mytool or npm i -g mytool to work for others, and you want to publish without leaving a long-lived npm token in CI.
What npm's docs say
From the package.json bin docs and the trusted publishers docs (read 18 October 2026):
"bin": {"mytool": "bin/cli.js"}(or a string if the command has the package's name). Files inbinmust start with#!/usr/bin/env node, otherwise they run without node. npm symlinks the command on Unix and writes a.cmdfile on Windows;binfiles are always included in the package even iffilesdoes not match them.- Trusted publishing: needs npm CLI 11.5.1+ and Node 22.14+. In the package settings add the GitHub owner, repo, workflow filename (in
.github/workflows/) and optional environment, and allow direct publishing withnpm publishin the trusted publisher's allowed actions. In the workflow, grant the OIDC id-token write permission, use a GitHub-hosted runner and runnpm publishwith no npm token. repository.urlin package.json must match the GitHub repo exactly or publishing fails. npm does not validate the config when saved, so errors show at publish time, and an unused new config expires after 2 days.- Provenance is generated automatically for public repos and packages.
How to describe it to your agent
Prepare this CLI for npm. Add abinentry with a#!/usr/bin/env nodefirst line, setfilesto only what ships, check withnpm pack --dry-runthat the tarball has no tests or secrets, and test withnpm packthennpx ./mytool-1.0.0.tgz --helpin a temp directory. Write a GitHub Actions workflow that publishes on a version tag with the OIDC id-token write permission and no stored npm token. Tell me which setup I must do on npmjs.com myself.
Mistakes to check
- No shebang, so the command is "not found" or runs as shell.
repository.urltypos that only fail at publish.- Publishing
.envor test fixtures becausefileswas not set.
Limits
From official docs only; I did not publish a package. Python tools use a different path (PyPI), not covered here. A different thread covers designing a CLI so coding agents can use it safely.
Started from a post by @npm, packaged by the editor. Original post