AWS Builder Center

Running Claude Code Securely: A DevSecOps Guide to Keeping Secrets Out

How to get Claude Code's productivity without letting an autonomous agent read your .env: deny-lists, sandbox credential masking, hooks, and safe IDE integration, validated against the official docs.

Claude Code, Anthropic's agentic command-line interface (CLI), is one of the most capable coding assistants available, but it runs with real access to your filesystem, shell, and network. From a DevSecOps perspective that raises an obvious question: how do you get the productivity without letting an autonomous agent read your  .env  file, exfiltrate a token through a web request, or silently rewrite a launch configuration?
This post answers three practical questions:
  • How do you secure Claude Code so it does not touch secrets and credentials?
  • How does a single developer get the most out of it?
  • Can it be integrated with an integrated development environment (IDE) like Visual Studio Code (VS Code)?
Everything below is validated against Anthropic's official Claude Code documentation as published on 30 July 2026. Because the configuration surface changes quickly, exact field names are worth reconfirming against  code.claude.com/docs  before a production rollout, and I have noted the minimum Claude Code version where a feature is version gated.

1. Securing Claude Code so it does not touch secrets

Permission deny-lists: the strongest, simplest control

The single most effective control is an explicit deny-list in your settings file. Deny rules are absolute. No other scope, and no permission-mode override, can beat them, and denied files are also excluded from the IDE  @ -mention context so they never reach the model through file selection either.
Place this in  .claude/settings.json  for a project, or  ~/.claude/settings.json  to apply it across all your projects:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(~/.ssh/**)",
"Read(~/.aws/**)",
"Read(~/.kube/**)",
"Bash(curl *)",
"WebFetch"
]
}
}

Claude Code is read-only by default. Editing files, running tests, and executing shell commands each require explicit approval, and commands that fetch from the web such as  curl  and  wget  are never auto-approved. The tool also uses fail-closed matching: any command that does not match an allow rule defaults to requiring manual approval, and a suspicious variant of a previously allowlisted command still triggers a prompt.

Sandboxing: operating-system-level isolation and credential masking

The more robust mechanism is the built-in Bash sandbox, which isolates shell execution at the operating-system level on macOS, Linux, and Windows Subsystem for Linux version 2 (WSL2). Native Windows is not supported, so on Windows you run Claude Code inside a WSL2 distribution.
The  sandbox.credentials  setting (requires Claude Code v2.1.187 or later) protects specific files and environment variables from sandboxed commands. Each entry takes a  mode :
  •  mode: deny  unsets the environment variable before each sandboxed command runs, or denies reads of the named file.
  •  mode: mask  (requires v2.1.199 or later) lets a command authenticate while hiding the real secret value. The sandboxed command sees a per-session sentinel value instead of the real credential. When a request leaves the sandbox for one of the credential's  injectHosts , a proxy substitutes the real value back in. The command, and anything it logs, never holds the real credential, but its requests still authenticate.
{
"sandbox": {
"enabled": true,
"credentials": {
"envVars": [
{
"name": "GITHUB_TOKEN",
"mode": "mask",
"injectHosts": ["api.github.com"]
}
]
}
}
}

One important caveat that is easy to miss: masking fails closed. The proxy has to see request contents to substitute the credential, so it must terminate Transport Layer Security (TLS) itself. Without a TLS-terminating proxy configured, the sandboxed command sees only the sentinel value and its requests will not authenticate. In other words, the example above does not "just work" for  gh  or  npm publish  until you have set up the proxy. Plan for that step rather than assuming masking is transparent.
Two further sandbox notes for a security review:
  • Explicit deny rules are always respected even in auto-allow mode, and destructive commands such as  rm  targeting  / , your home directory, or other critical paths still trigger a prompt.
  • Be careful with  allowUnixSockets . Allowing something like  /var/run/docker.sock  effectively grants access to the host through the Docker socket and can lead to a sandbox bypass.

Model Context Protocol servers and web fetches

Model Context Protocol (MCP) servers and web fetches are the other leak vectors worth locking down. Restrict which MCP servers are allowed to load, and deny-list tool patterns the same way you deny file reads. For organizations, administrators can deploy a  deniedMcpServers  policy and, for Claude Code managed through Mobile Device Management (MDM), a  managed-mcp.json  file that enforces an allowlist or disables MCP entirely. Anthropic reviews connectors against its policy before listing them, but it does not security-audit or manage third-party MCP servers, so prefer servers you wrote or providers you trust.
Web fetches run in an isolated context window to avoid injecting potentially malicious prompts, and tools that make network requests require approval by default.

Hooks: a programmatic last line of defense

Hooks are user-defined shell commands, Hypertext Transfer Protocol (HTTP) endpoints, or prompts that run at specific lifecycle points. A  PreToolUse  or  PostToolUse  hook can inspect a tool call or its output, scan for patterns such as  password ,  secret ,  token , or  key= , and return a deny decision before the result ever reaches Claude's context or is written to disk. This gives you an enforcement layer that does not depend on the model's judgment.

Enforcing all of this across a team

Managed settings, delivered through server-managed configuration at sign-in or through operating-system policy (a macOS property list, a Windows registry key, or a  managed-settings.json  file), cannot be overridden by user or project settings. When managed settings configure  sandbox.filesystem  or list any  sandbox.credentials.files  entry, only managed settings can change that key, so an administrator-deployed restriction stays in force. Use this scope for security policies that must be enforced organization-wide.

2. Getting the most out of it as a solo developer

Claude Code uses a layered settings model. Understanding the four scopes lets you separate personal defaults from team-shared standards:
  • User scope, in  ~/.claude/settings.json , holds your personal defaults and deny-list across every project.
  • Project scope, in  .claude/settings.json , is checked into version control and shared with collaborators. Use it for team-agreed allow rules for safe commands such as  Bash(npm run test *) .
  • Local scope, in  .claude/settings.local.json , is gitignored and holds machine-specific overrides and experiments.
  • Managed scope, described above, is deployed by information technology (IT) or DevOps and cannot be overridden.
When the same setting appears in more than one scope, the order of precedence is managed, then command-line arguments, then local, then project, then user. Permission rules are the exception: they merge across scopes rather than override.
Beyond permissions, the real leverage comes from a few features:
  •  CLAUDE.md  gives Claude persistent project context such as build, test, and lint commands, architecture notes, and conventions. Run  /init  to bootstrap one from an existing codebase. Files can import others with  @path/to/import  syntax up to four levels deep.
  • Path-scoped rules in  .claude/rules/*.md  keep instructions modular. A rule file with a  paths:  frontmatter field using glob patterns (for example  src/**/*  or  **/*.ts ) loads only when Claude reads a matching file, which reduces noise and saves context. Rules without a  paths:  field load every session at the same priority as  .claude/CLAUDE.md .
  • Auto memory (enabled by default via  autoMemoryEnabled ) lets Claude write notes to itself based on your corrections and preferences, carrying learnings across sessions. Both memory systems are treated as context rather than enforced configuration, so if you need to block an action regardless, use a permission rule.
  • Hooks are useful for automation as well as security, for example running your linter or test suite automatically after every edit through a  PostToolUse  hook on  Edit  or  Write .
  • Plan mode is worth using for any change that touches sensitive files, since Claude describes what it will do and waits for approval before making changes.
To progress toward maximum autonomy safely, move up the permission-mode ladder as trust grows: Manual, where Claude asks before edits and most commands, then Plan, then Accept Edits, which auto-approves file edits and a fixed set of safe filesystem commands like  mkdir ,  touch , and  mv  while still prompting for anything out of scope.

3. IDE integration with VS Code and JetBrains

Yes, and it is Anthropic's recommended way to use Claude Code in an IDE.

VS Code

The official VS Code extension requires VS Code 1.94.0 or higher and any paid Claude subscription (Pro, Max, Team, or Enterprise) or a Claude Console account. No Application Programming Interface (API) key is required. Install it from the Extensions view by searching for "Claude Code". The extension bundles its own copy of the CLI for the chat panel, though running  claude  in the integrated terminal still needs the standalone CLI installed.
It adds a chat sidebar, side-by-side inline diffs with accept, reject, or edit, plan review with inline comments before you approve,  @ -mentions of files with specific line ranges, and multiple sessions in tabs. The permission-mode selector at the bottom of the prompt box lets you switch between Manual, Plan, and Edit automatically, or you can set the default with  claudeCode.initialPermissionMode .
Under the hood the extension exposes a local IDE integration for diagnostics and diff viewing. It runs on loopback and is authenticated through a lock file under  ~/.claude/ide/ , not exposed off the machine unless you explicitly enable network-wide connections. This lock-file mechanism is documented in Anthropic's own issue tracker. Note that the lock files are always written to  ~/.claude/ide  and currently ignore  CLAUDE_CONFIG_DIR .
The same extension also installs in VS Code forks such as Cursor, Kiro, and Devin Desktop.

JetBrains

JetBrains IDEs have an equivalent plugin, but it does not bundle the CLI, so  claude  needs to be on your  PATH  separately. For remote development over Secure Shell (SSH) or WSL, install the plugin on the remote host rather than locally.

Security notes for both

  • Use Plan mode on untrusted repositories.
  • Avoid Accept Edits mode on code you have not reviewed, since it can modify IDE or launch configuration files without a prompt.
  • Remember that deny-listed files stay excluded from IDE selection sharing, so your  .env  will not be sent through an  @ -mention.
  • First-time runs on a new codebase, and new MCP servers, require trust verification. Note that trust verification is disabled when running non-interactively with the  -p  flag.

A note on running Claude Code on Amazon Bedrock

If your organization uses Amazon Bedrock as the inference path, you authenticate against your cloud provider rather than an Anthropic organization, so you restrict access through Amazon Web Services (AWS) Identity and Access Management (IAM) policies. This path also brings AWS-native controls into scope, including Virtual Private Cloud (VPC) isolation, IAM authentication, and CloudTrail audit logging. On Bedrock, Claude Code is limited to the CLI and the VS Code extension.

Summary

The security model rests on three layers that reinforce each other. Deny-lists give you absolute, simple blocks on secret paths and network commands. The sandbox adds operating-system-level isolation and credential masking so tokens authenticate without ever being visible to the model, provided you configure the TLS-terminating proxy that masking depends on. Hooks and managed settings let you enforce policy programmatically and organization-wide. Layer those over the productivity features (CLAUDE.md, path-scoped rules, auto memory, and Plan mode) and you get an agent that is both highly capable and kept firmly away from your secrets.
Because the configuration surface evolves quickly, confirm exact field names and version requirements against the official documentation before relying on them in a production rollout.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article