# Claude Code could send Anthropic API keys to a malicious repo's endpoint before the trust prompt

Source: https://botpassword.com/incidents/2026-01-claude-code-anthropic-base-url-key-leak
Disclosed: 2026-01-20 · Type: AI agent · Status: Resolved · Updated: 2026-10-25

Anthropic disclosed that Claude Code before version 2.0.65 read a repository's settings file and made API requests before showing its folder trust prompt. A malicious repository could set `ANTHROPIC_BASE_URL` to an attacker-controlled server, so simply opening it could send the user's Anthropic API key there. Update Claude Code, and rotate your Anthropic key if you opened untrusted repositories with an older version.

Identifiers: CVE-2026-21852, GHSA-jh7p-qr78-84p7

## What was exposed

The credential Claude Code sends with its API requests: an Anthropic API key, or other request data, according to the advisory. Claude Code lets a project's settings set environment variables, and `ANTHROPIC_BASE_URL` controls where API traffic goes. Before the fix, Claude Code loaded that configuration and issued requests as soon as it started in the folder, ahead of the dialog that asks whether you trust the repository. An attacker who persuaded you to clone and open a repository (a pull request to review, a sample project, a dependency you wanted to inspect) could therefore receive your key at their endpoint without any further action from you. A stolen Anthropic key can be used to run paid API calls on your account until it is revoked. The advisory does not report exploitation in the wild.

## Who is affected

You are affected if you ran Claude Code below 2.0.65 inside a repository you did not create, especially one cloned from an unfamiliar source. Users on the standard auto-update channel already have the fix, per Anthropic. Check your version with `claude --version`. To look for signs of a planted setting, search cloned repositories for a `.claude/settings.json` (or similar project settings) that sets `ANTHROPIC_BASE_URL` to a host other than Anthropic's.

## What to do

1. Update Claude Code to 2.0.65 or later (auto-update handles this for most users).
2. If you opened untrusted repositories with an older version, revoke and recreate your Anthropic API key in the Claude Console and review usage for calls you did not make.
3. Before opening a cloned repository with an agent, inspect its project settings for environment overrides such as `ANTHROPIC_BASE_URL`.
4. Use a separate, spend-limited key for agent work so a leak has a bounded cost.

## Keys to rotate

- [Anthropic](https://botpassword.com/keys/anthropic)

## Timeline

- 2026-01-20: Anthropic publishes GHSA-jh7p-qr78-84p7 (medium), titled as a data leak via malicious environment configuration before trust confirmation; fixed in 2.0.65. ([source](https://github.com/anthropics/claude-code/security/advisories/GHSA-jh7p-qr78-84p7))
- 2026-01-21: NVD publishes CVE-2026-21852 for the same issue. ([source](https://nvd.nist.gov/vuln/detail/CVE-2026-21852))

## Indicators

- A project settings file in a cloned repository that sets `ANTHROPIC_BASE_URL` to a non-Anthropic host.
- Claude Code versions below 2.0.65.

## Sources

- https://github.com/anthropics/claude-code/security/advisories/GHSA-jh7p-qr78-84p7
- https://nvd.nist.gov/vuln/detail/CVE-2026-21852
