SSD Nodes Learn Hosting plans →
Guides Matt ConnorBy Matt Connor

Does Claude Train on Your Code?

Anthropic trains on consumer code with model improvement on. Flagged or feedback sessions may also be used. Check session terms and local storage.

Does Claude train on your code?

On a Free, Pro or Max account, Anthropic trains new Claude models on your code when the model-improvement privacy setting is on, and that includes Claude Code sessions run from those accounts. Turning the setting off does not close every route. Sessions flagged for safety review, material you explicitly send as feedback, and programs you join, such as the Trusted Tester Program, can still be used. 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 by default. Explicitly submitted feedback or bug reports can be used for training, as can data your organisation chooses to share, 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 sessions to your own disk by default, and Anthropic's retention policy does not govern that copy.

The policy details below come from Anthropic's Claude Code data-usage page, its linked docs and Anthropic's privacy center, checked on 2026-11-01. 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, Max, and Ultra accounts when this setting is on (including when you use Claude Code from these accounts)." That setting is the main control, but it is not the only way your sessions can end up in training.

Anthropic's privacy center article on how it uses personal data in model training covers these plans "when accounts from those plans use Claude Code". It lists four cases in which your chats or coding sessions may be used to improve its models:

  • "You choose to allow us to use your chats and coding sessions to improve Claude". This is the setting above.
  • "Your conversations are flagged for safety review". Flagged sessions may be used to improve how Anthropic detects and enforces breaches of its Usage Policy, "including training models for use by our Safeguards team". You do not choose this one.
  • "You've explicitly provided materials to us (e.g. via our thumbs up/down feedback button)".
  • "By otherwise explicitly opting in to training (e.g. by joining our Trusted Tester Program)".

So turning the setting off stops routine training on your sessions, but not every use. In Claude Code, the feedback commands are the case to watch. The data-usage page says: "If you choose to send us feedback about Claude Code using the /feedback command, we may use your feedback to improve our products and services." The /feedback section below covers what that sends.

To see or change the setting, open claude.ai/settings/data-privacy-controls while signed in. Anthropic's help article calls the control "Help Improve our AI models". 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, Max and Ultra subscribers. Switching the setting off works from then on. The help article says it keeps new chats and coding sessions out of future training runs, but data already in a training run that has started, or in a model already trained, is not removed.

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 by default

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." Anthropic's commercial training policy also allows chats and coding sessions to be used for training when you explicitly submit feedback or bug reports; this does not require an organisation-wide training opt-in.

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 in the CLI, Claude Code picks one in this order, with exceptions:

  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, except that a profile written by ant auth login ranks here only when named in ANTHROPIC_PROFILE; otherwise it ranks below /login
  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. A signed-in Claude apps gateway session overrides every source in this list, including cloud-provider credentials. Running /login also overrides CLAUDE_CODE_OAUTH_TOKEN for the current session; new sessions read the variable again. If you have an active subscription and also have ANTHROPIC_API_KEY set, Claude Code uses the API key once you approve it, unless a higher-priority source applies. In non-interactive -p mode, the key is used without approval, subject to that precedence. Claude Desktop and cloud sessions do not read these API key or bearer-token environment variables.

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 subscription /login session once approved, subject to the exceptions above. 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-11-01, Anthropic's data-usage page, API documentation and privacy center give these retention periods:

  • Consumer accounts that allow data use for model improvement: "5-year retention period".
  • Consumer accounts that do not allow it: "30-day retention period".
  • API conversation content (your prompts and Claude's outputs): not retained by default, except for Covered Models, which require 30-day retention. Feature-specific storage requirements, Usage Policy enforcement and legal requirements also apply, as described in the API retention documentation.
  • Saved Team and Enterprise chats and coding sessions: retained in the product until deleted, then removed from backend storage within 30 days, subject to legal and Usage Policy exceptions.
  • 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". Claude Code with API keys can also use a commercial API organisation's ZDR arrangement. Anthropic's Covered Models policy also requires at least 30 days of retention by default for designated models, including Fable 5 and Fable 5.1, across providers. ZDR for those Fable models requires express authorisation from Anthropic.

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. The dialog asks how much history to include: the current session only, which is the default, or also other sessions from the same project over the last 24 hours or 7 days. 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 those providers; signed-in Claude apps gateway sessions disable survey ratings to Anthropic and write shared survey transcripts to a local archive. 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: messages, tool calls and tool results. 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. When HIPAA configuration applies, the sweep removes entries older than cleanupPeriodDays.
  • Transcripts of sessions started or last continued in Claude Desktop or Cowork are kept at any age by default from Claude Code v2.1.248 onward. Set desktopSessionCleanupPeriodDays to give them an age limit. They expire after cleanupPeriodDays instead when managed settings specify that value or HIPAA configuration applies; earlier versions also use cleanupPeriodDays.
  • The sweep does not run in claude -p --bare sessions unless managed settings provide cleanupPeriodDays.
  • 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 unless managed settings provide the value, which means transcripts can be 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 to review the rules.

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 the five newest older copies of ~/.claude.json, plus a copy of any version Claude Code could not parse, 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?

Yes, when 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. With the setting off, Anthropic's privacy center still lists three routes: sessions flagged for safety review, material you explicitly provide as feedback, and other explicit opt-ins such as the Trusted Tester Program. These sessions may be used for training; flagged-session use includes training safeguards models. Check and change the setting at claude.ai/settings/data-privacy-controls. Also run /status to confirm that Claude Code really uses your subscription login, because an approved ANTHROPIC_API_KEY in your CLI environment outranks it unless a higher-priority source, such as a signed-in Claude apps gateway session, applies.

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

No, by default. Explicitly submitted feedback or bug reports can be used for training, as can data the customer chooses to provide for model improvement. 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-11-01, consumer accounts with model improvement on have a 5-year retention period, and accounts with it off have 30 days. API conversation content is not retained by default, except for Covered Models, which require 30-day retention. Feature-specific storage requirements, Usage Policy enforcement and legal requirements also apply. Saved Team and Enterprise chats and coding sessions remain until deleted, then leave backend storage within 30 days, subject to legal and Usage Policy exceptions. 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 unless HIPAA configuration applies, and claude purge removes the local data for one project.

Was this article useful?