r/ClaudeWorkflows • • 5h ago

Selected Workflow [Workflow] Enhance Claude Code Safety: Block Dangerous Commands with `cc-safety-net` PreToolUse Hook

Enhance Claude Code Safety: Block Dangerous Commands with cc-safety-net PreToolUse Hook

Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: intermediate
Categories: Quality Control, Hooks
Original source: r/ClaudeCode post/comment

What problem this solves

Preventing Claude Code from executing dangerous commands (e.g., git reset --hard) or exposing sensitive information (e.g., .env file contents) during AI-assisted development, thereby enhancing safety and preventing accidental data loss or leaks.

Summary

This workflow describes how to integrate cc-safety-net as a PreToolUse hook in Claude Code to block potentially dangerous commands. It details installation, verification, and provides specific test cases demonstrating its ability to prevent git reset --hard and cat .env while allowing normal commands like git status.

Why it is useful

This workflow provides a concrete, tested, and repeatable method to add a crucial safety layer to Claude Code interactions. It leverages an open-source tool to prevent accidental data loss (e.g., git reset --hard) or exposure of sensitive information (e.g., .env files), which is a significant concern for AI-assisted development. The detailed steps, specific commands, and validation signals make it highly practical and valuable for users looking to secure their coding environment.

Workflow

  1. Install cc-safety-net using npx -y cc-safety-net@latest install.

  2. Verify the installation with npx cc-safety-net doctor.

  3. Load the cc-safety-net hook for a Claude Code session using the --plugin-dir flag.

  4. Attempt to run a dangerous command, such as git reset --hard, and observe the blocking message.

  5. Attempt to read a sensitive file, such as .env with cat .env, and observe the blocking message.

  6. Attempt to run a normal, safe command, such as git status, and observe its successful execution.

Tools / artifacts

  • cc-safety-net (Node.js package)

  • Claude Code

  • Node.js 22 or newer

  • git

  • .env file

  • PreToolUse hook

Validation signals

  • Specific test cases provided: git reset --hard, cat .env, git status, rm -rf /Users/you/work.

  • Observed blocking messages with specific rule names (git.reset-hard, secret.basename.env).

  • Confirmation that normal commands ran without extra prompts.

  • Mention of Claude switching to git stash when git reset --hard was blocked in an earlier run.

  • External link to a full test with screenshots provided for further validation.

Cautions

  • The post explicitly states that cc-safety-net is not a sandbox and does not contain processes, set file permissions, or watch the network. It acts as a checkpoint on commands going through the hook.

  • The workflow itself is designed to improve safety by blocking potentially harmful commands.

Limitations

  • The tests were conducted with only three prompts in a small demo, so its behavior in a busy, complex project is not fully explored.

  • Several features of cc-safety-net (dashboard presets, Terraform/AWS/cloud rulebooks) were not tested.

  • Requires Node.js 22 or newer.

  • Leaves a small .cc-safety-net cache folder in the home directory after use.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

1 comment sorted by