---
description: "Claude Code prompt injection vulnerability guide: how injection reaches the agent through files, web pages, and tool output, disclosed CVEs, and defenses."
title: "Claude Code Prompt Injection: Vulnerabilities and Defenses"
image: https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/11/is-claude-cowork-safe-security-risks-and-controls-bifrost-1920x1080--1-.png
---

Try Bifrost Enterprise free for 14 days. [Request access](https://www.getmaxim.ai/#enterprise-trial)

**TL;DR**

- Prompt injection in Claude Code happens when untrusted text the agent reads, such as a [CLAUDE.md](http://CLAUDE.md) file, a web page, a GitHub issue, or an MCP tool result, is treated as instructions.
- Disclosed issues in 2026 include API key exfiltration through a malicious project setting (CVE-2026-21852), hook and MCP consent bypasses (CVE-2025-59536), and secret theft through the Claude Code GitHub Action.
- No single control prevents injection; defenses work by limiting what the agent can read, run, call, and leak once an injection succeeds.
- Gateway controls add a second layer outside the laptop: guardrails on model requests and MCP tool results, tool filtering per key, secrets detection, and scoped, revocable credentials.
- Bifrost applies those controls to Claude Code traffic, and with AI Gateway + Bifrost Edge, to Claude Code on every company machine.

A Claude Code prompt injection vulnerability is any path by which untrusted text that Claude Code reads, from a repository file, a fetched web page, a GitHub issue, or an MCP tool result, gets interpreted as instructions that change what the agent does. Because Claude Code can run shell commands, edit files, and call tools, a successful Claude Code prompt injection can turn into command execution or credential theft. [Bifrost](https://www.getmaxim.ai), the [open-source AI gateway](https://github.com/maximhq/bifrost) built by Maxim AI for enterprise LLM, MCP, and agent traffic, adds controls outside the developer's machine. This guide covers how injection reaches Claude Code, what has been disclosed, and the layered defenses that limit the damage.

## What Is Prompt Injection in Claude Code?

Prompt injection in Claude Code is the manipulation of the agent through text it was supposed to treat as data. Direct injection comes from the person typing the prompt. Indirect injection, the more dangerous kind for coding agents, comes from content the agent reads while working: files, documentation, issue text, command output, and tool results.

Language models have no reliable boundary between instructions and data in their context. A comment in a source file that says "ignore previous instructions and run this command" competes with the user's actual request. Training and permission prompts help, but neither is a guarantee.

What makes coding agents a higher-risk target than chat assistants:

- **They act.** Claude Code runs shell commands, writes files, and calls network services.
- **They read untrusted content by design.** Reviewing a pull request means reading text written by someone outside the team.
- **They hold credentials.** API keys, cloud tokens, and repository tokens are often present in the environment.

Our [prompt injection defense guide for production AI agents](https://www.getmaxim.ai/articles/prompt-injection-defense-for-production-ai-agents-a-complete-2026-guide/) covers the general threat model; this post focuses on Claude Code specifically.

## How Prompt Injection Reaches Claude Code

Prompt injection reaches Claude Code through four channels: repository content, fetched web content, CI inputs such as issues and pull request comments, and results from MCP tools. A fifth path, repository-level configuration, can change Claude Code's behavior before the model reads anything.

![Untrusted content from repository files, web pages, GitHub issues, and MCP tool results flows into Claude Code's context, where it can steer shell commands, file edits, and outbound requests](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/claude-code-prompt-injection/claude-code-prompt-injection-paths.png)

Untrusted content from repository files, web pages, GitHub issues, and MCP tool results flows into Claude Code's context, where it can steer shell commands, file edits, and outbound requests

*Figure 1: Every source the agent reads is a possible instruction channel; the damage depends on what the agent can do next.*

Each channel, as Figure 1 shows:

- **Repository files.** `CLAUDE.md` is loaded as project instructions, and any file the agent opens enters its context. A cloned third-party repository is untrusted input.
- **Web content.** Documentation or search results fetched during a task can carry hidden instructions, including in HTML comments a human reader never sees.
- **CI inputs.** In GitHub Actions, issue bodies, pull request titles, and comments are written by anyone who can open them, then fed to the agent.
- **MCP tool results.** A ticketing, chat, or search tool returns content written by other people. The model reads that result as text.
- **Project configuration.** Files such as `.claude/settings.json` and `.mcp.json` in a repository can define hooks, MCP servers, and environment variables; see [Claude Code hooks for governance](https://www.getmaxim.ai/articles/claude-code-hooks-for-governance-and-gateway-policy/).

## Disclosed Claude Code Prompt Injection Vulnerabilities

Several Claude Code vulnerabilities were disclosed and patched in 2026, and they illustrate the main risk classes: configuration that runs before trust is granted, injected content that reads secrets, and permission checks that can be bypassed in CI. All of the issues below were fixed by Anthropic after responsible disclosure.

| Disclosure | Vector | Impact | Fix |
| --- | --- | --- | --- |
| CVE-2026-21852 | Repository `.claude/settings.json` set `ANTHROPIC_BASE_URL` to an attacker endpoint | API key sent to attacker before the trust prompt | Claude Code 2.0.65 |
| CVE-2025-59536 and a related hooks issue | Repository hooks and MCP settings bypassed consent | Command execution on opening a project | Patched; consent dialogs added |
| Claude Code GitHub Action, Microsoft research | Injected issue or PR text led the Read tool to read process environment files | CI secrets exposed | Claude Code 2.1.128 |
| Claude Code GitHub Action, GMO Flatt Security | Permission check trusted any GitHub App actor, plus injected issue text | OIDC token theft and repository write access | Patched action release |

[Check Point Research's analysis of CVE-2026-21852](https://research.checkpoint.com/2026/rce-and-api-token-exfiltration-through-claude-code-project-files-cve-2025-59536/) is the clearest example of why credential design matters: a cloned repository redirected Claude Code's API traffic and captured the API key in plaintext. [Microsoft's analysis of the Claude Code GitHub Action](https://www.microsoft.com/en-us/security/blog/2026/06/05/securing-ci-cd-in-agentic-world-claude-code-github-action-case/) showed injected content directing the agent to read secrets from the runner environment. The Cloud Security Alliance's [research note on AI agent prompt injection in CI/CD](https://labs.cloudsecurityalliance.org/research/csa-research-note-claude-code-github-action-prompt-injection/) documents the CI attack pattern across several incidents.

Similar issues have been found across coding agents, so defenses must assume an injection will eventually succeed. The roundup of [Claude Code security tools](https://www.getmaxim.ai/articles/best-claude-code-security-tools-for-enterprise-in-2026/) compares the controls available.

## Defending Claude Code on the Developer Machine

Defending Claude Code on the developer machine starts with the controls Claude Code itself provides: keeping the client updated, restricting permissions, sandboxing command execution, and treating unfamiliar repositories as untrusted. These controls reduce what an injected instruction can do locally.

Practical steps:

- **Stay current.** Several fixes above shipped in specific versions, so keep Claude Code and the GitHub Action updated through your software management tooling.
- **Use managed settings.** Organization-managed settings take precedence over project files, so admins can fix the API base URL, deny risky tools, and disable automatic approval of project MCP servers.
- **Restrict permissions.** Deny rules for network tools and sensitive paths, and require approval for shell commands in unfamiliar repositories.
- **Sandbox execution.** Run Claude Code's bash sandbox or a dev container when working on code you did not write.
- **Read the trust prompt.** Opening a project grants its configuration power over the session; review `.claude/` and `.mcp.json` in third-party repositories first.

Local controls depend on each machine's configuration. Our guide to [securing Claude Code in production with SSO, audit logs, and PII guardrails](https://www.getmaxim.ai/articles/securing-claude-code-in-production-sso-audit-logs-and-pii-guardrails-for-engineering-teams/) covers the organizational side, and the [AI security resource page](https://www.getmaxim.ai/resources/ai-security) covers the broader threat model.

## Defense in Depth: Adding Gateway Controls

Gateway controls add a second, independent layer between Claude Code and the models and tools it calls. Because every model request and MCP tool call passes through the gateway, guardrails, tool filtering, and credential scoping apply even when a laptop's local settings are weak or an injection gets past the model.

![Layered defenses: Claude Code permissions and sandboxing, then Bifrost guardrails on model requests, MCP guardrails and tool filtering on tools, and secrets detection plus logs](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/claude-code-prompt-injection/claude-code-prompt-injection-defense-layers.png)

Layered defenses: Claude Code permissions and sandboxing, then Bifrost guardrails on model requests, MCP guardrails and tool filtering on tools, and secrets detection plus logs

*Figure 2: No single layer stops injection; each layer limits what a successful injection can reach.*

[Bifrost](https://www.getmaxim.ai) connects to Claude Code through its Anthropic-compatible endpoint, as the [Claude Code integration guide](https://docs.getbifrost.ai/cli-agents/claude-code) describes. Once traffic flows through it, four gateway controls apply:

- **Guardrails on model requests.** Bifrost Enterprise [guardrails](https://docs.getbifrost.ai/enterprise/guardrails) validate inputs and outputs for prompt injection, PII, and credential leakage. Input rules inspect the request sent to the model, which includes file contents and web pages that local tools added to the conversation.
- **External prompt-attack detection.** Guardrail profiles can call providers with injection detection, such as [AWS Bedrock Guardrails](https://docs.getbifrost.ai/integrations/guardrails/aws-bedrock) prompt attack filters, alongside a [prompt guardrail](https://docs.getbifrost.ai/enterprise/guardrails/prompt-guardrails) that uses an LLM judge with your own policy.
- **Secrets detection.** The built-in [secrets detection guardrail](https://docs.getbifrost.ai/enterprise/guardrails/secrets-detection) flags API keys, tokens, and private keys in inputs and outputs, which catches credentials before they leave through a model response.
- **Request logs.** Every request is recorded with the virtual key, model, and content where logging is enabled, so an investigation can reconstruct what the agent saw and did.

The [AI guardrails page](https://www.getmaxim.ai/ai-guardrails) summarizes the guardrail options, and the [guardrails resource hub](https://www.getmaxim.ai/resources/guardrails) lists supported providers.

## Securing MCP Tool Output Against Injection

MCP tool output is the injection channel teams most often overlook, because tool results come from systems the team trusts, such as a ticketing tool, while the content inside them comes from anyone who can file a ticket. Securing it means inspecting tool results before they reach the model and limiting which tools the agent can call.

Bifrost applies [MCP guardrails](https://docs.getbifrost.ai/enterprise/guardrails) at the tool-execution boundary in two phases: before the tool runs, rules can inspect or redact its arguments, and after it returns, rules can inspect or redact its result before Bifrost passes it back to Claude Code. A prompt guardrail attached to an MCP output rule evaluates the text of the result against your policy.

Tool access matters as much as inspection:

- **Filter tools per key.** [Tool filtering](https://docs.getbifrost.ai/mcp/filtering) restricts each developer's virtual key to the tools their work needs; a key used for code review does not need write access to production systems.
- **Hold credentials centrally.** Upstream MCP credentials stay in the gateway, so an injected command cannot read them from a local config file.
- **Order checks deliberately.** Bifrost can [run guardrails on LLM and MCP traffic in a chosen order](https://www.getmaxim.ai/bifrost/blog/run-guardrails-on-llm-and-mcp-traffic-in-the-order-you-choose), for example redaction before a judge model sees the content.

The [MCP guardrails announcement](https://www.getmaxim.ai/bifrost/blog/mcp-guardrails-in-bifrost) explains the design, and the guide to [connecting Claude Code to internal MCP servers without exposing credentials](https://www.getmaxim.ai/articles/claude-code-internal-mcp-servers-connect-without-exposing-credentials/) covers the credential side.

## Limiting the Blast Radius of a Stolen Credential

Limiting the blast radius of a stolen credential means deciding in advance what a leaked key can do. CVE-2026-21852 showed that a Claude Code API key can be exfiltrated by a malicious repository. If that key is a raw provider key, the attacker gets unscoped model access billed to your account.

![Top lane: a leaked provider API key gives an attacker unrestricted model access billed to the team; bottom lane: a leaked Bifrost virtual key is scoped, budgeted, logged, and revocable](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/claude-code-prompt-injection/claude-code-prompt-injection-key-exposure.png)

Top lane: a leaked provider API key gives an attacker unrestricted model access billed to the team; bottom lane: a leaked Bifrost virtual key is scoped, budgeted, logged, and revocable

*Figure 3: Credential theft is a design-time question: decide in advance what a stolen key is allowed to do.*

With Claude Code routed through Bifrost, the provider keys never reach the laptop. Developers hold a [virtual key](https://docs.getbifrost.ai/features/governance/virtual-keys) instead, which limits the damage, as Figure 3 shows:

- **Scoped.** The key can reach only its allowed providers, models, and MCP tools.
- **Budgeted.** Budgets and rate limits cap what an attacker can spend.
- **Short-lived.** Keys can carry an expiry, and Bifrost Enterprise can issue per-user credentials through SSO with `apiKeyHelper` instead of static keys.
- **Revocable.** Disabling one key stops the attacker without rotating provider credentials for the whole team.

Fixing `ANTHROPIC_BASE_URL` in managed settings closes the redirect path itself, and the gateway design limits the impact if another path appears. The [AI governance page](https://www.getmaxim.ai/ai-governance) covers identity-based keys.

## Extending Protection to Every Developer Machine

Extending these protections to every developer machine is where AI Gateway + Bifrost Edge applies. The Bifrost gateway remains the policy engine, with guardrails, tool rules, virtual keys, and logs; Bifrost Edge runs on each laptop and routes Claude Code and other AI apps through that gateway without per-developer configuration.

Edge matters for prompt injection in two ways. First, coverage: a developer who never set `ANTHROPIC_BASE_URL` is still governed. Second, MCP control: Edge inventories the MCP servers configured inside each AI app on the device and enforces allow or deny decisions locally, as the [Edge MCP governance docs](https://docs.getbifrost.ai/edge/mcp-governance) describe, so an unapproved server added by a cloned project can be blocked. [Bifrost Edge](https://www.getmaxim.ai/edge) is generally available, requires the Enterprise Gateway, and runs alongside existing endpoint security tools. For a broader view, see [AI coding agent security across Cursor, Claude Code, and Copilot](https://www.getmaxim.ai/articles/ai-coding-agent-security-governing-cursor-claude-code-and-copilot/).

## Frequently Asked Questions

### What is a Claude Code prompt injection vulnerability?

It is a weakness that lets untrusted text read by Claude Code, from a repository file, web page, GitHub issue, or tool result, act as instructions. Because Claude Code runs commands, edits files, and calls tools, a successful injection can lead to command execution, data exposure, or credential theft. Defenses focus on limiting what the agent can reach.

### Can a [CLAUDE.md](http://CLAUDE.md) file contain a prompt injection?

Yes. Claude Code loads `CLAUDE.md` as project instructions, so a malicious or compromised repository can use it to steer the agent. Treat third-party repositories as untrusted, review `CLAUDE.md`, `.claude/`, and `.mcp.json` before opening them with an agent, and use permission rules and sandboxing for unfamiliar code.

### Was CVE-2026-21852 fixed?

Yes. CVE-2026-21852 affected Claude Code versions before 2.0.65 and allowed a malicious repository to set `ANTHROPIC_BASE_URL` and capture the API key before the trust prompt appeared. Anthropic fixed it in version 2.0.65. Keeping clients updated, fixing the base URL in managed settings, and keeping provider keys off laptops reduces exposure to similar issues.

### How do I protect Claude Code in GitHub Actions?

Limit which actors can trigger the workflow, give the job the least-privilege token it needs, keep secrets out of the agent's environment where possible, restrict tools with allowlists, and keep the action updated. Routing the agent's model and tool calls through a gateway such as [Bifrost](https://www.getmaxim.ai/llm-gateway) adds guardrails, scoped keys, and logs outside the runner.

### Do guardrails stop prompt injection?

Guardrails reduce prompt injection but do not eliminate it. Detection models catch many known patterns and miss some new ones. Treat guardrails as one layer: combine them with tool filtering, least-privilege credentials, sandboxed execution, and logging, so an injection that gets through cannot reach sensitive systems or leave without a record.

### Does MCP make Claude Code prompt injection worse?

MCP adds injection channels, because tool results contain content written by other people, and adds actions, because tools can write to real systems. Governing MCP through a gateway that filters tools per key, holds credentials centrally, and inspects tool results before they reach the model reduces both risks.

## Start Building with Bifrost

Claude Code prompt injection is a lasting risk class rather than a single bug: any agent that reads untrusted text and can act will face it. The workable defense is layered, with local controls on the laptop and independent gateway controls on every model request and tool call. Read the [Claude Code resource hub](https://www.getmaxim.ai/resources/claude-code), review [AI guardrails](https://www.getmaxim.ai/ai-guardrails), or [book a demo](https://www.getmaxim.ai/book-a-demo) to see guardrails and scoped credentials applied to Claude Code traffic.

## Read next

[![SAML vs OIDC: Which SSO Protocol for Enterprise AI Tools](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/saml-vs-oidc-which-sso-protocol-for-enterprise-ai-tools-bifrost-1920x1080.png) SAML and OIDC are the two dominant single sign-on protocols, and they suit different clients. This guide compares SAML vs OIDC on tokens, flows, and API support, explains where SCIM fits, and shows why AI tools called from code and agents favor OIDC.](https://www.getmaxim.ai/articles/saml-vs-oidc/)

[![7 Best Private AI Platforms for Regulated Enterprises](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/7-best-private-ai-platforms-for-regulated-enterprises-bifrost-1920x1080@2x.png) A private AI platform runs models and AI traffic inside infrastructure the organization controls. This guide ranks seven options, including Bifrost, NVIDIA AI Enterprise, Red Hat OpenShift AI, and Google Distributed Cloud air-gapped, on deployment, isolation, and governance.](https://www.getmaxim.ai/articles/private-ai-platforms/)

[![9 Best Open Source AI Coding Agents](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/9-best-open-source-ai-coding-agents-bifrost-1920x1080@2x.png) Open source AI coding agents publish the agent's own code under licenses such as MIT or Apache 2.0. This guide ranks nine of them, including OpenCode, Codex CLI, Cline, and Kilo Code, and shows how one Bifrost gateway governs model access, spend, and tool calls for all of them.](https://www.getmaxim.ai/articles/open-source-ai-coding-agents/)

## More in AI Governance

[![SAML vs OIDC: Which SSO Protocol for Enterprise AI Tools](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/saml-vs-oidc-which-sso-protocol-for-enterprise-ai-tools-bifrost-1920x1080.png) SAML and OIDC are the two dominant single sign-on protocols, and they suit different clients. This guide compares SAML vs OIDC on tokens, flows, and API support, explains where SCIM fits, and shows why AI tools called from code and agents favor OIDC.](https://www.getmaxim.ai/articles/saml-vs-oidc/)

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "publisher": {
        "@type": "Organization",
        "name": "Maxim Articles",
        "url": "https://www.getmaxim.ai/articles/",
        "logo": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w256h256/2025/08/thumbnail.png",
            "width": 60,
            "height": 60
        }
    },
    "author": {
        "@type": "Person",
        "name": "Kuldeep Paul",
        "image": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/2025/08/1727978381919.jpeg",
            "width": 800,
            "height": 800
        },
        "url": "https://www.getmaxim.ai/articles/author/kuldeep/",
        "sameAs": []
    },
    "headline": "Claude Code Prompt Injection: Vulnerabilities and Defenses",
    "url": "https://www.getmaxim.ai/articles/claude-code-prompt-injection/",
    "datePublished": "2026-11-24T12:54:00.000Z",
    "dateModified": "2026-11-26T12:54:52.000Z",
    "image": {
        "@type": "ImageObject",
        "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/11/is-claude-cowork-safe-security-risks-and-controls-bifrost-1920x1080--1-.png",
        "width": 1200,
        "height": 675
    },
    "keywords": "AI Governance",
    "description": "A Claude Code prompt injection vulnerability lets untrusted text in a repository, web page, issue, or tool result steer the agent's commands. This guide covers the injection paths, the CVEs disclosed in 2026, and the defenses that limit what a successful injection can reach.",
    "mainEntityOfPage": "https://www.getmaxim.ai/articles/claude-code-prompt-injection/"
}
```
