SSD Nodes Learn Hosting plans →
Guides Matt ConnorBy Matt Connor

Does Claude Train on Your Code?

Anthropic trains on your code if a consumer account has model improvement on, or your company opted in. See which terms a session uses and what stays on disk.

Does Claude train on your code?

On a Free, Pro or Max account, Anthropic uses your code to train new Claude models only while the model-improvement privacy setting is on, and that includes Claude Code sessions run from those accounts. Under commercial terms (Team plans, Enterprise plans, the API and third-party platforms), Anthropic does not train generative models on the code or prompts you send to Claude Code, unless your organisation chose to share data, for example through the Development Partner Program.

That answer has two catches. The first is that the terms depend on the credential Claude Code is actually using in a session, which is not always the plan you think you are on. The second is local: Claude Code writes a plaintext copy of every session to your own disk, and Anthropic's retention policy does not govern that copy.

The policy details below come from Anthropic's Claude Code data-usage page and its linked docs, checked on 2026-10-10. Policies change, so read the page itself before you rely on a detail for a contract.

Consumer accounts: the model-improvement setting decides

Free, Pro and Max are consumer accounts. For these, the data-usage page says: "We will train new models using data from Free, Pro, and Max accounts when this setting is on (including when you use Claude Code from these accounts)." Training depends on that one setting, and the choice is yours.

To see or change it, open claude.ai/settings/data-privacy-controls while signed in. Anthropic's help article calls the control "Model Improvement". Labels on settings pages move, so confirm the wording on the page itself. Claude Code also has a /privacy-settings command, which the command reference lists as available only to Pro and Max subscribers.

The same setting also changes how long Anthropic keeps your data. That is covered in the retention section below, and the difference is bigger than most people expect.

Commercial accounts: no training unless your organisation opts in

Team, Enterprise, the API and third-party platforms run under commercial terms. The data-usage page says: "Anthropic does not train generative models using code or prompts sent to Claude Code under commercial terms, unless the customer has chosen to provide their data to us for model improvement."

The named way to opt in is the Development Partner Program. Four facts about it matter:

  • It is opt-in. An organisation admin must expressly turn it on. On prepaid billing that happens in the Console privacy settings. On invoice billing it goes through your account executive.
  • It shares only Claude Code input and output tokens from the first-party Claude API.
  • It is available only on the Anthropic first-party API. Users of Amazon Bedrock and Google Cloud's Agent Platform (the name the doc now uses for Vertex) cannot join it.
  • Accounts under a ZDR (zero data retention) agreement are not eligible.

If your question is about client contracts, DPAs (data processing agreements) and where data is stored, that is a separate topic. It is covered in which Claude plan to use for client data.

Which terms is your Claude Code session actually under?

The plan on your invoice does not decide this. The credential Claude Code uses for the session does. Many developers have a Pro or Max login and an ANTHROPIC_API_KEY in their shell at the same time, and those two credentials belong to different accounts with different terms.

When several credentials are present, Claude Code picks one in this fixed order:

  1. Cloud provider variables
  2. ANTHROPIC_AUTH_TOKEN
  3. ANTHROPIC_API_KEY
  4. apiKeyHelper
  5. CLAUDE_CODE_OAUTH_TOKEN
  6. Anthropic profile or federation credentials
  7. Subscription OAuth (open authorization) credentials from /login

The authentication docs say the last item is the default for Pro, Max, Team and Enterprise users. Everything above it wins over your login. If you have an active subscription and also have ANTHROPIC_API_KEY set, Claude Code uses the API key once you approve it. In non-interactive -p mode, the key is always used when present.

So a Max user with an API key exported in ~/.bashrc can end up on the API, which the data-usage page lists under commercial terms, and never notice. The reverse also happens. A developer who believes they run on a company API key can be signed in with a personal Pro account, which means consumer terms and the consumer training setting. How Claude Code chooses between a subscription login and an API key covers the billing side of the same mechanism.

Check from the shell first. This prints the names of the matching variables and never their values:

env | grep -E '^(ANTHROPIC_|CLAUDE_CODE_)' | cut -d= -f1

No output means no Anthropic credential variable is set in this shell. A line such as ANTHROPIC_API_KEY means that key outranks your /login session. Some CLAUDE_CODE_ variables are ordinary options, so compare what you see with the list above. Then find where a key is set:

