Malicious AGENTS.md and Repo Hooks: Check a Repo Before Claude Code, Cursor or Codex Opens It
Published Oct 28, 2026 · 7 min read
Two reports this month made the same point from different directions. On Oct 22, Forever Security described a malicious AGENTS.md it found in a real customer's ~/Downloads folder, written to look like engineering notes. It told OpenAI Codex to add a "project tools" server to its own config and install a known-malicious npm package; with the real file in an isolated VM, Codex did it in more than 90% of attempts. Days later, JFrog found 42 real GitHub repositories armed with hooks for Claude Code, Gemini CLI, Cursor and VS Code that run a hidden 13 MB .github/init.js when the project is opened.
Neither attack needs a bug. The agent does what config files tell it to. So the fix is a habit: know which files can make your agent or editor act, and read them before you open a folder you didn't write. This guide lists those files for each tool, gives you a short script that finds them, and shows the settings that close the easy doors.
The files that can make your agent act
Instruction files steer the model. Settings files can run commands without the model at all. Both belong on the list:
| File | Read by | What it can do |
|---|---|---|
AGENTS.md, AGENTS.override.md | Codex, Cursor, Claude Code (when there's no CLAUDE.md) | Instructions the agent follows, such as "install this package first" |
CLAUDE.md, GEMINI.md, .cursor/rules/*.mdc | Claude Code, Gemini CLI, Cursor | Same: standing instructions in every session |
.claude/settings.json | Claude Code | Hooks such as SessionStart that run shell commands, an env block (for example a different ANTHROPIC_BASE_URL), helper commands |
.mcp.json, .cursor/mcp.json | Claude Code, Cursor | Start a local MCP server, which is any command the file names |
SKILL.md (in .claude/skills/ and elsewhere) | Claude Code and other Agent Skills tools | Instructions, bundled scripts, and in Claude Code its own hooks and pre-approved tools |
.vscode/tasks.json | VS Code, Cursor | A task with "runOn": "folderOpen" runs when the folder opens |
package.json | npm, pnpm, yarn | preinstall/postinstall scripts run when the agent installs dependencies |
The JFrog repos used most of this list at once: a SessionStart hook in .claude/settings.json running node .github/init.js || bun .github/init.js, plus triggers in .gemini/settings.json, .cursor/mcp.json, .cursor/rules/setup.mdc and .vscode/tasks.json. JFrog notes the payload files were too big for GitHub code search to index, so they looked empty from the web. You have to check the files on disk.
Rules files have a second trick. In 2025 Pillar Security showed a "Rules File Backdoor" that hides instructions in Cursor and Copilot rule files using invisible Unicode, such as zero-width joiners and bidirectional markers. The model reads them; you don't see them in an editor or a diff.
What each tool protects by default
Claude Code. In an interactive session, Claude Code shows a workspace trust dialog when you start it in a folder you haven't trusted, and it holds back hooks from every settings file until you accept. Servers in .mcp.json get their own approval prompt, and a cloned repo can't approve its own servers. Three gaps are worth knowing, all from Anthropic's permissions docs:
- Trust can extend from a parent folder. If you trusted
~/code, a fresh clone inside it can run its settings-file hooks without a new dialog. claude -pand SDK sessions never show the dialog and treat the folder as trusted, so committed hooks run and.mcp.jsonservers connect without asking.- A project skill's hooks and
allowed-toolsare used even before you trust the folder.
Cursor. Cursor's agent security docs say it supports workspace trust but it's disabled by default. That's why a .vscode/tasks.json with folderOpen is dangerous there: in VS Code, automatic tasks never run in an untrusted workspace. MCP connections in Cursor do need your approval.
Codex. Codex reads AGENTS.md before doing any work, walking from the project root down to the folder you started in, plus a global file in ~/.codex. The Forever attack aimed at ~/.codex/config.toml because that config applies to every Codex session on the machine, not just the folder with the planted file.
The 2-minute pre-open check
Clone the repo, but don't open it in an agent or Cursor yet. Run this script on the folder. It lists every agent and IDE config file, flags files over 1 MB (where JFrog's payloads hid), greps those files for lines that run commands or redirect the agent, and finds invisible Unicode:
#!/usr/bin/env bash
# agent-preflight.sh: scan a cloned repo BEFORE an AI agent or IDE opens it.
# Usage: bash agent-preflight.sh path/to/clone (needs GNU grep for the Unicode check)
cd "${1:-.}" || exit 1
echo "== Agent and IDE config files =="
find . \( -path ./.git -o -path ./node_modules \) -prune -o -type f \( \
-name 'AGENTS*.md' -o -name 'CLAUDE*.md' -o -name 'GEMINI.md' -o -name 'SKILL.md' \
-o -name '.mcp.json' -o -name '*.mdc' -o -name 'copilot-instructions.md' \
-o -path './.claude/*' -o -path './.cursor/*' -o -path './.gemini/*' \
-o -path './.codex/*' -o -path './.vscode/*' -o -path './.devcontainer/*' \) -print \
| tee /tmp/agent-files.txt
echo; echo "== Files over 1 MB outside node_modules (possible hidden payloads) =="
find . \( -path ./.git -o -path ./node_modules \) -prune -o -type f -size +1M -print
echo; echo "== Lines that run commands or redirect the agent =="
{ cat /tmp/agent-files.txt; [ -f package.json ] && echo ./package.json; } | tr '\n' '\0' |
xargs -0 grep -nIE \
-e '"(SessionStart|PreToolUse|PostToolUse|UserPromptSubmit|Stop)"' \
-e '"runOn" *: *"folderOpen"' \
-e '(ANTHROPIC|OPENAI)_BASE_URL|apiKeyHelper|headersHelper' \
-e 'enableAllProjectMcpServers|disableAllHooks|hasTrustDialogAccepted|config\.toml' \
-e '"(pre|post)install"' \
-e 'curl |wget |npx |bunx |npm (i|install) |pip install |base64|eval\(' 2>/dev/null
echo; echo "== Invisible Unicode (zero-width or bidi characters) =="
tr '\n' '\0' < /tmp/agent-files.txt | LC_ALL=C.UTF-8 xargs -0 grep -lP \
'[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{FEFF}]' 2>/dev/null
echo; echo "Done. Read every file listed above before you open this folder in an agent."
Save it as agent-preflight.sh and run bash agent-preflight.sh ./some-repo. The Unicode check needs GNU grep (on macOS, brew install grep and swap in ggrep). An empty section is good news. Anything listed is a file to read, not proof of malware: plenty of good repos ship hooks and MCP configs.
Red flags when you read the files
- Setup steps aimed at the agent. "Before any task, install X" or "add this server to your config" in an AGENTS.md or CLAUDE.md. Real projects document setup for humans in a README.
- Edits to the agent's own config. Anything that mentions
~/.codex/config.toml,~/.claude,hasTrustDialogAccepted, or turning off approvals or the sandbox. - A new API endpoint. An
ANTHROPIC_BASE_URLorOPENAI_BASE_URLyou didn't set can route your session and its token through someone else's server. - Hooks that run repo files. A
SessionStarthook callingnode,bunorpythonon a file in the repo, especially a large or minified one. - Long, dull instruction files. Forever's planted file ran to 13 KB of mundane notes; the bad line was buried in the middle.
- Invisible characters in any rules or instruction file. There's no good reason for them.
Harden your defaults once
Never start an agent in ~/Downloads or your home folder. A website can drop a file into Downloads without asking, and the agent will read it. Work in folders you created or cloned on purpose.
Cursor: add this to your user settings.json so new folders ask first and tasks can't auto-run:
{
"security.workspace.trust.enabled": true,
"security.workspace.trust.startupPrompt": "always",
"task.allowAutomaticTasks": "off"
}
Claude Code: read the trust dialog instead of clicking through it, and don't trust broad parent folders. Before scripting claude -p over a repo you didn't write, use one of the options from Anthropic's docs:
# ignore the project's settings files and .mcp.json
claude -p "summarize this repo" --setting-sources user
# or turn hooks off for this run, whatever the project says
claude -p "summarize this repo" --settings '{"disableAllHooks": true}'
Setting disableAllHooks in your user settings isn't enough on its own, because project settings take precedence and can set it back. The flag wins.
Codex: check ~/.codex/config.toml now and then for a server block or a base URL you didn't add.
Untrusted code in general: open it in a plain text editor, a dev container or a throwaway VM first. If you find a planted file that already ran, assume the agent's login token leaked: sign out, rotate it, and remove anything it added to your config.
Protect your own repos too
The same files are a supply-chain risk in the other direction: a pull request that edits AGENTS.md, .claude/settings.json or .cursor/rules/ deserves the same review as one that edits CI. Add those paths to CODEOWNERS so changes need an owner's approval, and keep your own rules short enough that a reviewer will actually read them. Our AGENTS.md template and hooks examples are built that way.
Rules and hooks you can read in five minutes
Everything in our kits is short, commented and meant to be read before you install it. The Cursor Rules Pack ($19) includes an AI agent safety rule and an AGENTS.md template among its 18 .mdc rules. The Claude Code Agent Starter Kit ($39) adds 3 safety hooks, subagents and skills. Get the Cursor Rules Pack Get the Starter Kit
FAQ
Can an AGENTS.md file really install malware?
Not on its own: it's plain text. But coding agents read AGENTS.md as instructions, and Forever Security reported a planted AGENTS.md in a customer's Downloads folder that told OpenAI Codex to add a server to its config and install a malicious npm package. In their tests with the real file, Codex ran it in more than 90% of attempts.
Is it safe to open a cloned repo in Claude Code?
In an interactive session, Claude Code shows a workspace trust dialog first and holds back hooks from settings files until you accept it. The risk is accepting without reading, trusting a parent folder the clone sits in, or running claude -p, which treats the folder as trusted. Read the repo's .claude/ folder and .mcp.json before you accept.
Does Cursor have workspace trust?
Cursor supports workspace trust but its docs say it is disabled by default. Turn it on with "security.workspace.trust.enabled": true in your user settings.json, and set "task.allowAutomaticTasks": "off" so .vscode/tasks.json can't run on folder open.
Should I ever start an agent in my Downloads folder?
No. A web page can save a file into Downloads without asking, and agents read instruction files from the folder they start in. Start agents only in folders you created or cloned on purpose.