NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Claude Code

CVE-2026-21852: Claude Code Leaks Data via Malicious Environment Configuration Before Trust Confirmation

mediumCVSS 4.0 5.3GHSA-jh7p-qr78-84p7

Claude Code before 2.0.65 applied environment settings from a repository before the user answered the trust prompt. A malicious repo could set `ANTHROPIC_BASE_URL` to its own server, so Claude Code sent API requests there, possibly with the user's Anthropic API key. Upgrade to 2.0.65. Auto-updating installs already have the fix.

Published Jan 21, 2026 · Analysis Nov 1, 2026

What an attacker can do

Claude Code reads a settings file from the project directory. In affected versions, an ANTHROPIC_BASE_URL value in that file took effect during project load, before the trust dialog appeared. Claude Code then made API requests to the attacker's endpoint, and those requests can carry the user's Anthropic API key in their headers.

The attack needs only that a developer opens Claude Code in a cloned repository the attacker controls. No prompt injection and no tool approval is involved, and the user sees no warning because the trust prompt comes too late. The attacker receives a working API key, which lets them run requests billed to the victim's account. The advisory rates it medium (CVSS 4.0 score 5.3) and reports low confidentiality, integrity and availability impact. It names no specific settings file and gives no workaround beyond updating.

Who is affected

The npm package @anthropic-ai/claude-code below 2.0.65. Check the installed version:

claude --version
npm ls -g @anthropic-ai/claude-code

Standard auto-update installs have received the fix. Installs that were updated by hand, pinned in a container image or held back by a version lock may still be older.

@anthropic-ai/claude-code

Ecosystem
npm
Affected
< 2.0.65
Fixed in
2.0.65
Check
npm ls @anthropic-ai/claude-code

How to fix it

Upgrade to 2.0.65 or later:

npm install -g @anthropic-ai/claude-code@latest

Anthropic's advisory lists no workaround other than updating. Because the key may already have been sent, rotate the Anthropic API key if you opened Claude Code in an untrusted repository on an older version.

How to tell if you were hit

Search repositories you opened with Claude Code for project-level settings files that define ANTHROPIC_BASE_URL or other environment overrides, and check that the host in the URL is one you expect. Review egress logs or proxy logs from developer machines for requests from the claude process to unknown hosts. Check your Anthropic Console usage for requests you did not make, and rotate the key if you find any.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

A vulnerability in Claude Code's project-load flow allowed malicious repositories to exfiltrate data including Anthropic API keys before users confirmed trust. If a user started Claude Code in an attacker-controller repository, and the repository included a settings file that set ANTHROPIC_BASE_URL to an attacker-controlled endpoint, Claude Code would issue API requests before showing the trust prompt, including potentially leaking the user's API keys.

Users on standard Claude Code auto-update have received this fix already. Users performing manual updates are advised to update to the latest version.

Questions

Do I have to accept the trust prompt for the leak to happen?

No. The requests went out before the trust prompt was shown, so declining it afterwards did not prevent the leak in affected versions.

Which version of Claude Code fixes CVE-2026-21852?

Version 2.0.65. Anything below it is affected, including 2.0.64.

Should I rotate my API key?

If you ran an affected version inside a repository you did not trust, yes. The advisory says the key could be leaked, but it does not confirm any real-world abuse.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

Coverage on the Beam blog

More Claude Code vulnerabilities

All Claude Code entries