LLM API Guide

Claude Code v2.1.314: blockWritesOutsideWorkingDirectories, Gateway IdP, Fixes

Configure permissions.blockWritesOutsideWorkingDirectories and gateway upstream IdP groups in Claude Code v2.1.314.

Summary

  1. Set permissions.blockWritesOutsideWorkingDirectories to true in Claude Code v2.1.314 to force Write, Edit.
  2. Understand the boundaries of this setting: it blocks writes to $TMPDIR and ~/.claude/plans/, is silently ignored on CLI versions below v2.1.314.
  3. Route enterprise Claude Apps Gateway traffic by IdP groups using the v2.1.314 upstreams groups list.
  4. Upgrade to pick up the late-October fixes for partial-read overwrites on large subdirectory CLAUDE.md files (v2.1.312) and missing-summary conversation wipes.

If you run Claude Code in auto, acceptEdits, or bypassPermissions mode, nothing in the default tool permission layer stops the agent from using Write or Edit to modify files in a sibling repository, overwrite ~/.zshrc, or alter a symlinked ~/.claude/settings.json in your home directory. Claude Code v2.1.314 (released October 30, 2026) adds a dedicated hard switch for this: permissions.blockWritesOutsideWorkingDirectories. Newer Claude Code releases and other API changes are covered in a later roundup of model and API updates.

When I enable permissions.blockWritesOutsideWorkingDirectories, the Write, Edit, and NotebookEdit tools reject any file path outside the current working directory and explicitly added directories, regardless of how permissive the active session mode is. This release also introduces Identity Provider (IdP) groups filtering on enterprise gateway upstreams—which holds even during upstream failover—and rolls up two critical late-October fixes that stop Claude Code from truncating large subdirectory CLAUDE.md files or wiping conversation history when /compact fails to produce a summary.

On this page

How to Configure permissions.blockWritesOutsideWorkingDirectories

You can enable this guard in your project .claude/settings.json, your global ~/.claude/settings.json, or inline via the --settings CLI flag when launching headless stages.

To lock down a repository or your local user profile, add the boolean key under the permissions object in settings.json:

json
{
  "permissions": {
    "blockWritesOutsideWorkingDirectories": true
  }
}

If you run automated pipelines or multi-stage CLI workflows with claude -p --permission-mode bypassPermissions (or --dangerously-skip-permissions), you can inject the setting directly on the command line so an implementer stage cannot write into a sibling workspace or the parent checkout:

bash
claude -p "Refactor the authentication middleware" \
  --permission-mode bypassPermissions \
  --settings '{"permissions":{"blockWritesOutsideWorkingDirectories":true}}'

What makes this setting different from standard permissions.deny rules is its precedence. In my testing on v2.1.314, blockWritesOutsideWorkingDirectories: true overrides both the session permission mode and explicit allow rules. Even if I launch a session with --permission-mode acceptEdits and explicitly pass --allowedTools "Edit(/Users/dev/outside-repo/**)", any attempt by Write, Edit, or NotebookEdit to touch /Users/dev/outside-repo is blocked immediately.

When a write is rejected, Claude Code returns a tool error directly to the model with the following message:

text
<path> is outside <working_dir>, <added_dir>; 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.

Because the check evaluates against the active working directory list, passing --add-dir /path/to/shared-lib at startup or running /add-dir /path/to/shared-lib inside the interactive TUI whitelists that folder as an authorized working directory.

What Gets Blocked vs. Allowed (The $TMPDIR and ~/.claude/plans/ Catch)

Before turning blockWritesOutsideWorkingDirectories on globally in ~/.claude/settings.json, you need to know how it treats Claude Code's own internal paths and system scratch folders. While testing v2.1.314 across user settings, project .claude/settings.json, and --settings flags, I found that the path boundary is strict enough to break a few built-in workflows if you are not expecting it.

