Claude Code can read files, change code and run commands with the access of your account. Start with a narrow working environment, backups, and explicit review—not an assumption that a permission mode or sandbox makes the machine safe. This guide covers the CLI’s configuration, not Anthropic’s separate Claude Code Security scanner.

📑Table of Contents
  1. Before changing settings: know the boundaries
  2. Nine security priorities
  3. 1. Keep valuable data out of reach
  4. 2. Select a mode deliberately
  5. 3. Deny sensitive reads, without assuming a complete barrier
  6. 4. Limit edits and shell approvals
  7. 5. Enable and verify the shell sandbox
  8. 6. Restrict network access separately
  9. 7. Treat MCP servers and hooks as code
  10. 8. Audit the effective configuration
  11. 9. Set team policy and isolate high-risk work
  12. Verify without destructive tests
  13. Frequently asked questions
  14. Continue reading

I once asked Claude Code to delete temporary working files and lost files I needed. I have also seen it edit or overwrite the wrong file. In another case, I found that colleagues had inadvertently brought .env contents into a session. Those experiences are why I treat limiting access and maintaining recoverable backups as separate tasks.

Earlier illustration of layered Claude Code security measures
Earlier illustration of layered controls; use the current nine priorities in the text rather than the labels in this image.

Before changing settings: know the boundaries

A permission mode determines which actions need approval. A sandbox restricts what covered shell commands can reach after they start. A container or VM adds an outer boundary; none guarantees safety against mistakes, prompt injection, compromised tools or every route to sensitive data.

In Claude Code v2.1.283 and later, interactive terminal and VS Code sessions have auto as their built-in starting mode, subject to settings, surface, organizational policy and availability. Earlier versions, plans, HIPAA configuration and non-interactive sessions differ. If auto is unavailable, the session starts in Manual. In auto, a classifier reviews some actions, but not every action; it can make mistakes. Check the active mode and the current permission modes documentation. For sensitive work, explicitly select Manual (default) and review requests rather than assuming that is the default.

Manual does not mean every read prompts. acceptEdits also approves file edits and certain filesystem commands. dontAsk denies actions that would otherwise prompt, but an installed mod can approve actions denied only by that mode. Explicit deny rules are evaluated in every mode, including bypass; however, Anthropic documents an important mod exception: without managed settings, managed MCP configuration, or a qualifying Team or Enterprise login, a trusted installed mod may approve even a denied call. Review installed mods and the hook and mod precedence rules. Do not treat bypass as a security control.

Nine security priorities

  1. Essential — reduce exposure and back up: use a dedicated account and disposable workspace, remove production secrets, and keep tested backups outside the agent’s write access.
  2. Essential — choose the permission mode: start sensitive interactive work in Manual and inspect each approval. A prompt is a decision, not proof of safety.
  3. Essential — restrict sensitive reads: add narrowly scoped deny rules, and keep secrets outside the environment where possible.
  4. Essential — limit writes and commands: protect important paths, avoid broad allow rules, and review any proposed command. Patterns do not understand every equivalent shell invocation.
  5. Essential where supported — enable the sandbox: verify it actually starts and understand its exclusions and unsandboxed retry behavior.
  6. Recommended — restrict network access: allow only necessary destinations, and enforce egress at an external boundary when the stakes require it.
  7. Recommended — review hooks and MCP: treat both as executable integrations with their own access and supply-chain risks.
  8. Recommended — audit effective permissions: review saved grants and project configuration regularly. Remove access that is no longer needed.
  9. Recommended for teams — managed policy and isolation: centrally distribute reviewed settings and use a properly configured container or VM for high-risk work.

These are priorities, not a measured percentage of risk eliminated. What is appropriate depends on the data, host and users involved.

1. Keep valuable data out of reach

Use a dedicated account with minimal OS permissions. Work on a copy of the repository, keep credentials out of that account and avoid mounting private directories into containers. Back up files to a location the agent cannot overwrite, then test restoration. A clean Git working tree helps review changes but is not a substitute for an independent backup.

