Skip to content
AI artificial intelligence
About usLet’s talk
Back to articles

An AGENTS.md in Downloads can hijack your AI agent. What to check in Codex and Claude Code

A malicious AGENTS.md in Downloads told an AI agent to install a harmful package. We explain the attack and what to check in Codex and Claude Code.

In short

On October 22, 2026, Forever Security described how it found a malicious AGENTS.md file in a customer's Downloads folder that told an AI agent to install the harmful npm package function-color. According to Forever, the package never ran because its tool blocked it. It is unclear how the file got onto the computer.

AGENTS.md is a plain text file with instructions for coding agents such as Codex or Claude Code. The agent reads it on its own at startup if the file sits in the folder where you launch it. And Downloads is the place on your disk that the web can write to most easily.

In Forever's tests, the malicious file got Codex to run the attacker's code (in the tests, a calculator) in more than 90% of attempts, and got Claude Code to route its traffic to a foreign server in roughly half of them. According to Forever, this is not a bug to patch but a consequence of how agents read files from their working folder.

What to do today

  • Do not run AI agents in your Downloads folder or on your Desktop; start them in the folder of a specific project.
  • Check whether Downloads contains AGENTS.md or CLAUDE.md files that you did not create.
  • Look through your Codex configuration and Claude Code settings for unknown MCP servers and API addresses.
  • Do not turn off approvals or the sandbox. If you find a suspicious file, rotate your tokens and tell the person or company that looks after your IT.

What Forever Security found

According to Forever Security's write-up, an agent at a customer tried to install the package function-color. Researchers Gal Weizman and Omer Samet traced it back to an AGENTS.md file in the ~/Downloads folder. The file was about 13 KB and posed as internal engineering team guidelines: a long, boring document in which the instructions for the agent get lost among ordinary rules.

The Hacker News adds that function-color pulls in a second package, function-flag, which downloads a malicious program for Windows. CloudSEK and Checkmarx had already described the campaign under the name MALFEX. The function-color package is no longer on npm.

Forever did not establish where the file on the customer's disk came from. It did show, on its own demo page, that a website can save a file to Downloads without asking. BleepingComputer checked that page: with default settings, Chrome, Edge and Firefox saved a harmless AGENTS.md file right away and only showed a download notification, while Brave asked for permission. The Hacker News notes that it is not known whether the malicious file reached the customer this way.

Why a text file can take over an agent

AGENTS.md is an open format: a Markdown file in which you describe the project, commands and working rules for an agent. According to the Codex documentation, Codex reads AGENTS.md files before it starts any work: first the global one from ~/.codex, then each one from the project root down to the folder where it was launched. If the folder is not part of any repository, Codex checks only that folder.

Claude Code works the same way with CLAUDE.md files. According to Anthropic's documentation, it loads them at startup from the current folder and from parent folders, and it can read AGENTS.md in place of CLAUDE.md. To the agent, such a file is not an ordinary document but an instruction from the project owner.

The trouble starts when you launch the agent in a folder the web writes to. A typical case: you ask the agent to tidy up Downloads or to rework a file you just downloaded, and you open the terminal right there. According to Forever's telemetry, roughly half of its customers do this. Gal Weizman told BleepingComputer that among those customers, Claude Code alone was launched from Downloads more than 1,300 times.

What the Codex and Claude Code tests showed

Forever reproduced the attack in an isolated virtual machine. In most attempts it used a harmless payload that opened a calculator instead of the harmful package; it ran the real file with the package once. We do not repeat the malicious instructions here.

In Codex, the file pushed the agent to add a new MCP server to ~/.codex/config.toml and to start another copy of Codex with the flag --dangerously-bypass-approvals-and-sandbox, meaning without approvals and without a sandbox. That configuration file applies to the whole computer, so the entry stays and works in every later project. According to Forever, this worked in more than 90% of attempts, and along the way the attack got past five safeguards, including folder trust and the network sandbox.

In Claude Code, a crafted CLAUDE.md file told the agent to write ANTHROPIC_BASE_URL into .claude/settings.json. Claude Code then sends its requests, together with the OAuth login token, to the attacker's server, and that server answers as if it were the model and can request shell commands with the sandbox turned off. According to Forever, this succeeded in roughly half of the attempts, and running code in the same session, through a subagent, in about a fifth. The change takes effect from the next Claude Code launch in that folder; in the current session, only once the agent starts a new subagent. According to Forever, a leaked token is enough to take over the account. The same file that worked in a clean folder failed every time in a folder full of security notes.

That is why Forever writes that there is nothing here for OpenAI or Anthropic to patch. An agent that is meant to follow instructions from AGENTS.md will also follow malicious instructions if the file sits in the wrong place. Your defense depends on where you launch the agent and what it is allowed to do.

Is marking the folder as untrusted enough

Do not count on it. According to the Codex configuration docs, in a project marked as untrusted Codex skips the layers from the project's .codex/ folder: configuration, hooks and rules. Forever writes that Codex follows AGENTS.md only in a trusted project, but working in Downloads once is enough for the folder to become trusted. On top of that, in a GitHub issue from August 29, 2026, a user described Codex 0.150.1 adding AGENTS.md from an untrusted project to its context as well. On October 29, 2026, the issue was still open with no reply from OpenAI.