Target Path / Operation blockWritesOutsideWorkingDirectories: false blockWritesOutsideWorkingDirectories: true Notes
Primary working directory (cwd) Allowed Allowed Standard project files work normally.
Directories added via --add-dir or /add-dir Allowed Allowed Treated as first-class working directories.
Sibling repos & ~/.zshrc / ~/.codex/config.toml Allowed (in bypass/auto modes) Blocked Rejects Write, Edit, and NotebookEdit.
Session auto-memory (~/.claude/projects/<slug>/memory/) Allowed Allowed Exempted so the agent can still record project memory.
Claude Code plan files (~/.claude/plans/) Allowed Blocked Breaks workflows where the agent writes plan files via Write.
System temp folder ($TMPDIR) Allowed Blocked Fails unless you pass $TMPDIR via --add-dir.
Claude Code settings.json files Allowed (if permitted) Blocked Prevents the agent from modifying its own config files.
Shell redirects (Bash echo > ../outside/file) Allowed Allowed Bash is not gated by this setting; requires OS sandbox.

The biggest practical side effect is that $TMPDIR and ~/.claude/plans/ are rejected when the setting is enabled. Session auto-memory under ~/.claude/projects/<slug>/memory/ has an explicit exemption and continues to write without issues, so you do not lose persistent memory across sessions. However, when the model tries to save a plan file to ~/.claude/plans/ or write an intermediate file into $TMPDIR using the Write tool, the tool call fails. Because of that, I do not enable this flag globally for interactive daily use where I rely on plan files; instead, I enable it in project-level .claude/settings.json files or pass it via --settings on automated --permission-mode bypassPermissions runs.

Silent Ignore on CLI Versions Older Than v2.1.314

If you commit "blockWritesOutsideWorkingDirectories": true into a shared repository's .claude/settings.json, keep in mind that Claude Code CLI versions prior to v2.1.314 do not validate unknown keys under permissions. When I loaded a .claude/settings.json containing this key in v2.1.296, the CLI parsed the rest of the file, executed SessionStart hooks normally, and printed zero warnings—while allowing out-of-tree writes right through.

If your team relies on checked-in .claude/settings.json files to enforce repo boundaries, add a version check to your repo's setup or preflight script so developers on older binaries know the guard is inactive:

bash
CURRENT_VER=$(claude --version | awk '{print $1}')
REQUIRED_VER="2.1.314"

if [ "$(printf '%s\n' "$REQUIRED_VER" "$CURRENT_VER" | sort -V | head -n1)" != "$REQUIRED_VER" ]; then
  echo "WARNING: Claude Code $CURRENT_VER ignores blockWritesOutsideWorkingDirectories. Upgrade to >= $REQUIRED_VER."
fi

Don't Confuse This With the Windows Low Integrity EPERM Error

If you upgraded to v2.1.312 or v2.1.314 on Windows and suddenly see out-of-directory writes failing with EPERM: operation not permitted, open '<path>.tmp.<pid>.<hash>', that is not caused by blockWritesOutsideWorkingDirectories. Starting in v2.1.312, Claude Code on Windows drops non-elevated processes to a Low Integrity level (S-1-16-4096). That OS-level token restriction causes Write, Edit, and Bash file outputs outside the working directory to fail with EPERM unless you run an elevated shell, whereas blockWritesOutsideWorkingDirectories always returns the explicit message telling you to run /add-dir.

Why Bash and Worktree Subprocesses Still Bypass the Guard

Turning on blockWritesOutsideWorkingDirectories does not mean an unattended agent is confined to your repository folder. The setting only inspects calls to the Write, Edit, and NotebookEdit tools. It has zero visibility into what happens inside the Bash tool or child processes spawned by build and test runners.

I have seen this trip up developers who assume that combining git worktree isolation (isolation: "worktree") with tool write guards creates a filesystem boundary. Git worktrees only separate the git checkout directory; the process still runs with your full user privileges across the entire filesystem. If a subagent running inside an isolated worktree executes cargo test or npm test, and a poorly written test fixture executes sh -c with an unescaped string that triggers rm -rf ~ or mv against $HOME, every per-call permission check—including command hooks, permissions.deny rules, and blockWritesOutsideWorkingDirectories—only sees the outer cargo test tool call and lets it run.

The same gap applies to direct shell commands. Even with blockWritesOutsideWorkingDirectories: true, if the model decides to work around a rejected Write call by running cat << 'EOF' > ../sibling-repo/config.json or sed -i inside Bash, the write succeeds.