For non-engineer teammates, I prefer an engineer-maintained configuration distributed during onboarding to asking each person to edit JSON. The owner should still explain what a prompt authorizes and where to report unexpected behavior.

2. Select a mode deliberately

For an interactive terminal session, claude --permission-mode default selects Manual for that launch. Confirm the visible status and any organization-specific configuration. Do not assume all actions require approval: reads and pre-approved operations can proceed without a prompt.

Plan mode is useful for exploring a task before making edits, but its read access and classifier-approved commands still matter. acceptEdits reduces friction by approving edits and certain filesystem commands; use it only when that tradeoff is acceptable. In CI, interactive approval may not be available. Use an isolated runner, the least privilege necessary and explicit controls, and check the documented behavior for the installed version.

3. Deny sensitive reads, without assuming a complete barrier

The following example is a starting point for a project .claude/settings.json; merge it into an existing JSON object instead of overwriting other settings. It illustrates the official path-rule syntax. Adapt paths to your actual layout and version, then verify in a disposable environment.

{
  "permissions": {
    "defaultMode": "default",
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  }
}

Read rules cover Claude’s file tools and recognized file-reading Bash operations. They are not a complete operating-system access boundary: indirect access through other programs, MCP servers, hooks, or unrecognized command forms can fall outside that protection. Paths and glob semantics matter. See permission rule syntax, and use OS permissions or a separate environment to keep real secrets inaccessible.

4. Limit edits and shell approvals

A command deny pattern covers matching text, not every possible way to perform an operation. A shell can invoke scripts, interpreters, aliases and other programs; a simple list of command names cannot establish a comprehensive block. Avoid permissive rules such as a blanket approval for every package script: a project can change what a script executes. Review diffs, write scope, arguments and side effects before approving a request.

Claude’s file-tool restrictions and sandbox filesystem restrictions have different scopes. In particular, the documented permissions.blockWritesOutsideWorkingDirectories setting applies to Write, Edit and NotebookEdit, not shell commands, MCP or hook programs; it requires v2.1.314 or later. Review the settings reference for version requirements and exceptions.

5. Enable and verify the shell sandbox

The sandbox is off by default. Even when enabled, its default read access covers much of the machine, and shell processes inherit environment variables. Keep real credentials out of the environment and review the read restrictions you need.

The built-in sandbox runs on macOS, Linux and WSL2. Native Windows commands run unsandboxed; use Claude Code inside WSL2 for the supported sandbox. Linux and WSL2 need the documented dependencies. Configure through /sandbox or the settings reference, and check the actual session rather than assuming the setting was applied.

The sandbox covers Bash, PowerShell and Monitor commands and their children, not Claude’s file tools, MCP servers or hooks. Its filesystem and network boundaries depend on configuration. excludedCommands run outside the sandbox; an unsandboxed retry can also change the boundary. Do not add broad exclusions as a routine fix. Diagnose a failed command first, and do not approve an unsandboxed retry unless you understand its access and accept the risk. Sandbox auto-allow can reduce prompts for covered commands; it is not equivalent to a human reviewing each command. See sandboxing for modes, dependencies and limitations.

6. Restrict network access separately

A domain allowlist constrains covered sandboxed traffic; it is not a guarantee that secrets cannot leave the machine. A permitted destination can itself receive data, and excluded commands, MCP, hooks, local services and other processes can have different access. Check proxy and domain-matching limitations in the sandbox documentation. For sensitive workloads, use independently managed egress controls and do not place credentials in the workspace.

7. Treat MCP servers and hooks as code

Review where an MCP server comes from, the credentials and filesystem it can access, and the operations it exposes. Remove integrations you do not need. MCP permissions and a shell sandbox are different controls: a server is not automatically contained by the shell sandbox.

