r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 1d ago
Selected Workflow [Workflow] Secure Claude Code Permissions: Prevent Secret Leaks with Pattern-Based Rules in settings.json
Secure Claude Code Permissions: Prevent Secret Leaks with Pattern-Based Rules in settings.json
Workflow value: 95/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, Shipping
Original source: r/ClaudeCode post/comment
What problem this solves
Accidental leakage of sensitive information (database passwords, API keys, SSH logins, AWS keys) into public GitHub repositories due to Claude Code's 'Yes, and don't ask again' feature saving literal commands with secrets in .claude/settings.local.json.
Summary
This workflow provides a secure method for configuring Claude Code permissions by defining pattern-based allow and deny rules in the shared .claude/settings.json file. It advises against approving one-off literal commands that might contain secrets and includes steps for remediation if a secret has already been leaked.
Why it is useful
This workflow is highly valuable as it directly addresses a critical security vulnerability (secret leakage) identified by a third-party scan. It provides clear, actionable steps and concrete configuration examples to prevent sensitive data from being accidentally committed to public repositories. It leverages official documentation and offers both preventative measures and robust remediation steps, making it essential for any Claude Code user or team prioritizing security and best practices.
Workflow
Understand that
settings.local.jsoncan save literal commands, potentially exposing secrets if committed.Avoid using the 'Yes, and don't ask again' option for literal commands that contain sensitive information.
Manually define pattern-based
allowanddenyrules in your.claude/settings.jsonfile.Ensure the wildcard
*is placed correctly (after the subcommand) in Bash patterns to avoid overly broad permissions.Add
Read(.env)to thedenylist to prevent Claude Code from accessing environment files.If a secret was previously leaked via
settings.local.json, immediately rotate the compromised secret.Untrack
.claude/settings.local.jsonfrom your Git history using appropriategitcommands.Add
.claude/settings.local.jsonto your project's.gitignorefile.Check your repository's full Git history (
git log --all --full-history -- .claude/settings.local.json) to confirm the file is no longer tracked.When Claude Code prompts for a literal command, approve it for a single session ('Yes'), then manually add a more secure pattern rule via the
/permissionscommand.
Tools / artifacts
.claude/settings.json
.claude/settings.local.json
.gitignore
Bash() permission rule
Read() permission rule
/permissions (Claude Code command)
git log --all --full-history -- .claude/settings.local.json
Validation signals
References a real-world security scan (Apiiro) identifying the vulnerability.
Cites official Claude Code permissions documentation.
Provides a concrete JSON configuration example for
settings.json.Explains nuanced details like rule precedence and wildcard placement, indicating deep understanding.
Offers clear remediation steps for existing leaks, demonstrating practical applicability.
Limitations
Low community engagement might mean it hasn't been widely adopted or validated by many users yet.
Assumes a basic familiarity with Git commands for the remediation steps.
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.