Use an AI Coding Assistant Without Leaking Your Codebase

What leaves your machine when you use Copilot or Claude Code, and the settings that control training, restrict file access, and catch leaked secrets.

A coding assistant does not receive only the question you typed. It receives the file you are editing, the code around your cursor, the output of the commands it runs, and often a map of your repository. With a vendor that trains on what it receives, one “fix this bug” prompt can put your source code in someone else’s training set.

Both Copilot and Claude Code now have a switch for training, and Claude Code also has rules that restrict which files the agent may open. What is missing is a sane order of operations: training and transmission are two different problems, the defaults differ by plan, and the switches live in different places depending on which seat you sit in. This guide walks that order.

1. Know what actually crosses the wire

GitHub is unusually explicit. In a March 25, 2026 post, “Updates to GitHub Copilot interaction data usage policy”, GitHub Chief Product Officer Mario Rodriguez said the company would use Copilot interaction data to “train and improve our AI models” “From April 24 onward.” GitHub’s policy documentation names the scope: “inputs, outputs, code snippets, and associated context.”

Anthropic describes the mechanics for Claude Code in its data usage documentation: the tool “sends data over the network,” and “This data includes all user prompts and model outputs, encrypted in transit via TLS 1.2+.” The same page notes that Claude Code stores session transcripts locally in plaintext under ~/.claude/projects/ for 30 days by default.

Two things to hold on to. Training is a separate decision from transmission, so turning training off does not stop your code being sent for the length of the session. And how much code leaves depends on the tool rather than the prompt: an agent that opens files and runs commands sends what it reads, often more than you meant to share.

2. Turn off training where the switch is

For GitHub Copilot, the setting is called “Allow GitHub to use my data for AI model training,” and you turn it off by setting the dropdown to “Disabled” (profile picture, then Copilot settings). From April 24, 2026 it applies to “Copilot Free, Copilot Pro, Copilot Pro+, or Copilot Max” users, and anyone who already opted out keeps that choice: GitHub says “your choice is preserved” (GitHub’s announcement). Copilot Business and Copilot Enterprise are not in scope, since GitHub “does not use Copilot Business or Copilot Enterprise customer data to train AI models”.

Two more controls sit in the same Copilot settings: set “Suggestions matching public code” to “Block,” and on the Cloud agent page, scope repository access to “Only selected repositories” rather than “All repositories.”

For Claude, Anthropic gives consumer accounts the choice directly: “We give you the choice to allow your data to be used to improve future Claude models.” The toggle lives at claude.ai/settings/data-privacy-controls, and it also sets retention: 5 years for consumer sessions when the setting is on, 30 days when it is off. Commercial terms are the opposite default: under Team, Enterprise, and API terms, “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” (for example by joining the Developer Partner Program).

The honest catch: the free and personal tiers are where your code is most likely to become training data, so check which account you are signed into before assuming your policy applies.

3. Decide which files the tool may read

This is the half of the problem a training setting does not touch: the assistant opening a file it decided to open. Claude Code’s permissions documentation gives you a rule engine for that, with deny rules for sensitive paths and for commands you never want run:

{
  "permissions": {
    "allow": ["Bash(npm run *)"],
    "deny": ["Read(./.env)", "Read(./secrets/**)", "Bash(git push *)"]
  }
}

The rule ordering is the useful part: “Rules are evaluated in order: deny, then ask, then allow.” A broad deny beats a narrow allow, so a convenience rule cannot re-open a path. Path patterns use gitignore syntax, and a bare filename like Read(.env) matches at any depth under the current directory.

Two catches catch people out. The first is that a .claudeignore file has no effect at all, so those entries have to be moved into Read deny rules. The second is that a deny rule is not an operating system boundary: it covers the built-in file tools and the file commands Claude Code recognizes in Bash, but “They don’t apply to a command that reads files without naming them, such as grep -r pattern . run from the directory that holds the file,” nor to a script that opens a file itself.

For that last gap, use the sandbox. It is off by default and opt-in:

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true
  }
}

failIfUnavailable matters: the default is to run unsandboxed when the sandbox cannot start, and Linux and WSL2 need bubblewrap and socat installed. Support covers macOS, Linux, and WSL2; on native Windows, Claude Code runs commands unsandboxed, so use WSL2 there. Inside the sandbox, filesystem.denyRead and filesystem.allowRead decide path access, where the narrower rule wins, and sandbox.credentials entries in “deny” or “mask” mode block or hide credential files and environment variables.

4. Scan for secrets before you start

The strongest control is the boring one: do not point the assistant at a repository holding live credentials. Gitleaks is an MIT-licensed scanner that finds “secrets like passwords, API keys, and tokens,” and its README notes that “gitleaks uses the git log -p command to scan patches,” so it covers history, not just the working tree.

gitleaks git -v path_to_repo
gitleaks dir -v path_to_directory

Findings carry a rule ID and a fingerprint, and the fingerprint is what you add to .gitleaksignore once you confirm a false positive. If a real secret turns up in history, rotate it rather than trying to scrub the commit.

5. When the code cannot leave at all

Some codebases may not be transmitted at all, and then the model has to run on your own hardware: a local runner such as Ollama or LM Studio with a local coding model, driven through an editor extension or a CLI agent. Our guide to running a local model covers the setup. The catch is that a local model changes where inference happens, not what the agent does. It still opens files, runs commands, and can paste a secret into a prompt, so apply the same deny rules and secret scan.

Quick checklist

  • Confirm which plan you are on. Training defaults differ between free, individual, and commercial seats.
  • Copilot: set “Allow GitHub to use my data for AI model training” to “Disabled,” set “Suggestions matching public code” to “Block,” and scope cloud agent repository access.
  • Claude consumer: check the privacy controls at claude.ai/settings/data-privacy-controls. Commercial: confirm nobody opted your organization into model improvement.
  • Add Read deny rules for .env, key files, and secret directories. .claudeignore does nothing.
  • Enable the sandbox, set failIfUnavailable to true, and use WSL2 rather than native Windows.
  • Run Gitleaks over the working tree and the history, and rotate anything real that was ever committed.
  • If the repository may not be transmitted, run the model locally and keep the tool pointed at it.