Set up or fix npm trusted publishing (OIDC) in GitHub Actions and remove NPM_TOKEN. Use for ENEEDAUTH, E404 on PUT, E422 repository.url, or migrating off 2FA-bypass tokens before January 2027.
Start a fresh conversation. Replace the highlighted placeholders.
Use npm-trusted-publishing to assess [repository, package names, and release workflow] and draft an npm OIDC migration. Check the exact calling workflow/environment, GitHub-hosted runner, repository metadata, npm 11.5.1+ or compatible Yarn, registry URL, and required existing permissions. Keep publish tokens out of the publishing step and never grant id-token on untrusted triggers. Show proposed edits and per-package trusted-publisher instructions for my npm login/2FA. Do not publish, change account settings, delete secrets, or revoke tokens; old-token retirement must wait for a successful tokenless release and my confirmation.
Required inputs
[repository, package names, and release workflow]
User-approved starter prompt based on a pinned source version; check current skill requirements before running. Task evidence ↗
SKILL.md
name: npm-trusted-publishingdescription: Set up or fix npm trusted publishing (OIDC) in GitHub Actions and remove NPM_TOKEN. Use for ENEEDAUTH, E404 on PUT, E422 repository.url, or migrating off 2FA-bypass tokens before January 2027.
npm Trusted Publishing
Moves a GitHub Actions release from a stored NPM_TOKEN to npm trusted publishing. GitHub signs a short-lived OIDC token for the run, and npm exchanges it for a publish token. It also diagnoses the misleading errors a half-finished migration produces. From January 2027, granular tokens that bypass 2FA can no longer publish directly (npm docs).
When to Use This Skill
The user wants to remove NPM_TOKEN / NODE_AUTH_TOKEN from a release workflow or set up OIDC or provenance publishing.
A CI publish fails with ENEEDAUTH, 404 Not Found - PUT https://registry.npmjs.org/... or E422 ... repository.url.
Release logs show npm notice npm tokens that bypass 2FA are being restricted.
Checklist (all must hold)
Work through every item. Missing any one of them produces the errors above.
OIDC permission: the publishing job has permissions: id-token: write. If the job had no permissions block, keep the scopes it needs, such as contents: write for tags and releases or pull-requests: write for changesets. Adding a block drops every scope you don't list.
npm 11.5.1 or newer runs the publish. Node 24 ships it. Node 22 ships npm 10, so add npm install -g npm@^11.5.1 (or a newer pinned major) before publishing. pnpm 10 hands the publish to npm, so the same rule applies. Yarn Berry needs 4.10.3+.
No token reaches the publish step. Remove NODE_AUTH_TOKEN, NPM_TOKEN and YARN_NPM_AUTH_TOKEN from the step, the job and the workflow env, and delete script lines that write _authToken or npmAuthToken. npm tries OIDC first but falls back to a configured token, so a leftover token keeps the old credential in use. Keep a read-only token only on install steps that need private packages.
actions/setup-node has registry-url: https://registry.npmjs.org.
package.jsonrepository.url names the same GitHub repo, for example git+https://github.com/OWNER/REPO.git, plus directory for workspace packages. A mismatch gives E422.
A trusted publisher exists on npm for each package (npmjs.com → package → Settings → Trusted publishing), or with npm 11.15+:
npm trust github <pkg> --repo OWNER/REPO --file release.yml --allow-publish --yes
The workflow file name must match exactly; it is case-sensitive and includes .yml.
For a reusable workflow, use the calling workflow's file name, and grant id-token: write in the caller too.
If the job uses environment:, set the same environment on the publisher.
A package that doesn't exist yet must be published once by hand first.
GitHub-hosted runner. Self-hosted runners can't use trusted publishing.
Security Rules
Untrusted triggers: never add id-token: write to a job in a workflow triggered by pull_request_target, issue_comment, workflow_run or discussion. It would let outsiders exchange an OIDC token and publish. Move publishing to release, push (tags) or workflow_dispatch.
Dry runs:npm publish --dry-run and npm pack jobs don't publish, so they need no id-token and no trusted publisher.
The old token: delete the secret (gh secret delete NPM_TOKEN) and revoke it on npmjs.com only after the first tokenless release succeeds.
Error Guide
Error
Usual cause
ENEEDAUTH
No id-token: write, npm older than 11.5.1, or a workflow file name that doesn't match the trusted publisher
404 Not Found - PUT https://registry.npmjs.org/<pkg>
Same as above, a mismatched environment, no trusted publisher yet, or an expired token still being used
E422 ... repository.url
repository is missing in package.json or names another repo
Publish still uses the token
A token remains in env, .npmrc or .yarnrc.yml (checklist item 3)