TL;DR Add
"blockWritesOutsideWorkingDirectories": trueunderpermissionsin~/.claude/settings.jsonand start a new session. When Claude needs another folder, give it one with/add-dir. To keep Bash from writing outside too, turn on the sandbox as well.
permissions.blockWritesOutsideWorkingDirectories makes Write, Edit and NotebookEdit refuse to write outside your working directories in every permission mode, bypassPermissions included. Without it, whether Claude changes your ~/.zshrc or the repo next door comes down to your mode: a prompt you approve without reading, a classifier deciding for you, or nothing at all.
Who decides a write outside the project today
Your working directories are the folder you started Claude Code in, plus any you add with --add-dir or /add-dir. For a Write or Edit outside them:
| Mode | Without the setting | With the setting |
|---|---|---|
default (manual) |
Asks you | Error, no prompt |
acceptEdits |
Asks you, unless allow has a bare Write or Edit |
Error |
auto |
The classifier decides | Error |
bypassPermissions |
Writes | Error |
The acceptEdits row was checked with claude -p on v2.1.332: with no rule, the Write to a sibling folder ended up in permission_denials; with --allowedTools Write, it created the file without asking; with --allowedTools Write plus the setting, it returned the error. No allow rule gets through the block. The permissions docs say as much: don't count on an Edit(*) rule to keep Claude inside the project, use this setting.
The same bug, with and without the setting
Two sessions in auto mode, the default mode in Claude Code v2.1.332. In each one (app2 without the setting, app3 with it), main.py imports ../lib/util.py, which has a syntax error, and the request is the same: python3 main.py fails. Fix it.
Without the setting, Claude rewrote the file in the neighboring repo with a shell command, and the classifier approved it:
● Bash(cd /tmp/wm/lib && printf 'def total(xs):\n return sum(xs)\n' > util.py && cd ../app2 && python3
main.py)
⎿ 6
⎿ Allowed by auto mode
With the setting in the project's .claude/settings.json, it tried an Edit and got this back:
● Update(/tmp/wm/lib/util.py)
⎿ Error: /tmp/wm/lib/util.py is outside /tmp/wm/app3; the permissions.blockWritesOutsideWorkingDirectories
setting blocks writes outside the working directories. Ask the user to add the directory with /add-dir,
or to remove that setting.
No prompt and no classifier in between. Claude stopped, explained the cause and suggested /add-dir /tmp/wm/lib, with one line that matters: "I didn't try to get around it with a shell command". That restraint was the model's call, not the setting's: the block doesn't cover Bash, and the first session wrote outside precisely through the shell. Step 4 closes that gap.
How to turn it on
1. Put it in your user settings
In ~/.claude/settings.json, next to whatever you already have under permissions:
{
"permissions": {
"blockWritesOutsideWorkingDirectories": true
}
}
Start a new session. A true in any settings file wins, so a repo can turn it on for itself in its .claude/settings.json, but no repo can turn yours off.
2. Check it
Ask Claude: Use the Write tool to create ~/block-test.txt. If your home folder isn't one of your working directories, you get the error above and the file doesn't exist.
3. Let one specific folder through
What gets past the block is making that folder a working directory:
/add-dir ../libinside the session, which asks whether you trust the folder and whether to remember itclaude --add-dir ../libat startupadditionalDirectoriesin your~/.claude/settings.json
After /add-dir, the same Write that had failed created the file. If that folder is another repo and Claude runs git there, also see what --add-dir does with the repo's trust.
4. Close the shell too
The setting doesn't limit Bash, MCP tools or the programs your hooks run. With Bash(python3 *) allowed and the block on, a python3 -c "open('<outside folder>/f.txt','w').write('hello')" wrote outside without a word. To keep commands inside the project as well, turn on /sandbox, which limits at the OS level where each command can write.
What it blocks that you might not expect
| Case | What happens |
|---|---|
| A symlink inside the project that points outside | Error: linked/h.txt resolves through a symlink to .../outside/h.txt, which is outside ... |
additionalDirectories only in the repo's .claude/settings.json |
Doesn't count: the Write to that folder still errored. Put it in your user settings |
| Claude Code's own settings files, inside the project too | Writes to Claude Code settings files are blocked while permissions.blockWritesOutsideWorkingDirectories is on, because a settings file could lift the block. Edit them yourself |
| Worktrees | Claude Code removes EnterWorktree and ExitWorktree, and an isolation: worktree subagent can't edit when its worktree sits outside. Add .claude/worktrees with /add-dir |
| Plan files, the scratchpad and the project's auto memory | Still written as usual |
| Cloud sessions | It may not apply: the container is already the boundary |
The first three rows were tried on v2.1.332; the rest come from the settings reference.
To lift it, remove it from every file that sets it and restart. A false isn't enough while another file says true. Its twin for reads is permissions.blockReadsOutsideWorkingDirectories, which does the same for Read, Grep and Glob.
Official docs: permissions.blockWritesOutsideWorkingDirectories · Working directories · Setting blocks writes outside the working directories
Requirements
- Claude Code v2.1.314 or later. Tested on v2.1.332, on Linux, with
claude -pand an interactive session.