Cybersecurity

Claude Code and the email in the User-Agent: hardening it against data leaks

Team Nippysoft
• • 15 min read
Claude Code and the email in the User-Agent: hardening it against data leaks

Between September and November 2026, several Claude Code users reported the same thing: the agent had sent their account email to third-party websites, written into the User-Agent header of a curl call. Nobody had asked it to. The model had the address at hand, and some sites ask automated clients for a contact. The case reached the front page of Hacker News, and Anthropic has been closing it step by step across several November releases.

This post covers what happened and what is still open, then maps the ways Claude Code can send information out and eight measures to close them, each with the official configuration and with what it leaves uncovered.

An instruction in the prompt asks the model for something; a rule outside the model decides it. Private data needs the second kind.

What happened with the email in the User-Agent header

Claude Code works with a context: everything the model reads in a session, from the system instructions and CLAUDE.md to the open files and the output of every command. From it the model picks tools, such as Bash to run commands or WebFetch to read a page, and whatever sits there it can copy into a command.

For signed-in users, the context included the account email, on purpose. Claude used to invent names for fields such as @author tags because it did not know who the user was. A member of the Claude Code team explained it on Hacker News: "So we added the account email in the model's context for signed-in users".

The User-Agent header is the text a program uses to introduce itself to a web server; curl -A sets that text. Some sites ask for a contact there: EDGAR, the SEC filing system, gives a company name and an email address as its example, and the Wikimedia policy warns that a script without contact details may be blocked. Claude complied with the only email it had. The same team member put it this way: "Some sites ask agents for a contact, and Claude would sometimes provide the email address in its context".

In everyday terms, it is like an assistant signing the visitor log of an office on behalf of a manager: the form asks for a contact email, and the assistant writes down the manager's personal one, because that is the one in the notebook.

The HTTP standard treats the From and User-Agent headers differently. For the From header, which carries an email address, RFC 9110 says that a user agent "SHOULD NOT send a From header field without explicit configuration by the user"; a robot should send it, but with the contact of whoever runs it, and a person configures that. For User-Agent it asks for no needless detail, because such detail increases "the risk of a user being identified against their wishes".

Why the instruction was not enough

Since version 2.1.234, from August, the prompt had told the model to use the email only to identify the user and not to send it to unrelated services. The reports kept coming: there was one on GitHub as early as September, issue #95258. In #104774, subagents made 9 requests to sec.gov with the email in curl -A, and #107757, with 118 comments, took the case to the Hacker News front page with 1616 points.

An instruction shifts what the model tends to do, not what it can do. With the address in the context and a network tool, one page asking for a contact is enough for the email to reach a server the user never chose.

A comment on #107757 adds that the model sometimes built the HTTP client name from the project at hand, so the header tied identity to topic. That is the account of one user who went through their transcripts; Anthropic did not confirm it.

What Anthropic changed and what is still open

According to the changelog, the fix arrived in three steps:

  • 2.1.317, November 2. A check that asks before a web or shell tool sends the account email to the network. It ships as a mod built into Claude Code, cc-plugin-privacy, on by default and turned off in /plugin.
  • 2.1.321, November 9. The check refuses, without asking, a shell command that holds the email and names a User-Agent.
  • 2.1.325, November 13. It also refuses the email as a client identity in scripts a command runs, in file writes, in WebFetch and in MCP tool calls.

Its README says the mod looks for the address in any case or encoded as %XX, next to a word that declares who is calling, such as User-Agent, curl -A or From. Anthropic also announced that the email would leave the context in the next release; up to 2.1.325, the changelog does not record it.

The reports show where the fix ends. On 2.1.319, a user tested against their own machine: Claude asked for permission and, once approved, the curl -A with the email ran (comment). There are false positives, such as a local mail script blocked on 2.1.325 (#110184). On Hacker News, before that release, Anthropic admitted the mod did not cover every case, "like when Claude writes a script and runs on its own".

Version 2.1.325 extended the check to exactly those scripts and writes. As of November 16, no leak report on that version has surfaced, nor has any statement that the case is closed.

Where information can leave Claude Code

The email was one case. What else can leave the machine, and through which door? The table sums up the exits the official documentation describes:

ExitWhat goes out
The Anthropic APIThe whole context: prompts, files read, CLAUDE.md and command output.
WebFetchWhatever URL Claude picks, query string included. Before each fetch, the hostname (not the full URL) also goes to Anthropic for a safety check.
Bash and PowerShellWhatever any command sends: curl, git push, npm publish or a script.
MCP serversWhatever Claude passes them as input.
HTTP hooksThe JSON of each event, sent as a POST to a URL.
Telemetry and error reportsMetrics without code, prompts or file paths; reports redact known patterns of secrets, paths and email addresses.
/feedback, /bug and /shareA copy of the conversation, code included.
Local transcriptsNothing on their own, but they sit in plain text under ~/.claude/projects/ for 30 days by default, and a backup or a git add can upload them.

No setting closes the first row: whatever enters the context travels to the API. The other rows have a lock, and the measures below are about those locks. The data usage page has the details of each exit.

Eight measures against leaks

Update and confirm the check is on

The check has existed since 2.1.317 and has covered scripts, writes, WebFetch and MCP since 2.1.325. On November 16 the stable channel was still on 2.1.311, so anyone on it does not have the mod. To confirm, run claude --version and check in /plugin that cc-plugin-privacy shows as enabled.

Permission rules that deny before asking

Permission rules are lists in settings.json that say which tools Claude uses without asking, which ones prompt and which ones never run. They are evaluated in order, deny first, then ask, then allow, and the first match wins. It works like the front desk of a building: if a name is on the banned list, it does not matter that it is also on the guest list.

This example from the settings reference denies reading .env and other secret files, and denies curl through Bash:

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(./config/credentials.json)",
      "Bash(curl *)"
    ]
  }
}

The curl rule matches the command as Claude writes it, so Bash(curl *) does not stop /usr/bin/curl or sh -c 'curl …'. The permissions guide suggests denying curl and wget and opening the web only through WebFetch per domain, with rules such as WebFetch(domain:github.com). A Read rule also stops the file commands Claude Code recognizes in Bash, such as cat or head, but not a grep -r over the folder or a Python or Node script that opens the file itself. That takes the sandbox, two measures below. On Windows, //c/**/.env matches any .env on that drive.

A hook that knows the private data

A PreToolUse hook is a custom script that Claude Code runs before each tool: it gets a JSON on stdin with the tool and its input, and it can deny the call. Unlike CLAUDE.md, it decides outside the model. The hooks guide explains the mechanism, and the hook against Co-Authored-By is another example of the same pattern.

The idea: a list of private strings (the email, the full name, the user folder) in ~/.claude/private-patterns.txt, outside the project and the context. The hook looks for them in the whole tool input, ignoring case and also after decoding %XX, and denies the call on a match. It is registered in settings with "matcher": "*", which according to the hooks reference fires it for every tool:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "node ~/.claude/hooks/block-private-data.mjs" }
        ]
      }
    ]
  }
}

The registration follows the shape of the official examples, but it was not tested inside Claude Code; what was tested is the script, with fake events on stdin. Adding Read(~/.claude/private-patterns.txt) to deny means Claude cannot open it with Read, cat or head; a script started from Bash still can. With the sandbox on, the same path under sandbox.credentials.files with "mode": "deny" closes it to commands too, and the hook still reads it because hooks run outside the sandbox. The script, block-private-data.mjs, needs nothing but Node:

#!/usr/bin/env node
// PreToolUse hook: denies a tool call whose input holds one of your private strings,
// and denies any call it cannot check (patterns file missing or unreadable, or an event that is not JSON).
// The strings live in a file outside the project, one per line; lines under 4 characters or starting with # are skipped.
import { readFileSync, writeSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";

const patternsFile = process.env.PRIVATE_PATTERNS_FILE ?? join(homedir(), ".claude", "private-patterns.txt");

function deny(reason) {
  // Synchronous write: process.exit right after an async stdout write can drop it, and the call would go through.
  writeSync(
    1,
    JSON.stringify({
      hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: reason },
    }),
  );
  process.exit(0);
}

let patterns = [];
try {
  patterns = readFileSync(patternsFile, "utf8")
    .split(/\r?\n/)
    .map((l) => l.trim().normalize("NFC").toLowerCase())
    .filter((l) => l.length >= 4 && !l.startsWith("#"));
} catch {
  deny("private-patterns.txt is missing or unreadable, so this call cannot be checked. Fix the file, then retry.");
}

let event;
try {
  event = JSON.parse(readFileSync(0, "utf8"));
} catch {
  deny("The hook got an event that is not JSON, so this call cannot be checked.");
}

// Collect every key, string and number of the tool input, one per line.
const parts = [];
(function walk(v) {
  if (typeof v === "string" || typeof v === "number") parts.push(String(v));
  else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) { parts.push(k); walk(x); }
})(event.tool_input ?? {});
const text = parts.join("\n").normalize("NFC").toLowerCase();

// Decode each run of %XX escapes on its own, so one malformed escape does not hide the rest.
const decoded = text.replace(/(%[0-9a-f]{2})+/g, (run) => {
  try { return decodeURIComponent(run).normalize("NFC").toLowerCase(); } catch { return run; }
});

const hit = patterns.find((p) => text.includes(p) || decoded.includes(p));
if (!hit) process.exit(0); // no match: no decision

deny("This call holds private data listed in private-patterns.txt. Do not send it; use a generic value or ask the user.");

It walks the keys and values of the input instead of searching the serialized JSON, because serializing a Windows path doubles its backslashes and the string no longer matches. It also decodes each run of %XX on its own: if the whole text is decoded in one call, a stray % anywhere else in the input throws and leaves the encoded email unchecked. Here are some results with fake events and a made-up address:

Bash curl -A with the address
  -> exit 0, deny
WebFetch, address percent-encoded in the URL
  -> exit 0, deny
MCP tool with the address in a header field
  -> exit 0, deny
Percent-encoded address plus a stray % elsewhere
  -> exit 0, deny
Windows path with backslashes as the private string
  -> exit 0, deny
Address split in two variables
  -> exit 0, no decision
Address in base64
  -> exit 0, no decision
Bash runs a script whose file holds the address (input does not)
  -> exit 0, no decision
Read of a file that holds the address (only the path is in the input)
  -> exit 0, no decision
Patterns file missing
  -> exit 0, deny

The hook denies the direct forms: the email as is, in capitals, encoded in the URL, inside a file being written or in an MCP tool field. It does not see the email split across two variables or two fields, in base64, encoded twice, written as an HTML entity, or already sitting in a script that runs with python fetch.py. It does not stop a Read either, because the input carries only the path and the content still enters the context. A private string shorter than 4 characters is never searched for. If the patterns file is missing or the event is not JSON, it denies the call with the reason, so a misnamed file cannot switch it off without warning. The cost: with "matcher": "*", a missing file blocks every tool until it is fixed, including the ones that could fix it, so the fix happens outside Claude Code. If the script fails or does not start, the call goes ahead, unless the registration carries "onFailure": "block", which, per the hooks reference, has been available since 2.1.295. It also gives false positives, such as denying a local file write that holds the address.

A sandbox so commands cannot go anywhere

The sandbox uses the operating system to isolate Bash commands: it decides which files they read and which domains they reach. They have no direct route out; connections go through a local proxy that checks each host against a list of allowed domains, which starts empty. According to the sandbox page, it runs on macOS, Linux and WSL2; on native Windows, Claude Code runs commands unsandboxed, and the option there is WSL2.

This official example keeps commands from reading the AWS credentials and the ~/.ssh folder, and strips GITHUB_TOKEN and NPM_TOKEN from their environment:

{
  "sandbox": {
    "enabled": true,
    "credentials": {
      "files": [
        { "path": "~/.aws/credentials", "mode": "deny" },
        { "path": "~/.ssh", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GITHUB_TOKEN", "mode": "deny" },
        { "name": "NPM_TOKEN", "mode": "deny" }
      ]
    }
  }
}

Domains are allowed through sandbox.network.allowedDomains, for example ["github.com", "*.npmjs.org"]. A command that fails inside the sandbox can ask to run outside it, and "allowUnsandboxedCommands": false shuts that door. The documentation shows it for a single session:

claude --settings '{"sandbox": {"enabled": true, "allowUnsandboxedCommands": false}}'

If the sandbox cannot start, commands run without it. With "failIfUnavailable": true, Claude Code refuses to start in that case, and on native Windows it never starts. The sandbox is only for commands. Read, Edit, Write, WebFetch and WebSearch follow the permission rules, and local MCP servers and hooks run outside the sandbox, which is why the measures go together.

Telemetry and the commands that upload the conversation

Several environment variables turn off exits that are not needed, and they can be set in settings.json under env:

  • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns off telemetry, error reporting, /feedback and auto-updates; with it, updating is manual.
  • DISABLE_TELEMETRY=1 and DISABLE_ERROR_REPORTING=1 turn each one off separately. With 0 or false they stay off too; turning them back on means removing the variable.
  • DISABLE_FEEDBACK_COMMAND=1 disables /feedback, /bug and /share.
  • CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 strips credentials from the environment of the processes Claude Code starts, such as commands, hooks and stdio MCP servers. It leaves GitHub tokens and proxy settings in place.
  • IS_DEMO=1 hides the email and the organization in the header and in /status, for recording or streaming. The documentation does not say it removes the email from the model's context.

Separately, cleanupPeriodDays shortens how many days local transcripts are kept.

Third-party MCP servers, plugins and HTTP hooks

An MCP server receives whatever Claude passes it, and a malicious one already installed can carry it off: the rules only decide what it is given. One that fetches outside content opens the door to prompt injection. The security page recommends writing one's own servers or using those from trusted providers. Three settings narrow the rest: deniedMcpServers blocks servers, "mcp__*" in deny denies every MCP tool, and enableAllProjectMcpServers is best left off, because it approves the whole .mcp.json of a repo without asking. For HTTP hooks, allowedHttpHookUrls limits which URLs they can post to and httpHookAllowedEnvVars which variables can go in their headers. Before installing a plugin, the plugin security guide helps decide whether to trust it. Command hooks, whether one's own or those that come with a plugin or a repo's .claude/settings.json, run with the user's full permissions: their code is worth reading before installing them or accepting a folder's trust. With claude -p there is no trust dialog, and the repo's hooks run anyway.

Keep data out of the context

CLAUDE.md and auto memory load at the start of every conversation, so secrets, connection strings and personal email addresses do not belong there. For .env, the Read(./.env) rule and the sandbox credentials entry work together. The working rule: if the model does not need a piece of data for the task, it should not see it; if it does need it, it should have no way to send it out.

Check what already went out

Transcripts sit in plain text under ~/.claude/projects/. A grep for one's own email across those .jsonl files shows whether it ever appeared in a command. For what goes out from now on, Claude Code honors HTTPS_PROXY and HTTP_PROXY and accepts a custom CA, so a local inspecting proxy shows each of its requests. A Bash command goes through that proxy only if the program it runs honors those variables; the sandbox can set those variables for the commands it isolates. With --debug, Claude Code logs each hook: command, result and duration.

Before adding a tool, an MCP server or a plugin, the useful question is what data from the context it could carry away, and where to.

What these measures do not cover

  • Prompt injection. A page or a file can ask the model to send data. The measures narrow the exits; they do not make the model immune.
  • bypassPermissions mode. Permission prompts do not appear, and if the unsandboxed retry is still enabled, a command that fails in the sandbox runs again outside it without asking.

The lesson for anyone building agents

Personal data in the context plus network tools add up to a possible leak. The instruction in the prompt was not enough; the answer was a deterministic check outside the model and the promise to take the data out of the context, in line with what RFC 9110 asks for: not sending the user's identity unless the user configures it. The person who announced the mod on Hacker News summed it up in one line: "we now disallow this programmatically".

Checked on November 16, 2026 against Claude Code 2.1.325 and the official documentation as of that date.

References

Subscribe

Get the latest posts delivered right to your inbox.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comments

No comments yet. Be the first to share your thoughts!

Subscribed!

Registered! A confirmation link has been sent to your email address. If you don't see it, please check your spam folder.

Error

An error occurred. Please try again.

Full code