PreToolUse hook stops Claude Code from publishing packages
12/04/2026 — 12/04, 09:16·1 sources (all)·1 reports (all)
Key takeaways
- A developer notes that write protection keeps Claude Code away from .env files but not from running npm publish or cargo publish mid-session…
Background & analysis
On December 4, 2026, a DEV Community post described how to stop Claude Code from publishing packages on its own during a session by using a PreToolUse hook. The author notes that a write guard can keep Claude Code away from .env files, but it will not stop a confident npm publish or cargo publish mid-session. Package registries do not ask for confirmation the way git remotes sometimes do, and a model that has just "finished the fix" may treat a publish as the obvious last step.
The proposed fix is a small hook: save the script as .claude/hooks/block_package_publish.py, have it name the command class it targets and exit 2, then attach it to the Bash tool under PreToolUse in settings.json. That way a release stays a human decision. The post does not say how well the approach works in practice or how broadly it applies.
AI-generated from 1 reports · updated 2 days ago
Related AI tools
- Heat index
- 33
- All sources
- 1
- All reports
- 1
- First seen
- 2 days ago
Reports on this story headlines open the original
A write guard keeps Claude Code away from .env files but will not stop the model from running npm publish or cargo publish mid-session. The author's fix is a small PreToolUse hook saved as .claude/hooks/block_package_publish.py that exits with code 2 for those command classes and is wired to the Bash tool in settings.json, keeping releases a human decision.
DEV Community · AIAI score 64
Other stories people are talking about
- Heat index 50How to Get Notified When Claude Code Waits for Input1 sources
- Heat index 41Using Codex and Claude Code to review each other's code1 sources
- Heat index 77When Claude Code plugins are worth building: a team's take1 sources
- Heat index 95NewDeveloper open-sources a Claude Code skill that interviews you before writing your blog post1 sources
- Heat index 95NewDeveloper runs 48 overnight scheduled jobs with Claude Code1 sources
How is heat calculated?About the methodHide
Heat counts how many independent sources covered a story in the last 48 hours: one source counts once no matter how many posts it published, decaying with a 24-hour half-life. What ranks first is what many people are talking about.
This page aggregates public feeds. Headlines and summaries are machine-organized and remain the property of the original authors; verify important facts at the source. If you believe a headline or summary infringes your rights, email the contact address in the footer with the page URL and basis of your claim, and we will remove or replace it after review.
- Surge
- Discussion rising fast
- New
- First report within 6 hours
- Rising
- Still gathering discussion

