Zero Day Room
Live
Threats

Malicious files in Downloads folders hijack AI coding agents

Security researchers found that AI coding agents can be tricked by malicious instruction files, like AGENTS.md, placed in a user's Downloads folder, leading to malware installation and account takeover.

Security researchers found that AI coding agents can be tricked by malicious instruction files, like AGENTS.md, placed in...

A malicious AGENTS.md file in a developer's Downloads folder attempted to make an AI coding agent install a known-malicious npm package, which could lead to account takeover through session token leakage. Security researchers discovered that malicious AGENTS.md files in download folders can hijack AI coding agents by exploiting their automatic file-loading behavior. The file was discovered in a customer's Downloads folder by security firm Forever Security. It instructed the AI coding agent to add a server to its configuration and install the npm package 'function-color'. AI agents automatically load files from their working directory and follow instructions to guide actions. Malicious instructions in non-executable files can cause AI agents to run commands, install packages, or change settings using available tools and permissions. Hundreds of customers run AI agents from their ~/Downloads folders, including Claude Code which launched over 1,300 sessions from that location. The proof-of-concept demonstrated that a malicious page could drop an AGENTS.md file into Downloads without user interaction. The attack exploits two conditions: agents trust instructions files in their working directory, and web pages can silently save files to the Downloads folder.

How the MALFEX malware campaign works

The attack chain uses deceptive markdown files to install malicious npm packages that pull in downloaders fetching Windows payloads. The 'function-color' package is part of the MALFEX malware campaign, which pulls in a downloader called 'function-flag' that fetches and runs a Windows payload. Researchers at CloudSEK and Checkmarx analyzed the MALFEX campaign. They found a malicious AGENTS.md file in a customer's Downloads folder that tricked an AI coding agent into installing a rogue npm package. The attack was reproduced against OpenAI Codex and demonstrated against Claude Code, allowing OAuth token theft and account hijacking. Markdown files like AGENTS.md are plain-text files containing project-specific instructions for AI coding agents. The malicious AGENTS.md file was located in the customer's ~/Downloads folder, which served as the agent's working directory. There is no patch available from OpenAI or Anthropic because the agents follow instructions as designed, similar to a browser rendering a phishing page. Forever Security said: "There is nothing here for OpenAI or Anthropic to patch."

Platform-specific success rates and limitations

The attack achieves high success against Codex but requires user approval against Claude Code, creating inconsistent threat levels across platforms. The attack was tested on two coding agents: Codex and Claude Code. The attack has a 90% success rate when tested against Codex using a harmless payload.

AgentSuccess RateKey Action Required
Codex>90%Modify ~/.codex/config.toml to register malicious server
Claude Code~50%User approval for writing to project settings file to leak token

Against Codex, the attack succeeded in more than 90% of attempts by modifying ~/.codex/config.toml to register a malicious server. Against Claude Code, the attack succeeded less often and required approval for writing to a project settings file to leak the session's login token. A malicious CLAUDE.md file redirected Claude Code's API traffic to a controlled server, exposing OAuth tokens in roughly 50% of tests. Once attackers have valid credentials, only 37% of their actions are blocked. The attack requires the target to launch their AI agent in the same directory as the malicious file.

Practical mitigation steps for users

Security teams recommend checking download folders for suspicious instruction files, reviewing agent configuration files, and maintaining approval prompts and sandboxes. Forever Security advises not to start coding agents in the Downloads folder, as it is writable by web pages without user interaction. Users should check for unexpected instructions files like AGENTS.md or CLAUDE.md in Downloads or cloned repositories before running agents. Users should review their agent's config files (e.g., ~/.codex/config.toml) for unauthorized server blocks or base URL changes. Users should keep approval prompts and sandboxes enabled and avoid instructions that ask to disable them. If a planted file is found, the session's login token should be rotated immediately, as it may have been leaked. About half of Forever Security's customers run a coding agent in their Downloads folder. Roughly a quarter of agent sessions involve the agent browsing the web on its own, creating a window for file drops without human oversight. Chrome, Edge, and Firefox save downloaded files to ~/Downloads by default without prompting for save location, though download notifications do alert users. Brave prompts users to approve downloads, which alerts them to file downloads. Immediate rotation of compromised session login tokens is critical.

Related coverage

More from Threats