Skip to content

feat(hooks): dangerous-actions-blocker — PreToolUse hook for Claude Code#1008

Draft
ousamabenyounes wants to merge 2 commits intortk-ai:developfrom
ousamabenyounes:feat/dangerous-actions-blocker
Draft

feat(hooks): dangerous-actions-blocker — PreToolUse hook for Claude Code#1008
ousamabenyounes wants to merge 2 commits intortk-ai:developfrom
ousamabenyounes:feat/dangerous-actions-blocker

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Summary

A ready-to-use PreToolUse Bash hook that intercepts dangerous CLI operations before AI agents execute them. Ships as a copyable file in hooks/claude/.

Discussion: #1007 — opening this draft PR alongside the issue so the team can review the actual implementation while we discuss scope and approach. Happy to adapt based on feedback.

What it does

Category Example Decision
Files rm -rf /, rm -rf ~ 🚫 block
Files rm -rf mydir (not a safe dir) ⚠️ ask
Git git push --force 🚫 block (allows --force-with-lease)
Git git reset --hard, git clean -f, git branch -D ⚠️ ask
Secrets cat .env, reading .pem/.key files 🚫 block
Database DROP TABLE, TRUNCATE, DELETE FROM x; 🚫 block
Docker docker system prune -a, mass removal ⚠️ ask

Container-aware: Commands inside docker exec / kubectl exec skip host-path checks (paths resolve in the container, not the host).

Usage

// .claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash", "hooks": ["bash hooks/claude/dangerous-actions-blocker.sh"] }
    ]
  }
}

Open questions (see #1007)

  1. Is this in scope for RTK or better as a separate project?
  2. Should this use Rust-based parsing instead of regex?
  3. What should be the default block vs ask decisions?

Test plan

  • Manual testing with Claude Code on destructive commands
  • Container exec false-positive fix verified

🤖 Generated with Claude Code

ousamabenyounes and others added 2 commits April 3, 2026 21:14
Ready-to-use Claude Code PreToolUse hook that intercepts destructive
CLI operations before execution:

- rm -rf on root/home/parent → block
- rm -rf on non-safe dirs → ask confirmation
- git push --force (but allows --force-with-lease) → block
- git reset --hard, clean -f, checkout -- ., branch -D → ask
- Secrets exposure (cat .env, .pem, API keys in commands) → block
- Destructive DB ops (DROP, TRUNCATE, DELETE ALL) → block
- Docker mass removal / system prune -a → ask

Container-aware: skips host-path checks inside docker/kubectl exec
since paths resolve inside the container, not the host.

See rtk-ai#1007 for design discussion.

Co-Authored-By: Claude <noreply@anthropic.com>
39 test cases covering all categories:
- File ops: rm -rf block/ask, safe dirs allowed, container exec bypass
- Git: force-push block, force-with-lease allowed, destructive ops ask
- Secrets: .env/.pem/.key blocked, API keys in commands blocked
- Database: DROP/TRUNCATE blocked, SELECT allowed
- Docker: prune -a ask, normal commands allowed
- Edge cases: empty input, safe commands pass through

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant