How to rotate npm access tokens
Reissue an npm granular access token with the same packages, scopes and IP ranges, move CI to it, then revoke the old one, allowing for npm's revocation delay.
Part of the guide
npmGranular access token
- Where to issue a new one
- docs.npmjs.com/creating-and-viewing-access-tokens
- What a leaked key reaches
- Up to 50 organizations and 50 packages or scopes, read-only or read and write, and never more than the user who owns the token can do.
- Can be scoped
- Yes
Keys can be limited to fewer permissions or resources.
- Expires
- Always set; write tokens default to 7 days and last at most 90
- Switching keys
- Overlap windowDelayed revocation
The old key keeps working for a while after you revoke it.
What Crunu does here
Crunu doesn't reissue keys at providers. It shows which values to replace and keeps the new one.
Build the list for a departure with the offboarding checklistOn this page
Create a new granular access token with the same packages, scopes, organizations, permission and IP ranges as the old one, give it to your CI and build machines, confirm that installs or publishes work, then revoke the old token. An npm account can hold up to 1000 granular tokens, so the two overlap for as long as you need (npm docs). One thing differs from most providers: revocation isn't always instant. npm warns that in some cases it can take up to an hour before a revoked token stops working (revoking tokens).
Crunu doesn't create or revoke npm tokens and doesn't talk to the registry. It shows which npm values a departing person received, stores the replacement as a new environment version, and hands it to npm at run time.
npm tokens after the 2025 changes
If your notes about npm tokens are older than late 2025, they are out of date:
- Classic tokens are gone. npm permanently revoked every existing classic token on December 9, 2025 (GitHub Changelog). Only granular access tokens remain.
- Local publishing uses sessions.
npm loginnow returns a session token that expires after two hours. - Write tokens are short-lived. New write-enabled granular tokens default to seven days and can't exceed 90 (GitHub Changelog).
- Direct publishing with a token is ending. npm says publishing new package versions directly with a granular token will be removed in January 2027, and since August 2026 tokens that bypass two-factor authentication can't perform account identity or governance actions. For CI/CD, npm points to trusted publishing, or to a read-and-write token limited to staging releases.
So a reissue of a publishing token is often the moment to stop using one at all.
Settings to copy from the old token
A granular token can cover up to 50 organizations and up to 50 packages, scopes or a mix of both. Access is read-only or read and write, and write access to packages is either publish-and-stage or stage-only. Access to an organization doesn't let the token publish its packages, a token never has more permission than its user, and it can be limited to IP ranges in CIDR notation. The full token appears only once; afterwards npm shows only its first and last four characters.
Reissue without downtime
- Create the token on the website under your profile picture, Access Tokens, Generate New Token, or with
npm token createin a recent npm CLI. Match the old token's packages, scopes, permission and CIDR ranges, and pick an expiration. - Save it in Crunu as
NPM_TOKENin the environment your builds use, for exampleweb-app / staging. The save adds a version to the environment's history. - Let
npmread it from the environment instead of a file. In.npmrc,${VARIABLE_NAME}is replaced from the environment, so the line//registry.npmjs.org/:_authToken=${NPM_TOKEN}stays safe to commit, and builds run undercrunu run. - Run an install of a private package, or a staged publish, with the new token and confirm it succeeds.
- Revoke the old token, either with the × button next to it on the website or with
npm token revokeand the token's ID. Allow up to an hour before you assume it's dead.
npm token create --name=web-app-ci --expires=30 --scopes=@kiteline \
--packages-and-scopes-permission=read-only --cidr=198.51.100.0/24
crunu run --env web-app/staging -- npm ci
npm token list --json
npm token revoke TOKEN_IDnpm token revoke takes the full token or an ID long enough to be unique. It doesn't accept the shortened token printed by the normal npm token list output, which is why the list above uses --json (npm-token). The .npmrc substitution rule is described in the npmrc reference.
When to reissue an npm token
- A departure. Their own tokens belong to their npm account, and a session from
npm loginon their laptop expires within two hours by itself. What you reissue are the tokens they could read: the CI token for private packages, a publishing token, a bot account's token. In Crunu, removing the person yields a reissue checklist of those values by name. - A leak. Revoke immediately and assume the token may work for up to another hour. Check the versions of your packages published in that window.
- Expiry. With a 90-day ceiling for write access, reissuing publishing tokens is routine whether anyone leaves or not, and the steps above are the routine.
What to rotate when a developer leaves covers the order of work for a whole departure, and the offboarding checklist builds the list for your stack. The registry side, creating and revoking, is always done with npm; Crunu keeps the new value and the record of when it changed.
Frequently asked questions
Something else? Write to support@crunu.com
Do npm classic tokens still work?
No. npm permanently revoked all existing classic tokens on December 9, 2025, and they can't be recreated or recovered. Only granular access tokens are supported, and npm login now gives a session token that expires after two hours.
How long can an npm token with write access live?
At most 90 days. When npm announced the limit in September 2025, it also lowered the default expiration for new write-enabled tokens to seven days. Every token gets an expiration date, at least one day in the future.
Is revoking an npm token instant?
Not always. The CLI reference says a revoked token is removed from the registry immediately, but npm's guide to revoking tokens warns that in some cases revocation can take up to an hour. For a leak, revoke first and treat that hour as exposed.
Does Crunu revoke npm tokens?
No. Crunu doesn't call the npm registry. It shows which npm values a departing person received, stores the new token as a new environment version and passes it to npm through crunu run, so it never sits in a committed .npmrc file.
Sources
Every source this page relies on, with the date we last checked it.
- npm Docs: About access tokens · checked October 30, 2026
- npm Docs: Creating and viewing access tokens · checked October 30, 2026
- npm Docs: Revoking access tokens · checked October 30, 2026
- npm CLI v11: npm-token · checked October 30, 2026
- npm CLI v11: npmrc · checked October 30, 2026
- GitHub Changelog: npm classic tokens revoked, session-based auth and CLI token management · checked October 30, 2026
- GitHub Changelog: Strengthening npm security, changes to authentication and token management · checked October 30, 2026