Claude Code Patch Review: Isolate Work, Then Verify

The short version: Give Claude Code one issue, a disposable copy of the repository, and the minimum tools it needs. Treat the resulting diff as a proposal—not a tested fix or permission to merge. The important boundary is not simply which folder the agent sees; it is everything the agent, its shell, and its integrations can reach.

A coding agent can be useful for the irritatingly small bug that interrupts a larger project: a parser rejects a valid input, a retry condition is inverted, or an error message loses context. The danger is turning that small job into an open-ended session with your normal credentials, repository hooks, network access, and publishing tools attached.

This guide describes a conservative patch-review workflow, not an impenetrable security recipe. The example is hypothetical: no repository was modified, and no tests were performed for this article. Commands and settings should be checked against your installed Claude Code version and your organization’s policies before use.

Start with a bounded task, not an autonomous ticket

Choose one issue whose expected behavior can be stated in a few sentences. Record the base commit, the affected area, acceptance criteria, and what must not change. If the fix requires a schema migration, a production credential, a new dependency, or a broad rewrite, stop and renegotiate the scope rather than quietly widening the session.

A good request distinguishes an output from an action: “produce a patch for review” is not “fix the issue in production.” Ask for a concise explanation, changed-file list, test commands and results if actually run, and unresolved risks. Explicitly prohibit pushing, merging, deploying, and contacting external services unless separately authorized. Those instructions matter for intent, but they are not enforcement: Claude Code’s permissions, not the prompt or repository instructions, govern what its tools can do. [2]

For a closer look at how the model, tool calls, and execution loop fit together, see AI Agents Explained: The Architecture Behind the Hype. The key distinction here is that an agent’s ability to propose code does not make it the right party to approve that code.

Diagram describing a working copy, scoped files, and secret, permissions and network boundaries
A separate copy is not itself a sandbox.

Make a disposable clone—and understand what it does not isolate

Use a fresh clone in a controlled environment rather than your everyday checkout. Pin it to the intended, verified base commit, and record that commit in the handoff. Prefer a clean environment with no personal home directory, credential mounts, SSH agent, cloud tokens, production data, or unnecessary network route. A clone avoids sharing the main repository’s Git metadata, but a directory alone is not a security boundary: processes can still inherit the user’s environment and access whatever the operating system permits.

If the repository is sensitive, use an appropriately isolated container or virtual machine with narrowly scoped mounts and network access, subject to your security team’s guidance. Containers also need careful configuration; a privileged container or one with a host socket and sensitive mounts can undermine the intended separation. Do not use real customer data to make the example convenient.

A Git worktree is useful for keeping working files apart, but it is not equivalent to a separate clone or an operating-system sandbox. Git describes linked worktrees as sharing most repository data, including common configuration and many refs. [4] Claude Code also documents that some saved permissions in a worktree resolve to the main checkout and can apply elsewhere in that repository. [2] For a disposable security-sensitive exercise, prefer a separate clone inside the controlled environment. A worktree is a convenience when shared metadata is acceptable, not a containment guarantee.

Before launching the agent, inspect the actual base and working state with git rev-parse HEAD and git status --short . Check what the clone contains, including tracked configuration and any copied files. Do not assume a fresh checkout means the surrounding machine has no secrets.

Review the repository’s trust surface first

Source code is not the only input an agent encounters. Inspect repository instructions such as CLAUDE.md , project-level Claude settings, .mcp.json , relevant scripts, dependency manifests, Git configuration, and configured hooks before granting trust or running commands. Instructions in a repository may be legitimate project guidance, but they are still content from that repository—not authorization to change your security policy or disclose data. A dependency install, test script, or build can execute code; review what the specific command invokes.

Check the broader session too: user and managed settings, enabled plugins, MCP servers, and environment variables can extend beyond the clone. Remove or disable integrations that the task does not need through the applicable configuration, then verify what is actually enabled. If you cannot account for a hook, server, or instruction, pause rather than assuming the folder boundary covers it.

Anthropic states that an installed plugin can execute arbitrary code with the user’s privileges; plugin hooks, monitors, and server processes run outside Claude Code’s shell sandbox. [3] That makes plugin review a prerequisite, not an afterthought. A plugin name or marketplace listing alone is not proof that its current contents are safe; inspect its source and configuration, and account for updates.

Set two separate controls: sandbox and permissions

Claude Code’s built-in sandbox constrains shell commands at the operating-system level. It is off by default, and Anthropic documents that it covers shell commands and their child processes—not built-in file and web tools, MCP servers, or hooks. [1] Those other paths need their own controls. An outer container or VM can place more of the Claude Code process behind a common boundary, but it must still be configured correctly.

Do not assume the sandbox hides secrets by default. The documentation says sandboxed commands can read most of the machine by default, including credential files, and inherit Claude Code’s environment variables. [1] Start with an environment that contains no unnecessary secrets, then configure and verify read restrictions, write locations, and network rules. Avoid adding broad host paths or domains just to make a failing command work. Also consider what data may be sent to the model provider under your organization’s applicable policies.

Turn on the sandbox deliberately and use /sandbox to inspect its resolved settings and dependency status. On Linux and WSL2, the documented prerequisites include bubblewrap and socat; native Windows commands are not covered by this sandbox, though WSL2 is supported. [1] For a controlled session, a settings example in the current documentation disables unsandboxed retries:

claude --settings '{"sandbox":{"enabled":true,"allowUnsandboxedCommands":false,"failIfUnavailable":true}}'

The additional failIfUnavailable setting matters: the documentation says commands otherwise run without sandboxing if it cannot start. [1] Check for excluded commands and effective settings; disabling retries alone is not proof that every process is contained. Anthropic also notes that commands typed at the interactive ! prompt usually run outside the sandbox, so they are not a reliable way to test the agent’s sandbox. [1] Use the documentation’s verification procedure in an environment where the probes are safe, and stop if the expected restrictions are not enforced.

Separately, inspect /permissions and choose a permission mode appropriate to human supervision. Use narrow approvals, deny unnecessary tools, and review prompts rather than granting blanket access. Sandbox auto-allow and permission modes are distinct: auto-allow can let sandboxed shell commands run without individual prompts even when file-edit tools would prompt. [1] Permission rules are evaluated deny, then ask, then allow. [2] But a text-matching rule for git push is not a complete network boundary: different command forms may not match it. [2] The stronger design is no push-capable credentials and no unnecessary network route, plus human-controlled integration.

A hypothetical one-issue patch

Suppose a small Python library rejects an empty configuration value when the documented behavior is to use a default. The issue is limited to the configuration parser and its tests. A reviewer prepares a clean clone at an agreed commit inside an isolated environment, confirms the issue against the project specification, inspects the relevant instructions and scripts, and starts a sandboxed Claude Code session without repository publishing credentials.

The prompt might read:

At the recorded base commit, investigate issue #42: an empty timeout configuration value should select the documented default rather than raise an error. Limit changes to the parser and the relevant tests. Do not change public interfaces, dependencies, CI, hooks, or unrelated files. Do not read credentials, access external services, push, merge, or deploy. Explain your proposed fix, list every changed file, and report only tests actually run with their commands and results. If the requirements are ambiguous or a broader change is needed, stop and ask.

The agent may inspect the parser and propose a conditional plus a regression test. That is an illustration, not an observed outcome. The human should check that “empty” means exactly what the project specification says: perhaps whitespace-only values, zero, and missing keys have different semantics. A narrow-looking change can still alter error handling for other inputs. The reviewer should also inspect any new tests for whether they assert behavior rather than merely repeat the implementation.

If an approved test requires a dependency install, inspect the install and test scripts first, decide whether network access is necessary, and use an approved isolated setup. A successful test is evidence about the exercised cases, not proof that the patch is secure or complete. If no test runs, the handoff must say “not run,” not “passed.”

Diagram of review, checks and human release decision
Keep review, checks and the release decision under human control.

Export the proposal, then review it independently

Have the agent stop with its changes in the disposable clone. A human can inspect git status --short , git diff --stat , and git diff , checking for unexpected files, changes to security settings, unrelated edits, secrets, generated artifacts, and dependency changes. Check staged changes separately with git diff --cached ; ordinary git diff alone does not show them. Untracked files also do not appear in a normal diff. Review their contents and deliberately include approved new files in the final patch; otherwise a newly written regression test can be silently omitted.

After reviewing and staging only intended files in the disposable clone, one way to export both tracked modifications and newly staged files is git diff --cached --binary > ../issue-42.patch . Confirm the patch itself contains the intended file list and no sensitive material. Keep it outside the clone only in a controlled location. Record the exact base commit and whether any work was deliberately excluded; do not rely on a filename as provenance.

In a separate, clean review checkout at the recorded base, inspect the patch and run git apply --check ../issue-42.patch before applying it. Git documents that --check tests applicability without applying the patch; a clean check is not a code review or a test result. [5] After approval, git apply ../issue-42.patch changes working files but does not create a commit. [5] Review the resulting diff again, run the relevant tests in the approved environment, and investigate any failure or unexpected change. Avoid bypassing safety checks or forcing a patch onto a mismatched base just to make it apply.

The human owner decides whether the result meets the issue, coding standards, security requirements, and release process. Any subsequent commit, push, pull request, or merge requires separate human authorization and follows the normal workflow. The agent’s job ends at the handoff.

Reusable handoff checklist

  • Issue and scope: Link or identifier, expected behavior, out-of-scope changes, and unresolved questions.
  • Provenance: Repository identity, exact base commit, disposable clone location, and patch artifact location.
  • Trust review: Repository instructions, settings, scripts, Git hooks, plugins, and MCP servers inspected; unexpected components disabled or escalated.
  • Access boundaries: Outer isolation, secrets and mounts excluded, network policy, sandbox status, effective permissions, and any approved exceptions recorded.
  • Change inventory: All modified, staged, and new files accounted for; patch inspected for unrelated content and secrets.
  • Verification: Commands actually run, results and failures, tests not run, environment limitations, and reviewer’s independent findings.
  • Decision: Human reviewer and next action; no automatic push, merge, deployment, or production change.

The practical win is not making the agent unrestricted and hoping it behaves. It is making the job small enough to inspect, the environment limited enough to reduce the consequences of a mistake, and the handoff clear enough that a human can say yes—or no—with evidence.

Sources

  1. Anthropic: Configure the sandboxed Bash tool.
  2. Anthropic: Configure permissions.
  3. Anthropic: Plugin security and trust.
  4. Git: git-worktree documentation.
  5. Git: git-apply documentation.