To actually lock both built-in file tools and shell subprocesses to the working directory, you have to pair blockWritesOutsideWorkingDirectories with Claude Code's OS-level Bash sandbox (which uses Seatbelt on macOS and bubblewrap on Linux/WSL2) and forbid unsandboxed fallback commands:

json
{
  "permissions": {
    "blockWritesOutsideWorkingDirectories": true
  },
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "filesystem": {
      "denyWrite": [
        "~/.ssh",
        "~/.config",
        "~/.zshrc",
        "~/.claude/settings.json"
      ]
    }
  }
}

When I run this combined configuration on macOS or Linux, blockWritesOutsideWorkingDirectories stops Write and Edit from touching anything outside the repo (including symlinked dotfiles that sandbox.filesystem.denyWrite alone does not catch on built-in tools), while the OS sandbox blocks Bash redirects and cargo test child processes from modifying files outside the workspace. If your test suite mocks remote commands or manipulates user files, I also set export HOME="$(mktemp -d)" inside the test runner environment so any stray ~ expansion points to an ephemeral directory rather than your real home folder.

Enterprise Gateway: Routing upstreams by IdP groups

Alongside local filesystem guards, Claude Code v2.1.314 expands the enterprise Claude Apps Gateway with a groups property on upstreams. When you define a groups list on an upstream block, the gateway only routes requests to that upstream if the authenticated developer belongs to one of the listed IdP groups—and it strictly enforces that group boundary on failover too.

Before v2.1.314, if you set up primary and backup upstreams for different departments (for example, separating a production engineering Bedrock/Vertex deployment from a general R&D pool), a primary outage could cause failover traffic from one team to spill into another department's upstream and burn through their reserved capacity or compliance boundary. Adding groups to each upstream entry prevents cross-group spillover during failover.

When you combine v2.1.314's upstreams[].groups with the oidc.user_id_claim added in v2.1.312 and the pooled_budget controls introduced in v2.1.316 (which I covered in detail in my Claude Code v2.1.316 guide on CLAUDE_CODE_DISABLE_ULTRATHINK, pooled budgets, and OIDC claims), you get a complete identity-to-upstream enforcement chain:

yaml
auth:
  oidc:
    issuer: "https://login.microsoftonline.com/<tenant-id>/v2.0"
    client_id: "claude-gateway-prod"
    user_id_claim: "oid"
    groups_claim: "groups"

upstreams:
  - name: "core-platform-primary"
    provider: "anthropic"
    api_key_env: "ANTHROPIC_CORE_KEY"
    groups:
      - "entra-group-core-platform"
      - "entra-group-secops"
  - name: "core-platform-failover"
    provider: "vertex"
    project_id: "corp-claude-failover"
    groups:
      - "entra-group-core-platform"
      - "entra-group-secops"
  - name: "general-eng-pool"
    provider: "anthropic"
    api_key_env: "ANTHROPIC_GENERAL_KEY"
    groups:
      - "entra-group-all-devs"

managed:
  group_limit_mode: "min"
  policies:
    - name: "core-platform-policy"
      groups: ["entra-group-core-platform"]
      pooled_budget:
        monthly_usd: 15000
      cli:
        env:
          OTEL_RESOURCE_ATTRIBUTES: "cost_center=cc-1042,team=core-platform"
        settings:
          permissions:
            blockWritesOutsideWorkingDirectories: true
    - name: "general-eng-policy"
      groups: ["entra-group-all-devs"]
      pooled_budget:
        monthly_usd: 5000
      cli:
        env:
          OTEL_RESOURCE_ATTRIBUTES: "cost_center=cc-2099,team=general-eng"

The Multi-Group Attribution Catch (first-match-wins)

There is one architectural quirk you need to watch out for when deploying group-based gateway configs for developers who belong to multiple Entra ID or Okta groups. While upstreams[].groups accurately restricts which backend endpoints a developer's token can hit, managed.policies evaluates in strict list order (first-match-wins).

If an engineer belongs to both entra-group-core-platform and a second project group because they split their day across two cost centers, the gateway always applies the cli.env.OTEL_RESOURCE_ATTRIBUTES from whichever policy appears first in the config file. Even worse, because group_limit_mode defaults to min, their spend ceiling is constrained by the lowest limit across both groups, while 100% of their OpenTelemetry billing attribution gets logged against the first group in the list. Developers cannot override a gateway-managed env variable from their local .claude/settings.json to switch billing groups mid-day. To avoid misattributing token spend, order your most specific project policies above broad umbrella groups (like all-devs), or keep billing-attributed developers in mutually exclusive IdP groups per gateway endpoint.

Two Destructive Overwrite Bugs Fixed in This Release Cycle

Many developers searching for the v2.1.314 write guard are upgrading after running into two severe data-loss bugs that surfaced in late October: large subdirectory CLAUDE.md files getting truncated on save, and /compact wiping out entire conversation histories. While both fixes are often discussed together with v2.1.314, they actually landed in the immediately preceding point releases—v2.1.311 (October 26, 2026) and v2.1.312 (October 27, 2026)—so upgrading your CLI to v2.1.314 or newer resolves all of them at once.

1. Truncated Overwrites on Large Subdirectory ./CLAUDE.md and Rules Files (Fixed in v2.1.312)

In monorepos, it is common to keep a large ./CLAUDE.md, .claude/rules/ file, or @-included instruction file inside a subdirectory. Prior to v2.1.312, when Claude Code auto-loaded or inspected one of these large files in a subdirectory, it frequently read only the opening lines of the file due to read-window truncation. Later in the session, if you asked Claude to append a new convention or update the rules file, the model called the Write tool using only the partial header it had seen in context—silently overwriting the entire file and deleting everything below the initial read offset.

Starting in v2.1.312, the Write tool tracks whether the model has read the complete contents of an existing CLAUDE.md, rules file, or @-included file in a subdirectory. If the model only saw the beginning of the file and attempts a full-file Write, Claude Code blocks the overwrite and instructs the model to either read the rest of the file first or use Edit to make an in-place change.

If you lost a CLAUDE.md or source file to a bad Write call before upgrading and the file was not yet committed to git, check ~/.claude/file-history/<session-id>/ on your machine (or ~/Library/Application Support/Code/User/History/ if you had it open in VS Code). Claude Code saves pre-edit snapshots of files touched by Write and Edit inside ~/.claude/file-history/, which has saved me from having to rewrite untracked rules files from scratch.

2. /compact Replacing the Conversation With a Summary-Less Reply (Fixed in v2.1.311)

The second replacement bug happens during context compaction. When you run /compact, Claude Code appends a compaction prompt to the end of the conversation instructing the model to generate <analysis> and <summary> blocks, and then replaces your prior conversation history with that summary.

On models with aggressive prompt-injection filters—most notably claude-sonnet-5 during manual /compact runs—the model sometimes misidentified the appended compaction system prompt (CRITICAL ... create a detailed summary of the conversation) as a hostile prompt injection attached to the tail of the user's message. Instead of outputting a <summary> block, the model replied with a warning flagging the text as an injected instruction, or simply answered the last user question normally. Prior to v2.1.311, Claude Code did not verify that a summary block existed before truncating the history: it saved the model's refusal or one-line answer as the new compacted context, permanently wiping the rest of the session while printing Compacted in the UI.

In v2.1.311 (documented under ## 2.1.311 in the official Claude Code CHANGELOG), Anthropic updated the compaction handler so that if the model's response does not contain a summary, Claude Code requests the summary a second time before replacing the conversation history. Upgrading to v2.1.314 also resolves the earlier v2.1.296 compaction bug where manual /compact could leave an empty system block in the payload and trigger API Error: 400 messages.3: system content must contain at least one block (if you are still hitting 400 errors on custom proxies after compacting, see my troubleshooting guide for Claude Code API Error 400 messages).

One final note when you move to v2.1.314: if you use the VS Code extension or the Claude Desktop Code tab, v2.1.314 also enables automatic idle compaction for conversations that exceed 200K tokens once the session goes idle and the prompt cache expires. Unlike the broken manual /compact behavior on older builds, this runs through the updated summary verification path so your long sessions are summarized cleanly before the expired cache forces a full re-prefill bill.

Sources and checks

  1. Claude Code v2.1.314
  2. v2.1.311
  3. v2.1.312
  4. Claude Code CHANGELOG