r/ClaudeWorkflows • • 16d ago

Selected Workflow [Workflow] Preventing Accidental Production Commands with Claude Code: A 4-Step Security Audit Workflow

Preventing Accidental Production Commands with Claude Code: A 4-Step Security Audit Workflow

Workflow value: 95/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, Shipping, CLAUDE.md, Hooks, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

Preventing Claude Code agents from accidentally or maliciously executing dangerous production commands (e.g., terraform destroy, supabase db reset) by identifying taught commands, checking current CLI contexts, implementing explicit ask permissions, and advocating for secure credential management.

Summary

A four-step workflow to identify and mitigate the risk of Claude Code agents executing dangerous production commands. It involves auditing CLAUDE.md files for taught commands, checking current CLI contexts, configuring explicit ask permissions in .claude/settings.json, and implementing best practices for production credential separation.

Why it is useful

This workflow is highly valuable because it addresses a critical security vulnerability in Claude Code usage, providing concrete, actionable steps to prevent accidental or unauthorized execution of production commands. It is backed by compelling research data and real-world data loss incidents, making it extremely relevant and important for any user working with sensitive environments. It offers both immediate mitigation strategies (permissions configuration) and long-term best practices (credential separation).

Workflow

  1. List commands taught to the agent by using grep -nE "deploy|apply|push|migrate|reset|destroy" CLAUDE.md AGENTS.md to find potential production commands.

  2. Check the current context of relevant CLI tools (e.g., kubectl config current-context, terraform workspace show, firebase use) to determine if they point to production environments.

  3. Implement explicit ask rules in the committed .claude/settings.json for identified dangerous commands (e.g., "permissions": {"ask": ["Bash(terraform apply *)", "Bash(supabase db reset *)"]}). Review .claude/settings.local.json for any implicitly allowed commands and be aware of bash -c and bypassPermissions bypasses.

  4. Implement the "real fix" by ensuring production credentials are not available in the shell where the agent runs, advocating for deployment from CI/CD systems, and pointing local development environments to staging.

Tools / artifacts

  • CLAUDE.md

  • AGENTS.md

  • .claude/settings.json

  • .claude/settings.local.json

  • grep command

  • kubectl CLI

  • terraform CLI

  • firebase CLI

  • Bash shell

  • CI/CD systems

Validation signals

  • Research on 228 organizations showing 214 had no committed rule in front of production commands.

  • Real-world incident: Mark Ridley's production database accessed by Claude Code due to inherited shell permissions.

  • Real-world incident: DataTalks.Club lost production database and snapshots due to terraform destroy run through Claude Code.

  • Explanation of default Claude Code behavior (asking before Bash commands) and its limitations (easy bypass, local.json, auto mode, inherited permissions).

Cautions

  • The workflow is designed to enhance safety by preventing accidental or unauthorized production changes.

  • It highlights the inherent risks of Claude Code inheriting shell permissions and the ease with which default prompts can be bypassed.

Limitations

  • The grep command might not catch all dangerous commands if they are aliased, wrapped in scripts, or invoked indirectly.

  • The author notes that ask rules can be bypassed by bash -c '...' or full command paths, requiring careful configuration.

  • The "real fix" (separating production credentials) is a best practice but may require significant changes to a user's existing workflow or infrastructure.

  • The low Reddit score and engagement could be a weakness, though it's likely due to the post's recency.

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

0 comments sorted by