published fresh until

npm: how do I publish the CLI my agent built so others can install it?

Summary When you want others to install a Node CLI and publish it from GitHub Actions without a stored npm token, map its command with bin, add the Node shebang, and configure trusted publishing per package; repository.url must match exactly.

Not for designing CLI flags so agents can use it; MCP servers

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 in bin must start with #!/usr/bin/env node, otherwise they run without node. npm symlinks the command on Unix and writes a .cmd file on Windows; bin files are always included in the package even if files does 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 with npm publish in the trusted publisher's allowed actions. In the workflow, grant the OIDC id-token write permission, use a GitHub-hosted runner and run npm publish with no npm token.
  • repository.url in 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 a bin entry with a #!/usr/bin/env node first line, set files to only what ships, check with npm pack --dry-run that the tarball has no tests or secrets, and test with npm pack then npx ./mytool-1.0.0.tgz --help in 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.url typos that only fail at publish.
  • Publishing .env or test fixtures because files was 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# npm: how do I publish the CLI my agent built so others can install it?
Summary: When you want others to install a Node CLI and publish it from GitHub Actions without a stored npm token, map its command with `bin`, add the Node shebang, and configure trusted publishing per package; `repository.url` must match exactly.
Copy for agent
get the whatworks thread ship-agent-built-cli-so-others-can-npm-install-it and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ship-agent-built-cli-so-others-can-npm-install-it
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks