This guide shows you how to prevent API keys, passwords, and personally identifiable information (PII) from being sent to AI tools like Cursor and Claude. You’ll learn practical steps to redact, mask, and manage sensitive data so your prompts stay clean and your credentials stay private.
What You’ll Need
- Access to the settings or configuration files for Cursor and Claude (e.g., Claude Code’s settings.json or Cursor’s rules).
- A text editor for creating scripts or configuration snippets.
- Basic familiarity with environment variables and command-line tools.
Step-by-Step
- Identify all sensitive data in your workflow. List every API key, token, password, and piece of PII (names, emails, phone numbers, addresses, IPs) that might appear in your code or prompts. This includes hardcoded values in source files, .env files, and configuration files.
- Move secrets to environment variables. Replace hardcoded values with references like
process.env.API_KEYoros.environ['API_KEY']. Store the actual values in your shell profile or a secure secret manager, not in files that AI tools might read. - Use .gitignore to exclude secret files. Ensure files like
.env,.env.local, and any config files containing secrets are listed in your.gitignore. This prevents them from being committed and accidentally included in AI context. - Configure Cursor’s ignore rules. In Cursor, create a
.cursorignorefile in your project root and add patterns for files that should never be read by the AI, such as.env,*.pem,secrets/*, and**/config/credentials.json. - Set up Claude Code’s permissions. In Claude Code, use the
settings.jsonfile to definepermissions.allowandpermissions.denyrules. For example, deny reading.envand allow only specific directories. You can also useignorePatternsto exclude sensitive files. - Create a pre-prompt redaction script. Write a small script (Python, Node, or shell) that scans your selected files for patterns like
sk-...,AKIA..., or email addresses, and replaces them with placeholders like[REDACTED]before you copy code into a prompt. Run this script before pasting any code into Cursor or Claude. - Use a clipboard manager with redaction. Tools like CopyQ or Ditto allow you to create custom commands that transform clipboard content. Set up a command that strips lines matching secret patterns before you paste into an AI chat.
- Manually review before sending. Even with automation, always scan your prompt for anything that looks like a key or personal data. Look for long alphanumeric strings, common key prefixes, or names and emails.
- Use Cursor’s built-in secret detection. Cursor has a feature that attempts to detect and warn about secrets when you include them in prompts. Ensure this is enabled in settings. If it warns you, heed the warning and redact.
- Test with a dummy key. Periodically, paste a fake key like
sk-test-1234567890abcdefand see if it appears in any logs or outputs. This helps verify your redaction is working.
Common Mistakes
- Relying solely on AI’s built-in detection—it’s not foolproof and may miss custom formats.
- Forgetting to redact PII like names or emails in code comments or logs.
- Ignoring that Cursor can read your entire workspace unless you set ignore rules.
- Putting secrets in files that are not ignored, like
config.jsorsettings.py. - Copying entire files into prompts without checking for embedded secrets.
Tips
- Use a dedicated secrets manager (like a password manager or cloud KMS) to generate and rotate keys.
- For Claude Code, use the
--dangerously-skip-permissionsflag only in trusted, isolated environments, as it bypasses all permission checks. - In Cursor, use the
@symbol to reference specific files rather than pasting raw content—this still sends the file content, so ensure the file is clean. - Create a template for prompts that includes a placeholder for sensitive data, so you never forget to redact.
- Regularly audit your AI chat logs (if you keep them) for any accidental leaks.
Troubleshooting
- Cursor still reads ignored files. Check that
.cursorignoreis in the correct root and that the patterns match the file paths. Also, restart Cursor after changes. - Claude Code ignores settings. Ensure
settings.jsonis in the expected location (~/.claude/settings.jsonfor user-level, or.claude/settings.jsonin the project). Validate JSON syntax. - Redaction script misses some patterns. Expand your regex to cover more variations, and test with sample data.
- Secrets still appear in logs. Check if your terminal or AI tool logs the full prompt. Disable logging or use a separate environment for sensitive work.
- Environment variables not available in AI tool. If you use a GUI like Cursor, it may not inherit your shell’s env vars. Use a tool like
direnvor explicitly set them in the project’s.env(but then ignore that file).
Frequently Asked Questions
Q: Can Cursor or Claude see my .env file?
A: Only if you explicitly include it in the prompt or if you haven’t set ignore rules. By default, Cursor may read files in your workspace, but you can block it with .cursorignore.
Q: Is it safe to paste a code snippet that contains a placeholder like sk-xxx?
A: Yes, as long as the placeholder is not a real key. Using a clear fake like sk-test-123 is safe.
Q: What if I need to share code with an AI that has real keys in it?
A: Never do that. Redact first, then share only the non-sensitive parts. If you must share the full code, use a local model or a secure sandbox.
Q: Does Cursor have a built-in secret scanner?
A: Yes, Cursor attempts to detect secrets and warns you, but it’s not perfect. Always double-check.
Q: How do I handle PII in logs or error messages?
A: Use a logging library that automatically redacts emails, IPs, and names. Or write a filter that scrubs these before sending to AI.
Q: Can I use environment variables in Cursor’s prompt?
A: Not directly in the prompt, but you can reference files that read env vars. However, the file content is still sent, so ensure the file doesn’t contain the actual secret.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- OnePlus Watch 2 Teased? What We Know
- Vagrant vs Docker: Which Should You Use for Development?
- iQOO Neo 10 vs Neo 10R: Which Phone Should You Choose?
- Embedded OS: What They Do & When You Need One
- Best Sony E-Mount Lenses: Format & Subject Guide
- Samsung Galaxy Note Discontinued? Status Explained