grep -n 'ANTHROPIC_' ~/.bashrc ~/.profile ~/.zshrc 2>/dev/null

Next, confirm inside Claude Code with /status. It opens the Settings screen on the Status tab, which shows the account and connectivity for the session. When a login and an API key are both configured, the docs say /status marks the credential that is not in use. Read the answer there instead of guessing. To fall back to your subscription, remove the key from the shell and start Claude Code again:

unset ANTHROPIC_API_KEY

Then run /status once more. Also delete the matching export line from your shell profile, or the key returns in the next login shell.

How long does Anthropic keep your Claude Code data?

As of 2026-10-10, the data-usage page gives these retention periods, quoted as written:

  • Consumer accounts that allow data use for model improvement: "5-year retention period".
  • Consumer accounts that do not allow it: "30-day retention period".
  • Commercial users (Team, Enterprise, and API): "Standard: 30-day retention period".
  • Transcripts shared via /feedback, or via /bug and /share, which report through the same path: "retained for 5 years".
  • Transcripts shared through the session quality survey: "retained for up to 6 months".

Two details are easy to miss. First, turning the model-improvement setting on moves consumer retention from 30 days to five years, so that setting decides more than training. Second, the page does not state a retention period for Bedrock, Agent Platform or Foundry. Check your cloud provider's terms instead of assuming 30 days.

ZDR exists, but it is narrow. The page says it is "available to qualified accounts for Claude Code on Claude for Enterprise" and that "ZDR is not included in the standard Enterprise plan".

What /feedback and the session survey send

/feedback sends Anthropic a copy of the conversation history, code included, and that copy is kept for five years. On an account with 30-day retention, this is how a single conversation ends up stored for five years. Before you run it in a client repository, think about what the session has read. Setting DISABLE_FEEDBACK_COMMAND=1 opts out of the command.

The session quality survey works differently. The rating alone stores no transcript. If you answer Yes to the follow-up question "Can Anthropic look at your session transcript to help us improve Claude Code?", the transcript is kept for up to six months. Anthropic says these shared survey transcripts "do not impact your data training preferences and cannot be used to train our AI models." Set CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY=1 to turn the survey off.

On Bedrock, Agent Platform and Foundry, or with no Anthropic credentials, /feedback uploads nothing. It writes an archive under ~/.claude/feedback-bundles/, and nothing leaves the machine until you forward that file. A Yes to the survey on those providers also writes a local archive instead of uploading. Telemetry and error reporting are off by default on those providers, and so is bug reporting. The survey and the WebFetch domain safety check still run on every provider. Running Claude Code through Bedrock or Vertex covers that setup.

The local copy: plaintext transcripts in ~/.claude/projects

Everything above is about Anthropic's servers. Claude Code also keeps its own record on the machine where it runs. The data-usage page says Claude Code clients "store session transcripts locally in plaintext under ~/.claude/projects/ for 30 days by default to enable session resumption."

Each transcript holds the full conversation: "every message, tool call, and tool result". The docs say plainly what follows from that: "If a tool reads a .env file or a command prints a credential, that value is written to projects/<project>/<session>.jsonl." Transcripts are not encrypted at rest, and "OS file permissions are the only protection."

This matters most in two situations. On a shared VPS (virtual private server), anyone with root or sudo on the box can read your home directory, whatever its mode. When the code belongs to a client, the transcript is a second copy of their code, and of every secret the session touched, sitting on your disk for a month.

You can see this for yourself. This lists transcripts that contain a private key header:

grep -rl 'PRIVATE KEY' ~/.claude/projects 2>/dev/null

No output is the healthy result. Each path it prints is a transcript that holds key material, because a file read or a command output in that session put it there.

The 30-day sweep, set by cleanupPeriodDays, also removes subagent transcripts, large tool outputs, file-history snapshots, plan files, debug logs and the paste cache. Some files follow other rules:

  • ~/.claude/history.jsonl holds every prompt you have typed, with timestamp and project path. In a normal setup the sweep does not touch it, and it stays until you delete it.
  • Transcripts of sessions started or last continued in Claude Desktop or Cowork are kept at any age unless you set desktopSessionCleanupPeriodDays, which needs Claude Code v2.1.248 or later.
  • The sweep does not run at all in claude -p --bare sessions.
  • Auto memory files under projects/<project>/memory/ are not deleted by the sweep.

Lock down Claude Code transcripts on a VPS

