Malicious AGENTS.md Files Hijack AI Coding Agents, Enabling Rogue npm Installs and Token Theft
What Happened – Researchers at Forever Security discovered a new attack vector that abuses the plain‑text AGENTS.md instruction file used by AI coding assistants such as OpenAI Codex and Anthropic Claude Code. By placing a malicious AGENTS.md in a user’s ~/Downloads folder, an attacker can cause the AI agent to automatically execute the instructions it contains. In a controlled proof‑of‑concept the team showed the agent installing a rogue npm package (named function‑color) and, in a separate test, redirecting Claude Code’s API traffic to a server under the attacker’s control, exposing the model’s OAuth token. The attack succeeds without any user interaction beyond the browser silently downloading the file; the AI agent must simply be launched from the same directory where the malicious file resides.
Why It Matters for Trust & Control Assurance – The technique highlights a gap in AI governance: without explicit policies and user awareness, AI agents will obey untrusted instruction files, breaking the boundary between intended project context and arbitrary filesystem locations.
Who Is Affected – Software developers and data‑science teams that run AI coding assistants locally; vendors of AI coding tools (OpenAI, Anthropic, Cursor CLI, etc.); enterprises that embed AI agents into internal development pipelines.
Recommended Actions –
- Restrict the working directory of AI coding agents to the specific project folder rather than a broad home or Downloads directory.
- Enforce a review process for any AGENTS.md, CLAUDE.md, or similar instruction files before the agent is allowed to load them.
- Enable browser download prompts or use extensions that require explicit user consent for files saved to ~/Downloads.
- Apply sandboxing or containerization for AI agent execution to limit filesystem access.
- Update security awareness training to cover AI‑agent workspace hygiene and the risks of auto‑loaded instruction files.
Source: BleepingComputer article
Technical Notes –
- Attack vector: Malicious AGENTS.md file placed silently in ~/Downloads by a web page; AI agent automatically reads the file when launched from that folder.
- Tools leveraged: npm package installation, OAuth token extraction via redirected API calls.
- Success rates: 90 % for a harmless calculator payload on Codex; ~50 % for token theft on Claude Code.
- Browser behavior: Chrome, Edge, and Firefox save downloads to ~/Downloads without prompting; Brave prompts the user.
- Mitigations from vendors: OpenAI and Anthropic recommend launching agents from the project root and keeping the working directory narrowly scoped.