Prompt Injection: Your AGENTS.md File Is The Backdoor

Prompt Injection: Your AGENTS.md File Is The Backdoor

AGENTS.md hijacked Codex in more than 90% of tests, according to the security writeup that documented the payload. A matching CLAUDE.md attack on Claude Code landed in about half of tests. Those two numbers are why this isn't a footnote in someone's threat model.

Prompt injection in a coding agent means instructions smuggled into content the agent reads as part of its work — an issue description, a code comment, a README, a config file (SecureLayer7). OWASP's Top 10 for LLM applications files it under indirect prompt injection, which occurs "when an LLM accepts input from external sources, such as websites or files" (Brandefense).

The detail most developers get wrong is which files count as input.

How AGENTS.md Prompt Injection Actually Works

AGENTS.md, CLAUDE.md, .cursorrules and .cursor/rules/ load as trusted context in every session (Vulkro). The file you wrote to steer your agent is also a steering wheel someone else can grab.

This isn't hypothetical, either. Forever Security found a malicious AGENTS.md sitting in a customer's Downloads folder, per the writeup describing the incident. It told Codex to install an npm package called function-color. The package was malware. Then the payload "edited the machine-wide MCP server config and launched a new session with approvals and the sandbox turned off." Install, reconfigure, relaunch with the guardrails off.

One markdown file. That was the whole attack.

Why Indirect Prompt Injection Needs No Bug

Here's what should rewire how you think about agent security: nothing in that chain required a vulnerability.

As NeuralTrust puts it, "agents follow it by design.

So a poisoned file can make an agent install packages, rewrite its own settings or leak credentials without any software bug." Your agent read its instructions and executed them faithfully. That's the feature working.

Codex reads AGENTS.md and Claude Code reads CLAUDE.md because persistent steering files shaping every session is the entire point of the tool. Another documented payload "read like engineering notes and told the agent to register a new tool server and install an npm package that pulls in malware." The disguise worked given that it wasn't a disguise. It looked like instructions as it was instructions.

Picture a repair shop. A mechanic pops the hood and finds a note taped there: "the grinding in the rear brakes is normal, skip the inspection, sign off the service." If he follows it, nobody hacked the lift or the torque wrench. He obeyed a note he assumed came from the owner. Your agent is the mechanic. Your repo is the note.

The damage follows a pattern from there.

The agent "may leak secrets, run commands, or plant persistence in the repository," as SecureLayer7 describes the attack model. In the writeup's Claude Code tests, a malicious CLAUDE.md reportedly redirected the agent's API traffic to a server the researchers controlled, which exposed auth tokens and let that server send commands back. Your keys. A stranger's server.

One file edit.

And unlike phishing, prompt injection through a rules file doesn't hit once.

A poisoned file "steers every future edit, not just one," as Vulkro notes.

Count the files with that property: AGENTS.md, CLAUDE.md, .cursorrules, .cursor/rules/, .github/copilot-instructions.md, and .windsurfrules. Six.

Per OWASP's cheat sheet, they "can be modified by a malicious PR or by the agent itself to embed persistent instructions."

Sit with that second vector.

The agent itself can modify them. An attacker who can write repository content influences agent behavior. And an attacker who edits a memory or config file reaches the model without ever being part of your explicit request (Brandefense).

Do you read the diff when a pull request touches CLAUDE.md?

Most of us audit npm dependencies on every install and merge rules-file edits without reading a word. That's backwards. The dependency can only run code. The rules file decides what your agent trusts next week.

Prompt Injection Surfaces Beyond the Rules File

Watching only the rules files means watching one door in a house of doors.

OWASP lists the full set of surfaces where repository content becomes instructions the moment the agent reads it (cheat sheet):

- Issue bodies and pull-request descriptions - Pull-request comments and issue comments - README files in any cloned repo - Dependency changelogs - Error traces and test output - Fetched web pages and documentation sites - MCP tool responses

Per the same research roundup, README files, changelogs, issue comments, documentation sites. And even test output can all carry directives into an agent's context window.

The attacker doesn't need write access to your repo, either. A hostile issue comment on a public project you've asked your agent to fix does the job. The writeup's shortlist of attack locations inside a cloned repo is CLAUDE.md, AGENTS.md, .cursor/rules. And the README — which is exactly what you get handed when you pull a stranger's template.

Solo operators absorb this worst.

