Prevent Accidental npm publish

Claude Code can run npm publish during a refactoring session, pushing half-finished code to the public npm registry. In Auto Mode, there's no confirmation prompt.

The Fix

The npm-publish-guard hook (included by default in cc-safe-setup) blocks a publish command that begins the command string:

It is anchored to the start. Its pattern is ^\s*(npm\s+publish|npx\s+npm\s+publish), so cd pkg && npm publish goes past it — the hook is never asked about the part after the separator. Run --blindspots to see how much of your own history arrives in that shape.

# Blocks: npm publish, npm publish --tag, yarn publish, pnpm publish
npx github:yurukusa/cc-safe-setup

Also blocks: cargo publish, gem push, twine upload, pip publish. Each has a dedicated guard hook.

Allow Dry-Run

The hook allows npm publish --dry-run — you can test without actually publishing.

Package Manager Coverage

EcosystemHookBlocks
npm/yarn/pnpmnpm-publish-guardnpm publish
Rustcargo-publish-guardcargo publish
Pythonpip-publish-guardtwine upload
Rubygem-push-guardgem push
PHPcomposer-guardcomposer global require

Block All Publish Commands

npx github:yurukusa/cc-safe-setup

npm-publish-guard included by default. 900+ example hooks total.

cc-safe-setup · GitHub