Claude Code Security and Compliance: Data, Controls, Risks
A security review of Claude Code has to answer two kinds of question. What happens to our data once it leaves the laptop: is it used for training, how long is it kept, where is it encrypted? And what can the agent do on the laptop: which commands it runs without asking, how it handles untrusted content, and what we can enforce centrally? Anthropic documents both, and this guide collects the answers in one place, quoting the policy pages rather than paraphrasing them into stronger claims.
It covers the data policy (training, retention, Zero Data Retention, encryption), telemetry and how to turn it off, the client's built-in protections and their documented limits, prompt injection, MCP and cloud-session security, and a practical checklist for a regulated rollout. Certifications and compliance artefacts live in Anthropic's Trust Center; this guide does not restate them as guarantees. For enforcement mechanics, see Claude Code Enterprise Setup and Claude Code Permissions.
Training and retention by account type
Anthropic's data usage page draws the line between consumer and commercial terms:
- Consumer (Free, Pro, Max): you choose whether your data may be used to improve future models, and that includes Claude Code usage from those accounts. If you allow it, data is retained for five years; if you do not, 30 days. You can change the setting at any time in claude.ai's privacy controls.
- Commercial (Team, Enterprise, API, third-party platforms): Anthropic does not train generative models on code or prompts sent to Claude Code under commercial terms, unless the customer opts in, for example through the Development Partner Program. Standard retention is 30 days.
- Zero Data Retention is available to qualified accounts for Claude Code on Claude for Enterprise. It is not part of the standard Enterprise plan; your account team enables it per organisation after confirming eligibility.
Two exceptions are easy to miss. Transcripts you send with /feedback, /bug, or /share are retained for five years. And if you answer Yes to the optional "Can Anthropic look at your session transcript?" follow-up after a session survey, the transcript, subagent transcripts, and raw session log are uploaded (with known key patterns redacted) and kept for up to six months.
Data in transit is encrypted with TLS 1.2 or later. At rest, the Anthropic API uses AES-256 infrastructure-level disk encryption; Bedrock uses AES-256 with AWS-managed keys or your own KMS keys; Google Cloud uses Google-managed keys with CMEK available; Microsoft Foundry depends on the deployment's hosting option.
Quick reference
- If a developer signs in with a personal Pro or Max account at work, their sessions fall under consumer terms. Enforce organisation logins with managed settings such as
forceLoginOrgUUID. - Organisations with ZDR or the HIPAA configuration cannot use cloud sessions,
/web-setup, or Remote Control, because those features store session data. - For the exact legal terms, the Commercial Terms of Service and Privacy Policy govern, not this summary.
Remember this
Commercial terms mean no training by default and 30-day retention; feedback reports are the long-retention exception.
What stays on the developer's machine
Claude Code runs locally and keeps plaintext session transcripts under ~/.claude/projects/ for 30 days by default so sessions can be resumed. Anything a tool touched is in them: file contents, command output, pasted text. If Claude reads .env or a command prints a token, that value is now on disk in plain text, protected only by file permissions. Prompt history in ~/.claude/history.jsonl is kept until deleted.
For regulated environments:
- Lower
cleanupPeriodDays(minimum 1). Set it in managed settings to apply it fleet-wide. - Deny reads of secret files with permission rules, for example
Read(./.env),Read(./.env.*),Read(~/.aws/**). - Set
CLAUDE_CODE_SKIP_PROMPT_HISTORYto skip writing transcripts and prompt history, or pass--no-session-persistencewith-pin automation. - Use
claude purgeto delete one project's local state.
Credentials are stored in the macOS Keychain when available, in a 0600 file on Linux, and in a file inheriting your profile directory's permissions on Windows.
Quick reference
- Full-disk encryption on developer laptops is what protects these plaintext files at rest; check it is enforced by your device management.
- Desktop and Cowork transcripts are exempt from
cleanupPeriodDaysby default;desktopSessionCleanupPeriodDaysgives them a limit. - Endpoint DLP tools that scan home directories will see transcripts; decide whether that is desired.
Remember this
Local transcripts are plaintext copies of what Claude saw; deny secret reads and set retention centrally.
Telemetry, error reports, and how to turn them off
Claude Code sends two kinds of operational telemetry. Metrics cover latency, reliability, and usage patterns and, per the docs, never include code, prompts, or file paths. Error reports contain Claude Code's own error messages and stack traces, with known secret, path, email, and personal-information patterns redacted before sending.
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns off all non-essential traffic at once, including surveys. It does not affect the WebFetch domain safety check, which sends only the hostname (not the URL or content) to api.anthropic.com to check a blocklist, or the official plugin marketplace auto-install; each has its own switch. Disabling telemetry also disables feature-flag evaluation, which can make features such as Remote Control unavailable.
All of these variables can be set in the env block of managed settings, so they apply to every machine.
| Service | Claude API default | Bedrock, Vertex, Foundry | Turn off |
|---|---|---|---|
| Usage metrics | On | Off | DISABLE_TELEMETRY=1 |
| Error reports | On for Pro/Max sign-ins (v2.1.198+) | Off | DISABLE_ERROR_REPORTING=1 |
| /feedback reports | On | Off (written to a local archive) | DISABLE_FEEDBACK_COMMAND=1 |
| Session quality surveys | On | On | CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY=1 |
| WebFetch domain safety check | On | On | skipWebFetchPreflight: true |
Quick reference
- If you disable the WebFetch check, restrict fetches with
WebFetch(domain:...)permission rules instead, or Claude can fetch any URL without the blocklist. - On a signed-in Claude apps gateway session, analytics, error reports, and survey ratings to Anthropic are disabled by the gateway credential itself.
- Your own OpenTelemetry export is separate from Anthropic's telemetry and goes only where you point it.
Remember this
Metrics exclude code and prompts; one variable disables non-essential traffic, but WebFetch's hostname check has its own setting.
Built-in protections and their documented limits
The client's protections, as the security page describes them:
- Permission modes. Auto mode (the starting mode in interactive terminal and VS Code sessions on recent versions) has a classifier review actions and block those it judges unsafe; your ask and deny rules still apply, and organisations can disable it. Manual mode starts read-only and asks before edits and commands, except a built-in set of read-only commands such as
ls,cat, andgit status. - Working directory boundary. In Manual mode, file tools ask before reading or writing outside the starting folder. The docs are explicit that this is a permission prompt, not a sandbox: a Bash command you approve can still write anywhere your user account can.
- Sandboxed Bash with filesystem and network isolation, configured with
/sandbox, is the operating-system-level control. - Command injection detection and fail-closed matching. Commands Claude Code cannot fully analyse prompt even if part of them matches an allow rule, and unmatched commands require approval.
- Network commands such as
curlandwgetare not auto-approved by default. - Trust verification. Interactive sessions show a workspace trust dialog in an untrusted folder, and project MCP servers have their own approval. A
claude -psession shows neither prompt, so repository hooks and MCP servers can run in a folder no one reviewed.
The docs close with a plain warning: these protections significantly reduce risk, but no system is completely immune, and the user remains responsible for reviewing proposed code and commands.
Quick reference
- Before scripting
claude -pover third-party repositories, review their.claude/and.mcp.json, or run with hooks disabled. - On Windows, the docs recommend against enabling WebDAV, which can let network requests bypass the permission system.
/permissionsaudits the rules in force; run it after policy changes.
Remember this
Permission prompts are a control, not a boundary; sandboxing and scoped credentials are what contain an approved command.
Prompt injection, MCP, and cloud sessions
Prompt injection is text in a file, web page, issue, or tool result that tries to redirect the agent. Claude Code's defences include the permission system, network-command approval, and WebFetch's design: for most fetches a separate model call reads the page and Claude receives that call's answer, not the raw page. Anthropic's recommendations for untrusted content are to review commands before approving them, avoid piping untrusted content straight into Claude, verify changes to critical files, use virtual machines for scripts and tool calls that touch external services, and report suspicious behaviour with /feedback.
MCP servers are a supply-chain question. Anthropic reviews connectors against listing criteria for its directory, but does not security-audit or manage any MCP server. Servers can come from .mcp.json, user and local scopes, claude.ai connectors, and plugins, so reviewing .mcp.json alone does not show everything a session can load. Organisations restrict servers with managed MCP configuration (allowManagedMcpServersOnly with allowedMcpServers).
Cloud sessions run in isolated Anthropic-managed VMs with limited network access by default. GitHub credentials stay encrypted on Anthropic's servers and never enter the VM; a proxy attaches them and rejects branch deletions and tag pushes. All operations are logged for audit, and VMs are reclaimed after inactivity.
Quick reference
- A deny rule such as
Bash(curl *)matches command text; for network control that does not depend on how a command is written, use sandbox network isolation. - Slack and other chat integrations read conversation context and may follow instructions in it; restrict them to trusted channels.
- Use
/security-reviewfor an on-demand security pass over the changes on your branch, alongside human review.
Remember this
Treat every external input as untrusted, allowlist MCP servers centrally, and isolate untrusted work in a VM or sandbox.
A rollout checklist for regulated teams
These are the decisions a security team usually makes before broad rollout. Most are managed-settings keys, which means they are enforced on the client and depend on the policy reaching each machine; verify delivery with claude doctor and a deliberately blocked action, as described in the enterprise setup guide.
Remember the documented boundary of client-side policy: a user with a modified client can bypass any client-side control, and some configurations (custom base URLs, provider variables) skip server-managed settings entirely. For controls that must hold against a determined user, combine managed settings with credentials scoped to what developers may touch, network egress rules, and MDM-protected settings files.
| Control | How | Why |
|---|---|---|
| Force organisation logins | forceLoginMethod / forceLoginOrgUUID in managed settings | Keeps sessions under commercial terms |
| Deny secret reads | permissions.deny Read rules, managed | Keeps credentials out of context and transcripts |
| Remove bypass mode | permissions.disableBypassPermissionsMode | No unreviewed actions |
| Restrict MCP | allowManagedMcpServersOnly + allowedMcpServers | Only vetted servers load |
| Sandbox Bash | sandbox settings, allowManagedDomainsOnly | OS-level file and network limits |
| Shorten local retention | cleanupPeriodDays in managed settings | Less plaintext on laptops |
| Audit usage | OpenTelemetry via managed env | Who ran what, when |
| Watch config changes | ConfigChange hooks | Detect local settings tampering |
| Decide on ZDR or HIPAA | Account team | Server-side retention; disables cloud features |
Quick reference
- Run a pilot with the full policy before rollout; strict rules such as
allowManagedPermissionRulesOnlygenerate prompts users will ask you to allow. - Report vulnerabilities in Claude Code through Anthropic's HackerOne programme, not public issues.
- Keep the Trust Center's SOC 2 Type 2 report and ISO 27001 certificate with your review evidence.
Remember this
Decide logins, secret denies, bypass, MCP, sandbox, retention, and auditing up front, then verify each reached real machines.
Hands-on: a one-hour security review
Work through this with one developer machine and your security team.
1. Confirm the account type with /status: commercial organisation login, not a personal Pro or Max account.
2. Search existing transcripts for secrets: grep -l "BEGIN RSA\|AWS_SECRET\|API_KEY" ~/.claude/projects/*/*.jsonl. Rotate anything found.
3. Write a draft managed policy with the checklist keys above and install it on a test machine.
4. Verify: .env cannot be read, --dangerously-skip-permissions is refused, an unlisted MCP server does not load, and curl example.com inside the sandbox is blocked unless the domain is allowed.
5. Set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 and confirm with your network monitoring which hosts the client still contacts.
6. Record which controls are client-side only and which have a server or OS-level backstop.
Pass criterion: every checklist control was tested with an action that should fail, and the review notes state the residual risks honestly.
Quick reference
- Expect
api.anthropic.com(or your provider/gateway) and the WebFetch check host in step 5 unless you disabled the latter. - If step 2 finds secrets, the policy change is preventive only; rotation is the fix for exposure that already happened.
- Repeat the verification after Claude Code upgrades; settings and defaults evolve.
Remember this
Test each control with a failing action and write down what is client-side only.
Key takeaway
Claude Code's data story depends on the account: commercial terms (Team, Enterprise, API, cloud providers) mean no training on your code or prompts by default and 30-day standard retention, with Zero Data Retention available to eligible Enterprise organisations; consumer accounts choose between five-year retention with training and 30 days without. /feedback transcripts are kept for five years. Locally, plaintext transcripts under ~/.claude/projects are the exposure most teams overlook.
On the machine, permission modes, fail-closed command matching, workspace trust, and sandboxed Bash reduce risk, but an approved command can write anywhere the user can, -p skips trust prompts, and MCP servers are not audited by Anthropic. Enforce logins, secret denies, MCP allowlists, sandboxing, retention, and auditing through managed settings, verify them on real machines, and back them with OS and network controls. See also Claude Code Sandboxing and Isolation and Claude Code Zero Data Retention.
Practice (60 min): run the six-step review above with your security team.
References
- Claude Code docs: Security — checked Oct 17, 2026
- Claude Code docs: Data usage — checked Oct 17, 2026
- Anthropic Trust Center — checked Oct 17, 2026
Shoaib Hossain
Lead Author & Systems ArchitectSoftware engineer and distributed systems architect specializing in backend scalability, cloud-native infrastructure, databases, and AI engineering workflows. Author and maintainer of Core Concept Learning.
Related Articles
Explore this topic