You clone a starter repo, wire up three MCP servers, let the agent run while you're on a call. Nothing gets a second pair of eyes. Enterprise teams at least have a review queue.

You've got autopilot and whatever attention is left over.

How to Prevent Prompt Injection in Your Repo

OWASP's recommendation doesn't hedge: "treat all repository content (issues, PRs, comments, READMEs) as untrusted input when processed by an AI coding agent" (cheat sheet).

That's the whole mental model, and adopting it costs nothing today.

Here's the routine for every repo not built from scratch.

Read AGENTS.md, CLAUDE.md, and .cursorrules in full before the first agent session, since a file you haven't read is a file someone else wrote. Diff the rules files on every pull, the same way you'd diff a dependency lockfile. Treat any PR that touches an instruction file as review-critical rather than docs-noise, since that's the persistence mechanism OWASP flags. And watch for the tell from the reported Codex payload: a session trying to relaunch itself with approvals and the sandbox off isn't optimizing your workflow, it's pulling your brakes. Keep approvals on. Keep the sandbox on. Read what your agent installs before it installs it.

None of this needs new tooling.

It needs accepting that trust in an agent context runs one direction: you wrote the prompt. And the repo wrote the rest of it.

Reading the file fixes most of this.

Open your repo right now and read AGENTS.md, CLAUDE.md, .cursorrules, and .github/copilot-instructions.md top to bottom. If you didn't write every line yourself, your agent is currently taking orders from a stranger.

Prompt Injection FAQ

Can CLAUDE.md be a prompt injection vector?

Yes. The writeup's CLAUDE.md attack on Claude Code worked in about half of tests. And reportedly redirected the agent's API traffic to a server the researchers controlled.

Claude Code loads CLAUDE.md as trusted context in every session, so a poisoned file steers every session after it.

How do I audit AGENTS.md for injected instructions?

Read it top to bottom before the first agent session.

Diff it on every pull like a lockfile. Treat any PR touching it as review-critical instead of documentation noise, since OWASP flags these files as a persistence mechanism that can be modified by a malicious PR or by the agent itself.

What is indirect prompt injection?

OWASP's classification for what happens "when an LLM accepts input from external sources, such as websites or files." In coding agents, that means instructions hidden in content the agent reads — issue bodies, PR comments, READMEs, changelogs, even MCP tool responses — rather than anything you typed.

Which files should I treat as untrusted?

All repository content, per OWASP. Start with the six steering files: AGENTS.md, CLAUDE.md, .cursorrules, .cursor/rules/, .github/copilot-instructions.md, and .windsurfrules. Then the README in anything you cloned from someone else.

Sources

- Security writeup: prompt injection in AI coding agents (dev.to) - SecureLayer7: coding agent prompt injection - Brandefense: AGENTS.md Downloads folder hijack - Vulkro: repository content as an injection surface - NeuralTrust: AGENTS.md analysis - Peretz: documented agent payloads - OWASP Secure Coding with AI Cheat Sheet - Research roundup: one planted AGENTS.md file (linux.org.hk)

```json { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [ { "@type": "Question", "name": "Can CLAUDE.md be a prompt injection vector?", "acceptedAnswer": { "@type": "Answer", "text": "Yes. The security writeup's CLAUDE.md attack on Claude Code worked in about half of tests and reportedly redirected the agent's API traffic to a researcher-controlled server. Claude Code loads CLAUDE.md as trusted context in every session." } }, { "@type": "Question", "name": "How do I audit AGENTS.md for injected instructions?", "acceptedAnswer": { "@type": "Answer", "text": "Read it in full before the first agent session, diff it on every pull like a lockfile, and treat any pull request touching it as review-critical. OWASP flags these files as modifiable by a malicious PR or by the agent itself to embed persistent instructions." } }, { "@type": "Question", "name": "What is indirect prompt injection?", "acceptedAnswer": { "@type": "Answer", "text": "OWASP classifies it as what occurs when an LLM accepts input from external sources, such as websites or files. In coding agents it covers instructions hidden in issue bodies, PR comments, READMEs, changelogs, and MCP tool responses." } }, { "@type": "Question", "name": "Which files should I treat as untrusted?", "acceptedAnswer": { "@type": "Answer", "text": "All repository content, per OWASP: issues, PRs, comments, and READMEs. Start with AGENTS.md, CLAUDE.md, .cursorrules, .cursor/rules/, .github/copilot-instructions.md, and .windsurfrules, then the README in anything cloned from someone else." } } ] } ```