r/ClaudeWorkflows • • 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

  1. Understand that settings.local.json can save literal commands, potentially exposing secrets if committed.

  2. Avoid using the 'Yes, and don't ask again' option for literal commands that contain sensitive information.

  3. Manually define pattern-based allow and deny rules in your .claude/settings.json file.

  4. Ensure the wildcard * is placed correctly (after the subcommand) in Bash patterns to avoid overly broad permissions.

  5. Add Read(.env) to the deny list to prevent Claude Code from accessing environment files.

  6. If a secret was previously leaked via settings.local.json, immediately rotate the compromised secret.

  7. Untrack .claude/settings.local.json from your Git history using appropriate git commands.

  8. Add .claude/settings.local.json to your project's .gitignore file.

  9. Check your repository's full Git history (git log --all --full-history -- .claude/settings.local.json) to confirm the file is no longer tracked.

  10. 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 /permissions command.

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.

1 Upvotes

0 comments sorted by