Rightshold™ Sign up

Answers · agent safety

How do I check whether an AGENTS.md or CLAUDE.md file in a downloaded folder or a parent directory is safe?

Last updated

TL;DR: Treat instruction files as text that steers your agent, and check every one it will load, not just the one in the project. The tools look in different places. Claude Code loads CLAUDE.md and CLAUDE.local.md from the directory you start it in and every directory above it, and loads ones in subdirectories once it works there; when no CLAUDE.md is on that path it reads AGENTS.md and .claude/AGENTS.md the same way (v2.1.277 or later). Codex reads your global ~/.codex file, then walks from the project root (by default the nearest directory at or above you that contains .git) down to where you started, taking one of AGENTS.override.md, AGENTS.md or a configured fallback name per directory. Cursor applies AGENTS.md in the project root and its subdirectories, plus .mdc rules in .cursor/rules. So a CLAUDE.md left in ~/Downloads is loaded by Claude Code for every project you start anywhere under ~/Downloads. Work from a dedicated folder you control, list instruction files in it, below it and in every parent, read them raw (including files they import with @path), then confirm what loaded: /context or /memory in Claude Code, or ask Codex to list its instruction sources. Instructions are context, not enforcement, and a repository's settings, hooks and .mcp.json can do more than its instructions can, so check those too.

What should I check, step by step?

1. Don't start agents in Downloads, your home directory or a shared parent folder. Move or clone the project into a dedicated work folder whose parents you control. Claude Code concatenates every CLAUDE.md from the filesystem root down to your working directory, so one planted file in a parent applies to every project beneath it.

  1. List instruction and config files in the folder and every parent before you start (macOS/Linux shell): d="$PWD"; while :; do ls -a "$d" | grep -E '^(CLAUDE(\.local)?\.md|AGENTS(\.override)?\.md|\.claude|\.codex|\.cursor|\.cursorrules)$' | sed "s|^|$d/|"; [ "$d" = / ] && break; d=$(dirname "$d"); done
  2. Search inside the project too, because Claude Code loads subdirectory CLAUDE.md files when it reads or edits files there and Cursor applies nested AGENTS.md files for work in that directory: find . \( -name CLAUDE.md -o -name CLAUDE.local.md -o -name AGENTS.md -o -name AGENTS.override.md -o -name '*.mdc' -o -name .cursorrules -o -name .mcp.json \) -not -path '*/node_modules/*'. Then list .claude/, .codex/ and .cursor/rules/ directly.
  3. Read each file raw (cat -A, or a plain editor), not as a rendered Markdown preview. Look for instructions to run commands, fetch URLs, read keys, tokens or SSH files, turn off checks, or hide what the agent did, and for invisible or bidirectional characters. Claude Code strips block-level HTML comments before loading a CLAUDE.md at launch, but they remain visible when Claude opens the file with its Read tool, so don't treat comments as harmless.
  4. Follow imports: Claude Code expands @path imports (paths relative to the importing file, up to four hops) and shows an approval dialog the first time a project imports files outside your working directory. Decline unless you know those files. An @file mention in a Cursor rule tells Agent to read that file with its tools when it needs it.
  5. Check the files that can run things, not just the instructions: .claude/settings.json (hooks, env, apiKeyHelper), .mcp.json, .codex/config.toml and .codex/hooks.json. Claude Code's docs say repository hooks in settings files are used even if you trusted only a parent folder, and in claude -p or SDK runs; Codex loads project-local hooks only when the project .codex/ layer is trusted.
  6. Confirm what actually loaded. Claude Code: run /context and check Memory files, or /memory (subdirectory files load later and print a Loaded line). Codex: run codex --ask-for-approval never "List the instruction sources you loaded." or log with -c log_dir=./.codex-log. Cursor: open Customize and look at Rules.
  7. Narrow discovery: Claude Code's claudeMdExcludes setting skips files by absolute path or glob (except a managed CLAUDE.md). In Codex, project_root_markers = [] treats the current directory as the project root so parents aren't searched. If your home directory is itself a git repository (some dotfile setups), Codex's default treats it as the project root and reads instruction files in every directory from home down to your working folder.
  8. Enforce limits outside the instructions: Claude Code's docs say CLAUDE.md is context, not enforced configuration, and point to permissions.deny, hooks and the sandbox for rules that must hold. For claude -p in a repository you didn't write (no trust dialog appears), the docs suggest --setting-sources user or --bare, and --settings '{"disableAllHooks": true}'.

How each coding agent finds instruction files

Claude Code: managed policy, then ~/.claude/CLAUDE.md, then CLAUDE.md and CLAUDE.local.md from every directory between the filesystem root and the working directory, concatenated root first, so the file closest to you is read last. Files in subdirectories load on demand when Claude reads, writes or edits a file there. By default AGENTS.md is read only if there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it; AGENTS.local.md, AGENTS.override.md and .agents/ are not read.

Why downloaded folders and parent directories are the risk

Unzipping or cloning into a folder that already holds an old CLAUDE.md or AGENTS.md puts that file on the agent's path. You read the project's instructions, but Claude Code also loads the parent's, and the model gets both as instructions.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Before I start my coding agent in this folder, scan this AGENTS.md / CLAUDE.md for hidden text and for instructions aimed at the agent.”

One-click setup

{
  "tool": "scan_text",
  "arguments": {
    "text": "<the full raw contents of the AGENTS.md, CLAUDE.md or .mdc rule>"
  }
}

Rightshold does not run your coding agent, read your folders or decide which instruction files load. It scans text you send it and checks MCP servers you ask about. Not legal advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'