Claude Code asks whether you trust a new folder the first time you launch it there. According to the Claude Code security documentation, that question does not appear in non-interactive mode with the -p flag or when working through the SDK. The question only comes up on the first launch, so once you have trusted Downloads, you will not see it again.

A browser setting does help. In Chrome you can turn on a prompt asking where to save each file; then a website cannot save anything to Downloads without your click. According to BleepingComputer, Brave asks by default.

What to check on your computer

The commands below only read files and change nothing. They are written for a terminal on macOS and Linux, and we checked them on Linux; on Windows, search File Explorer for the same file names in your Downloads folder. In the Codex configuration, Forever also advises checking chatgpt_base_url, the address Codex uses when you sign in with ChatGPT.

If you find an AGENTS.md or CLAUDE.md that you did not create, read it first, delete it only afterwards, and keep a copy for the person or company that looks after your IT. If the configuration contains an entry you did not add, remove it and rotate your tokens: sign out of Codex and Claude Code, sign in again and revoke the API keys stored on that computer.

Where to look for traces of the attack
ToolFileWhat to look forWhat to do
Codex~/.codex/config.tomlUnknown [mcp_servers.*] sections or a changed chatgpt_base_urlRemove the entry, rotate tokens
Claude Code.claude/settings.json in the folder where the agent ran, and ~/.claude/settings.jsonANTHROPIC_BASE_URL or proxy settings you did not addRemove the entry, sign in again
Any agentDownloads and DesktopAGENTS.md, AGENTS.override.md or CLAUDE.md files you did not createRead, keep a copy, delete
npmnode_modules foldersThe packages function-color and function-flagDisconnect the computer from the company network and call whoever handles your IT
Terminal on macOS or Linux – read-only
# Agent instruction files in Downloads and on the Desktop
find ~/Downloads ~/Desktop -maxdepth 3 \( -name AGENTS.md -o -name AGENTS.override.md -o -name CLAUDE.md \) 2>/dev/null

# MCP servers and API addresses in the Codex config
grep -nE '^\[mcp_servers|base_url' ~/.codex/config.toml 2>/dev/null

# API address and proxy in Claude Code settings
grep -nE 'ANTHROPIC_BASE_URL|PROXY' ~/.claude/settings.json ~/Downloads/.claude/settings*.json 2>/dev/null

# Packages from the MALFEX campaign (depth 4 is an example, increase it if needed)
find ~ -maxdepth 4 -type d \( -name function-color -o -name function-flag \) 2>/dev/null

What to set up at your company

If several people at your company use agents, write down a simple rule: the agent starts only in a project folder, never in Downloads, on the Desktop or in the home directory. According to BleepingComputer, OpenAI and Anthropic also recommend launching the agent in the project root.

An agent that browses the web on its own can also download something on its own. According to Forever, roughly a quarter of agent sessions at its customers open a real browser. Give such agents a separate working folder, with no keys and no access to the configuration of other tools.

Rules for the team

  • We launch agents in the project folder, not in Downloads, on the Desktop or in the home directory.
  • We use flags that turn off approvals and the sandbox only on isolated machines.
  • The browser asks where to save each file.
  • We review changes to ~/.codex/config.toml and .claude/settings.json like code changes.
  • When we find a suspicious file, we rotate tokens and tell the person or company that looks after our IT.

What we did not test

We did not reproduce the attack and did not run the malicious file or the function-color package. We describe the tests and their results based on Forever Security's write-up; more than 90% and roughly half of the attempts are Forever's figures, not our measurements.

We did not check Cursor, GitHub Copilot or other agents that read AGENTS.md. We know how Codex behaves in an untrusted project from the documentation and the GitHub issue, not from our own test. We ran the commands from the section above on Linux against sample files to confirm that they find the traces and change nothing; we did not run them on macOS.

Frequently asked questions

Is it enough to delete the AGENTS.md file from Downloads? If an agent never ran in that folder, usually yes. If one did, also check the Codex configuration and Claude Code settings, because according to Forever the attack adds entries there that stay after the file is deleted.

Does this only affect Codex and Claude Code? Forever tested these two tools. AGENTS.md is an open format that many coding agents read, so the same rule applies to each of them: the agent follows instructions from files in the folder where you launch it.

Can a browser really save a file without asking? According to BleepingComputer, with default settings Chrome, Edge and Firefox save a downloaded file to Downloads right away and only show a notification. You can change this in your browser settings by turning on the prompt asking where to save.

Is using ChatGPT or Claude in the browser at risk? This attack targets agents that run on your computer and read files from your disk on their own, such as Codex or Claude Code in the terminal. A regular chat in the browser only sees files you upload to it yourself. Be careful with apps and modes that you give access to folders on your disk: the same rule applies to them.

What next

We cover in more detail how content from the web and documents tries to give an agent orders in our prompt injection guide. If Claude Code runs in auto mode at your company, check what to set up in a separate guide. We collected the rules on what an agent may do without human approval in the AI agent permissions checklist.

Prompt injection: when a document tries to give your agent orders →Claude Code stops asking about every command: auto mode by default and what to set up at work →AI agent permissions checklist for business →

Sources and further reading

The sources behind this article. Instructions and example scenarios are suggestions from our editorial team.

Back to articles