To stop Claude Code from writing files, you need to set a permission boundary using the tool's built-in permission modes and the permissions.json file. By default, Claude Code can ask before writing, but you can restrict it to read-only or deny writes entirely. The key is to configure the permission system before you start a session, then verify with a test command. This guide walks you through the exact steps, including how to allow reads but block writes, how to allow writes only in specific folders, and how to revert changes if you make a mistake.

What You'll Need

  • Claude Code installed and logged in (CLI tool from Anthropic).
  • A terminal or command prompt on your computer.
  • Access to your project folder where Claude Code will run.
  • Basic familiarity with editing JSON files (for the permissions file).

Step-by-Step

  1. Understand the permission modes. Claude Code has three main permission settings: acceptEdits (allows file writes without asking), bypassPermissions (allows all actions including writes and tool use), and default (asks before each action). To stop writes entirely, you want to disable both acceptEdits and bypassPermissions. You can do this via command-line flags or the settings file.
  2. Start Claude Code with the read-only flag. The simplest way to stop writes for a single session is to launch Claude Code with the --permission-mode flag set to read-only. In your terminal, navigate to your project folder and run: claude --permission-mode read-only. This tells Claude Code to never write or edit files; it can only read files and respond with text. This is the fastest way to test if your workflow works without any file changes.
  3. Set the permission mode in the settings file for persistent changes. If you want to stop writes every time you run Claude Code in a specific project, edit the .claude/settings.json file in your project root. Open it in a text editor and add or modify the permissions object. For example, set "defaultMode": "read-only". If the file doesn't exist, create it. The exact structure is: { "permissions": { "defaultMode": "read-only" } }. Save the file. Now every time you start Claude Code in that folder, it will be read-only.
  4. Use the permissions.json file for granular control. For more control, you can create a .claude/permissions.json file. This file lets you allow or deny specific tools, like Write or Edit, and even restrict them to certain file paths. To deny all writes, add a rule like: { "deny": [ { "tool": "Edit", "path": "**" }, { "tool": "Write", "path": "**" } ] }. This tells Claude Code to refuse any edit or write operation anywhere in the project. You can also allow reads by not denying the Read tool.
  5. Allow writes only in a specific subfolder. If you want Claude Code to write only to a scratch folder but nowhere else, use a permission rule like: { "allow": [ { "tool": "Write", "path": "scratch/**" }, { "tool": "Edit", "path": "scratch/**" } ], "deny": [ { "tool": "Write", "path": "**" }, { "tool": "Edit", "path": "**" } ] }. The order matters: allow rules are checked first, then deny rules. This way, writes to scratch/ are allowed, but any other write is denied.
  6. Test the configuration. After setting the permission mode or editing the permissions file, start Claude Code and ask it to make a simple change, like "Edit this file to add a comment". If you've set read-only mode, Claude Code should respond that it cannot edit files. If you've set a deny rule, it should refuse with a permission error. If it still writes, check your settings file for syntax errors or typos.
  7. Use the interactive permission prompt to your advantage. Even without setting a specific mode, Claude Code will ask for permission before each write by default. When you see the permission prompt, you can choose "No" to deny that specific write. To stop all writes for the session, you can also type !permissions during a session to open the permission manager and switch to read-only mode.
  8. Verify with a dry run. If you're unsure about a change, you can use the --dry-run flag (if available in your version) to see what Claude Code would do without actually doing it. This is not a substitute for permission settings, but it helps you preview actions. Check your version's help with claude --help to see if this flag exists.

Common Mistakes

  • Editing the wrong settings file. Claude Code uses multiple settings files: user-level (in your home directory) and project-level (in .claude/). If you edit the user-level file, it affects all projects. If you edit the project file, it only affects that project. Make sure you're editing the right one.
  • Forgetting to save the JSON file. A common error is editing the permissions file but not saving it before starting Claude Code. The tool reads the file at startup, so you must save it first.
  • Using the wrong tool name. In permissions rules, the tool names are case-sensitive. Use Write for creating files and Edit for modifying existing files. If you use lowercase, the rule won't match.
  • Overly broad deny rules. If you deny Read as well, Claude Code can't even see the files, which might break its ability to answer questions. Only deny Write and Edit unless you have a reason.
  • Not testing after changing settings. You might think you've set read-only, but a typo in the JSON can cause the setting to be ignored. Always test with a simple edit request.

Tips

  • Use the --permission-mode flag for quick tests. It's the fastest way to try read-only without editing files.
  • Keep a backup of your permissions.json. If you experiment, you can revert easily.
  • Combine with a git commit. Before letting Claude Code write, commit your current code. Then if something goes wrong, you can revert.
  • Use the interactive permission manager. During a session, type !permissions to see and change the current mode without restarting.
  • Check the official documentation. The permission system evolves; the --help command shows the current flags.

Troubleshooting

Claude Code still writes files despite read-only mode. First, check that you started the session with the correct flag or that the settings file is valid. Run claude --permission-mode read-only and then ask it to edit a file. If it still edits, your version might not support that flag—check claude --help for the exact syntax. Alternatively, the project settings might be overridden by a user-level setting that allows writes. Look in your home directory for .claude/settings.json and remove any acceptEdits or bypassPermissions flags.

Permission errors when you want to allow writes. If you've set deny rules too broadly, Claude Code might refuse to write even in allowed folders. Double-check the order of rules in your permissions.json. Allow rules must come before deny rules. Also, ensure the path patterns match exactly. Use ** for recursive matching, not just *.

Settings file not being read. If your changes have no effect, confirm the file is named exactly settings.json or permissions.json and is in the .claude folder of the project root. Also, ensure the JSON is valid—use a validator if needed. Claude Code won't warn you about invalid JSON; it just ignores it.

Can't find the .claude folder. It might be hidden. On macOS/Linux, use ls -a to see hidden files. On Windows, use dir /a. If it doesn't exist, create it.

Frequently Asked Questions

Can I stop Claude Code from writing files entirely, including the permissions file itself?

Yes, you can set the permission mode to read-only, which prevents all writes, including to its own config files. However, the settings file is read at startup, so you can still edit it manually before launching.

What's the difference between acceptEdits and bypassPermissions?

acceptEdits allows file edits without prompting, but other tools may still ask. bypassPermissions skips all permission checks, including for bash commands and network access. To stop writes, disable both.

Will read-only mode still let Claude Code run bash commands?

Yes, read-only mode only affects file writes and edits. Bash commands are still subject to the default permission rules, so Claude Code will ask before running them. If you want to block bash too, you need to deny the Bash tool in permissions.json.

How do I allow Claude Code to write only to a specific file?

Use a permission rule like { "allow": [ { "tool": "Edit", "path": "src/main.js" } ] } and then deny all other edits. The allow rule must be listed before the deny rule.

Can I change permissions mid-session?

Yes, type !permissions in the Claude Code prompt to open the permission manager. From there, you can switch to read-only or adjust rules without restarting.

Is there a way to preview what files Claude Code will change?

Some versions support a --dry-run flag that shows actions without executing them. Check your version's help. If not available, you can use git diff after a change to see what was modified.