HaiAI123

Curated Global AI Tools Directory

Industry update
25
heat index
Flat

Using a PreToolUse hook to stop Claude Code from wiping your workspace

12/01/2026 — 12/02, 09:20·1 sources (all)·2 reports (all)

Key takeaways

  • A developer has published a PreToolUse hook script under .claude/hooks that runs before shell commands and blocks the git reset --hard, git…

Background & analysis

On December 1, 2026, a post on DEV Community proposed using a PreToolUse hook to keep Claude Code within bounds. The author noted that a shell allow-list can already keep the agent away from destructive commands and force-push, but it often still leaves sudo uncovered. Once the model has root, a "quick fix" can change system packages, rewrite /etc, or install a binary nobody reviewed. The suggested remedy is a small PreToolUse hook that names the blocked command and exits with code 2, so the agent stays inside the repository. The script is saved as .claude/hooks/block_sudo.py and made executable.

The next day, December 2, the same author published a follow-up applying the idea to workspace wipes. According to that post, a shell allow-list also tends to miss git reset --hard, git checkout -- . and git clean -fdx, commands that discard uncommitted work in a single shot. After a messy diff or a failed merge, the model will reach for them as a "clean start." The hook described there lives under .claude/hooks, runs before the shell executes, names the blocked command and exits with code 2, forcing the agent to ask first or leaving recovery to the human.

Both posts stop at how the hook is written and what it blocks. Neither reports deployment results or later updates, so the matter currently rests at that point.

AI-generated from 2 reports · updated 4 days ago

Latest turnA developer published a PreToolUse hook for Claude Code that blocks git reset --hard, git checkout -- ., and git clean -fdx — commands the agent tends to reach for after a messy diff or a failed merge and that discard uncommitted work in one shot. The hook runs before the shell, names the blocked command, and exits with code 2, so the agent has to ask first or leave recovery to you.

Related AI tools

updream
24-hour heatHeat index 25
Just charted — trend is building up
24 hours agonow

Reports on this story headlines open the original

Dec 2
  1. A developer published a PreToolUse hook for Claude Code that blocks git reset --hard, git checkout -- ., and git clean -fdx — commands the agent tends to reach for after a messy diff or a failed merge and that discard uncommitted work in one shot. The hook runs before the shell, names the blocked command, and exits with code 2, so the agent has to ask first or leave recovery to you.

    DEV Community · AIAI score 68
Dec 1
  1. A shell allow-list can keep Claude Code away from destructive commands and force-push, yet sudo often slips through; once the agent has root, a quick fix can change system packages, rewrite /etc or install a binary you never reviewed. The fix is a small PreToolUse hook that names the blocked command and exits with code 2, keeping the agent inside the repo. Save it as .claude/hooks/block_sudo.py and make it executable.

    DEV Community · AIAI score 63

Other stories people are talking about

How is heat calculated?About the method

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

Back to AI industry updates →