Hooks run programs with your environment’s privileges. PreToolUse can block or request approval, but hooks can also approve actions in documented circumstances. Their behavior depends on event, permission mode, exit status, and installed mods; test them as code, protect their configuration and avoid writing secrets to audit logs. See the hooks reference.

I have moved many workflows from MCP to CLI tools because I find them easier to inspect and constrain. That is a workflow preference, not proof that every CLI is safer: a command can also access credentials or the network. See our MCP vs CLI comparison and hooks guide.

8. Audit the effective configuration

Use /permissions to inspect rules and remove stale approvals. Review user settings (~/.claude/settings.json), shared project settings (.claude/settings.json), local project settings (.claude/settings.local.json), command-line options and managed policy. The exact precedence and exceptions are documented in the settings reference. Commit shared settings only after review; keep personal settings and secrets out of Git.

I review team permissions regularly because temporary approvals can accumulate. On my own machines I use stricter controls for work than personal projects; that difference reflects the consequences of a mistake, not an assertion that personal data needs no protection.

9. Set team policy and isolate high-risk work

Managed settings help administrators distribute policy, but do not assume every setting has identical precedence or that managed policy replaces OS isolation. In managed settings, permissions.disableBypassPermissionsMode can disable bypass mode. Admins should check the current managed-only keys and exceptions before deployment, then verify the effective settings on representative machines.

For untrusted repositories and CI, use a disposable container or VM with a non-privileged user, minimal mounts, no production credentials and controlled network access. A container with a host socket, privileged mode or broad host mounts can defeat the intended isolation. Review repository instructions, project settings, hooks and MCP definitions before allowing them to run. Non-interactive -p and SDK sessions do not display the normal workspace trust dialog; consult the permissions documentation for which project content can still load.

Verify without destructive tests

Use an isolated disposable workspace with no real secrets, valuable files, production credentials, Git remotes or network access. Create a dummy marker file, configure a matching Read deny, and request a read of that dummy path. Test a specific harmless command against a matching rule. If behavior is unexpected, stop rather than approve; inspect /permissions, settings, version and mode. A successful check proves only the tested path and operation, not that every indirect route is blocked. Never test by executing a destructive command or downloading and running remote code.

Frequently asked questions

Is Claude Code secure by default?

No mode is a safety guarantee. Current interactive sessions may start in auto mode depending on version, surface and settings. Check the mode, limit accessible data and layer permissions with isolation.

Why did my settings not take effect?

Check JSON syntax, file location, version, active mode, effective permissions and higher-priority settings. Consult the current settings documentation and restart the session when needed.

What if a command fails in the sandbox?

Check platform support, dependencies and the denied access first. An excluded command or unsandboxed retry changes the security boundary; do not approve it automatically.

What is the difference between project and local settings?

.claude/settings.json is intended for shared project settings. .claude/settings.local.json is for local project preferences and should not be committed. Check the settings documentation for precedence and trust exceptions.

Are MCP servers covered by the shell sandbox?

No. MCP servers have their own process and access. Vet the server, its tools, credentials and deployment environment separately.

Does a deny rule always win?

Deny rules apply across permission modes and take precedence over allow rules. However, the documented installed-mod exception can override a deny in setups without the specified managed controls or qualifying organization login.

What should teams watch for in CI?

Non-interactive sessions cannot rely on an interactive trust prompt. Review repository-supplied settings and integrations, isolate the runner and withhold production credentials unless explicitly required.

Is this the Claude Code Security scanner?

No. This guide is about hardening the Claude Code CLI. Claude Code Security is Anthropic’s separate code vulnerability scanning product.

Continue reading

krona23

Author

krona23

Over 20 years in the IT industry, serving as Division Head and CTO at multiple companies running large-scale web services in Japan. Experienced across Windows, iOS, Android, and web development. Currently focused on AI-native transformation. At DevGENT, sharing practical guides on AI code editors, automation tools, and LLMs in three languages.

DevGENT about →

Leave a Reply

Trending