Start with file permissions. Check the mode of the directory:

stat -c '%a %U %n' ~/.claude ~/.claude/projects

A healthy line starts with 700 followed by your own user name. If the last digit is not 0, other accounts on the server have some access to that directory. Remove group and other access from everything inside it, then look for anything still readable by other users:

chmod -R go-rwx ~/.claude
find ~/.claude -perm /o=r

No output from find is the healthy result. File modes do not stop root. On a box where other people hold sudo, the safer pattern is one Unix account per client, or a separate VPS per client. Running Claude Code safely on a VPS covers the user and sandbox setup.

Next, shorten local retention and block the common secret files. Add this to ~/.claude/settings.json, and merge it with any keys already in the file:

{
  "cleanupPeriodDays": 7,
  "permissions": {
    "deny": [
      "Read(.env)",
      "Read(.env.*)",
      "Read(secrets/**)"
    ]
  }
}

cleanupPeriodDays takes a whole number of days. The minimum is 1, and 0 fails with a validation error, so you cannot use it to switch transcripts off. Get the value right, because a settings error on cleanupPeriodDays pauses the sweep, which means transcripts are kept longer instead of shorter. Claude Code shows a warning in /status until you fix it. A bare file name such as .env in a Read rule matches at any depth under the current directory, because the rules use gitignore pattern syntax. Run /permissions in a new session, and the dialog lists each rule with the settings file it came from.

Deny rules have a limit. They apply to Claude's file tools, to file commands Claude Code recognises in Bash such as cat and head, and to redirection targets. They do not apply to a script that opens files itself, or to a command like grep -r pattern . that reads files without naming them. For enforcement at the OS level, the docs point to the sandbox.

A short retention period has a cost: a swept session no longer appears in the /resume picker. How Claude Code resume and session history work explains what you lose and how to keep it.

Two stronger options exist. The CLAUDE_CODE_SKIP_PROMPT_HISTORY environment variable skips writing transcripts and prompt history in any mode. For scripted runs, pass --no-session-persistence together with -p. Both mean there is nothing to resume later.

Remove a client's local data when the job ends

claude purge deletes the state Claude Code holds for one project. That covers transcripts and auto memory under projects/, per-session task, debug and file-history entries, the matching prompt lines in history.jsonl, and the project's entry in ~/.claude.json. Preview it first:

claude purge ~/work/client-repo --dry-run

The output is a deletion plan that lists each item and why it is included. Run the same command without --dry-run and it shows the plan again, then asks for confirmation before it deletes anything. Before v2.1.288, the command was claude project purge.

The purge leaves shell-snapshots/ and backups/ alone, because they are not tied to one project. backups/ holds up to five older copies of ~/.claude.json, which can still contain the project entry. Images and scratchpad files live under the temp directory, so the purge does not remove them either. Delete those by hand if the client expects a clean machine.

FAQ

Does Claude train on my code if I use Claude Code with a Pro or Max plan?

Only while the model-improvement setting on your account is on. Anthropic's data-usage page says it trains new models on data from Free, Pro and Max accounts when that setting is on, and this includes Claude Code use. Check and change it at claude.ai/settings/data-privacy-controls. Also run /status to confirm that Claude Code really uses your subscription login, because an ANTHROPIC_API_KEY in your environment outranks it.

Does Anthropic train on code sent through the API, Team or Enterprise?

No, unless the customer chose to provide data for model improvement. Under commercial terms, Anthropic does not train generative models on code or prompts sent to Claude Code. The named opt-in is the Development Partner Program, which an organisation admin must turn on. It covers only the first-party Claude API, so Bedrock and Google Cloud's Agent Platform users cannot join it.

How long does Anthropic keep Claude Code conversations?

As of 2026-10-10, consumer accounts with model improvement on have a 5-year retention period, and accounts with it off have 30 days. Team, Enterprise and API accounts have a standard 30-day period. Transcripts sent with /feedback, /bug or /share are kept for 5 years. Transcripts shared through the session survey are kept for up to 6 months.

Where does Claude Code store my conversations on my own machine?

In plaintext JSONL (JSON Lines) files under ~/.claude/projects/, one file per session, deleted after 30 days by default. Change the period with cleanupPeriodDays in ~/.claude/settings.json. The minimum is 1. Your typed prompts in ~/.claude/history.jsonl stay until you delete them, and claude purge removes the local data for one project.