Researchers Uncover How AI Coding Agents Can Be Hijacked via Malicious Instructions in Downloads Folders
Security researchers have uncovered a subtle yet dangerous attack vector targeting AI coding agents, demonstrating how a malicious instruction file secretly dropped into a user’s Downloads folder can trick autonomous software into executing unauthorized code, installing rogue packages, and leaking sensitive credentials.
The discovery, made by researchers at Forever Security, highlights the unintended security risks that emerge when powerful AI agents are granted broad access to local file systems. By exploiting the core functionality of modern AI tools, the attack vector bypasses traditional software vulnerabilities entirely, operating instead through the intended design of the software.
According to the findings, the researchers discovered a malicious markdown instruction file named "AGENTS.md" sitting inside a customer’s local Downloads folder. This file, which had been crafted to blend in with standard project structures, successfully tricked an AI coding agent into attempting to install a malicious Node Package Manager (npm) package known as function-color.
Following the initial discovery in the wild, the research team reproduced the attack vector in controlled testing environments against OpenAI Codex. Furthermore, they demonstrated a related and sophisticated technique targeting Claude Code, showing how malicious instructions could be leveraged to leak OAuth tokens and completely hijack the underlying user account without requiring direct exploitation of the core LLM architecture.
Markdown files such as AGENTS.md and CLAUDE.md are plain-text documents that serve a very specific, legitimate purpose in modern software development. They are routinely used by developers to provide project-specific context and instructions to AI coding agents. These files typically dictate which testing frameworks to use, outline coding conventions, specify preferred libraries, and define the specific tools the agent should employ while assisting with a codebase.
Because these files are text-based and non-executable, they have historically not been viewed by security scanners as traditional payloads or malware. However, the latest research demonstrates that when an AI agent reads these documents, it treats the text as authoritative operational guidance. Consequently, malicious instructions embedded within the markdown can cause AI agents to run terminal commands, modify configurations, or install external software packages using the full permissions and system tools available to them.
Agents Following Malicious Instructions
Forever Security, a specialized security firm that monitors and analyzes the risks introduced by autonomous AI software and coding agents, first identified the tactic during an investigation into anomalous behavior on a customer’s machine. The coding agent in question was observed attempting to install the unauthorized function-color npm package.
When researchers traced the origin of this command, they discovered that the instruction had been pulled directly from an AGENTS.md file residing in the customer’s home Downloads directory, which had also been designated as the working directory for the AI session.
AI coding agents are inherently designed to scan their current working directory upon startup, automatically loading applicable context files to guide their operational workflow. While these configuration files are safe when created by trusted developers within dedicated project repositories, the Forever Security team realized that the mechanics of the system introduce severe risks when agents are launched in unvetted locations.
Emphasizing the architectural nature of the issue, the researchers noted that there is nothing for major artificial intelligence providers like OpenAI or Anthropic to patch in terms of a traditional software bug. An agent that strictly follows instructions found inside an AGENTS.md file located within its active folder is performing precisely the function it was built to execute.
The researchers’ empirical tests confirmed that an external attacker could successfully manipulate widely used development tools such as OpenAI Codex and Claude Code into executing arbitrary code or harvesting sensitive credentials simply by ensuring an instruction file was present in the agent’s working path.
While the researchers were unable to definitively determine how the specific malicious instruction file landed on the victim’s device in the initial customer incident, they explained that the mechanics of modern web browsing create a uniquely vulnerable environment. Specifically, the ~/Downloads folder occupies a special status on most computing systems because it is one of the few directories that a web page can write to independently.
According to Forever Security’s findings, a standard web page can silently download a file named AGENTS.md directly into a user’s Downloads folder without prompting the user or requiring any direct interaction beyond visiting a compromised or malicious site.

To demonstrate the viability of this delivery mechanism, the research team developed a proof-of-concept web page. When verified, the test page successfully dropped an AGENTS.md file containing harmless placeholder strings directly into the default local directory.
By default, several of the world’s most popular web browsers, including Google Chrome, Microsoft Edge, and Mozilla Firefox, save files acquired from the internet straight to the local Downloads directory without forcing the user to manually select a destination for every individual asset. While browsers typically display download notifications or small status alerts to indicate that a file has been saved, many users routinely ignore these transient visual cues. Other web browsers, such as Brave, handle incoming files differently by prompting the user to approve the download action, providing an extra layer of user awareness.
However, simply dropping a file into the Downloads folder is only the first phase of the attack chain. For the payload to activate, the target user must subsequently launch an AI coding agent with that exact directory set as the active working space, allowing the tool to ingest the malicious instructions.
Researchers pointed out that this user behavior is surprisingly common in everyday development workflows. People frequently rely on AI agents to help organize messy directories, review newly acquired scripts, or quickly inspect archives and files that have just been saved from the web.
Internal telemetry and statistics gathered by the researchers indicate that hundreds of customers routinely run prominent AI coding assistants, including Claude Code, OpenAI Codex, and the Cursor CLI, directly from their home Downloads folders. For instance, analytics shared by the researchers revealed that Claude Code alone had launched more than 1,300 distinct sessions from that exact high-risk location.
Tests Show Attack Feasible
To measure the real-world viability of the threat, the research team executed a series of controlled tests against major AI coding frameworks. When testing their reconstructed attack chain against OpenAI Codex using a benign payload designed to open the local operating system calculator application, the researchers recorded a staggering 90% success rate across trials.
In a separate, more advanced test focusing on data exfiltration, the researchers utilized a malicious CLAUDE.md file to manipulate Claude Code’s underlying API traffic, redirecting network communications to a server under their direct administrative control. This redirection exposed the active agent’s OAuth token, effectively enabling the attacker-controlled server to impersonate the legitimate AI model and issue unauthorized tool calls that successfully executed arbitrary code in approximately half of all test runs.
The researchers emphasize that the underlying risk stems entirely from an intersection of intended browser behaviors and autonomous agent design, placing the ultimate responsibility for prevention and defense squarely on the shoulders of the end user.
Security experts advise that users should strictly avoid setting the home Downloads folder, or any other broad system directory that frequently receives unvetted files from the internet, as the working directory for AI coding agents.
Major artificial intelligence developers, including OpenAI and Anthropic, explicitly recommend that users initiate their AI coding agents strictly within the isolated root directory of the specific software project they intend to modify.
Keeping the active working directory closely scoped to the relevant project helps supply the artificial intelligence model with appropriate context while effectively limiting its operational scope. This narrow boundary drastically reduces the likelihood that the agent will inadvertently discover, process, and act upon untrusted files located in unrelated system directories.
The core recommendation from industry guidelines is to start an AI coding agent at the exact root of the target project rather than operating out of a broad parent directory or a general user profile folder. Users are advised to keep the agent’s filesystem access as narrow as practical, expanding permissions only when explicitly necessary for the task at hand.
Furthermore, development professionals should carefully review unfamiliar instruction files such as AGENTS.md, CLAUDE.md, and similar markdown directives before permitting an AI coding agent to parse them. Maintaining strict approval prompts, utilizing sandbox protections, and testing potentially untrusted code within an isolated environment before executing it on a primary production system remain essential baseline precautions for safely navigating the era of autonomous software agents.
