Prevent Claude Code From Modifying Research Data
This guide shows you how to stop Claude Code from editing or deleting your research data and scripts. By setting up file permissions, using ignore rules, and configuring Claude Code’s safety settings, you can run it for analysis or code review without risking your original files. You’ll need a basic understanding of your terminal and file paths.
What You’ll Need
- Claude Code installed and logged in
- Access to a terminal (command line)
- Your research data and scripts stored in a known directory
- Basic knowledge of file paths and permissions
Step-by-Step
- Back up your data and scripts. Before any Claude Code session, copy your research folder to a safe location (e.g.,
research_backup_$(date +%Y%m%d)). This is your safety net. - Create a
.claudeignorefile in your project root. This file tells Claude Code which files or folders it should never read or modify. Open a terminal and run:cd /path/to/your/research nano .claudeignore
Add lines for each sensitive item. For example:
data/ scripts/ *.csv *.xlsx *.R *.py
Save and exit (Ctrl+O, Ctrl+X in nano).
- Set file permissions to read-only. Make your research files immutable to prevent any process from writing to them. Use:
chmod -R a-w data scripts
This removes write permissions for all users. To change back later, use
chmod -R u+w data scripts. - Use Claude Code’s
--permission-modeflag. Start Claude Code with a restrictive mode that requires approval for any file edit. For example:claude --permission-mode plan
In plan mode, Claude Code can only propose changes, not execute them. You can also use
--permission-mode acceptEditsbut that allows edits; better to useplanordefaultwith explicit approvals. - Run Claude Code in a sandboxed environment. If you want extra safety, run Claude Code inside a Docker container or a virtual machine with only read-only access to your research folder. For example, mount your research directory as read-only:
docker run -v /path/to/research:/research:ro -it claude-code
This way, even if Claude Code tries to write, the OS blocks it.
- Monitor Claude Code’s actions with
--verbose. Start withclaude --verboseto see every command it runs. Watch for anywriteoreditcommands. If you see one, immediately interrupt (Ctrl+C) and review. - Use a separate working directory. Copy only the files you need for analysis into a temporary folder and run Claude Code there. Keep your original research untouched. For example:
mkdir /tmp/claude_work cp -r /path/to/research/* /tmp/claude_work/ cd /tmp/claude_work claude
This isolates any accidental changes.
- Review all changes before accepting. If Claude Code proposes edits, always inspect the diff carefully. Use
git diffif you have version control, or manually compare files. Never accept a change that touches your data or scripts unless you are certain.
Common Mistakes
- Forgetting to add subdirectories. The
.claudeignorefile only applies to the paths you list. If your data is indata/raw/, addingdata/covers it, but if you only adddata/raw/, other subfolders remain accessible. - Using
chmodon the wrong path. Runningchmod -R a-w .from your home directory will lock all your files, causing system issues. Always target specific folders. - Ignoring symlinks. If your research folder contains symbolic links, they bypass
.claudeignoreand permissions. Usereadlink -fto resolve them and add the real paths to your ignore list. - Not testing the ignore rules. After creating
.claudeignore, ask Claude Code to list files in the directory. If it still sees your data, the rules are wrong.
Tips
- Use version control. Even with all precautions, use Git to track changes. Commit your research before each Claude Code session, so you can revert instantly.
- Create a dedicated Claude Code config. Add settings to your
~/.claude/settings.jsonto disable file edits globally. For example, set"permissions": {"allow": []}to deny all tools by default. - Run Claude Code in a separate user account. Create a low-privilege user and run Claude Code as that user. This limits damage if something goes wrong.
- Use the
--dangerously-skip-permissionsflag only in disposable environments. Never use it on your main research machine.
Troubleshooting
Claude Code still edits files despite .claudeignore. Check that the ignore file is in the correct directory (the one you launch Claude Code from). Also, the syntax must be exact: use data/ for a folder, not data (though both work). Test with claude --debug to see which files it reads.
Permissions are not sticking. If you’re on macOS, chmod may not work on files with extended attributes. Use xattr -c data to clear them, then reapply permissions. On Windows, use icacls instead of chmod.
Claude Code ignores the read-only mount in Docker. Ensure you’re using the :ro flag correctly. Also, if you mount a file (not a directory), it must be mounted individually. Double-check your Docker command.
Claude Code crashes or hangs when it can’t write. Some tools expect write access. If you see errors, try using --permission-mode plan or provide a writable scratch directory (e.g., /tmp) for temporary files.
Frequently Asked Questions
Q: Can I still let Claude Code read my data?
A: Yes, read access is fine. The goal is to prevent writes. Use chmod -R a-w to allow reading but not writing.
Q: Does .claudeignore work like .gitignore?
A: Yes, it uses similar patterns. Lines starting with # are comments, and you can use wildcards like *.csv.
Q: What if I need Claude Code to create new files?
A: Allow it to write to a separate directory (e.g., output/) that you don’t protect. Keep your research data and scripts read-only.
Q: Is there a way to undo changes if Claude Code modifies something?
A: If you have a backup or Git, you can restore. Without those, it’s difficult. That’s why backups are essential.
Q: Can I set these protections permanently?
A: Yes, you can add the chmod commands to your system startup or use a script that runs before each Claude Code session. The .claudeignore file persists in your project.
Q: Does this work with Claude Code on Windows?
A: Yes, but use icacls instead of chmod for permissions, and the ignore file works the same.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.