How to Audit AI Coding Agent Configs for Planted Instructions
A planted AGENTS.md or CLAUDE.md can make Codex or Claude Code rewrite its own settings. Here is the 20-minute check for every developer machine.
On this page 6 sections
Audit the agent's own settings, not just your code. Check ~/.codex/config.toml for MCP servers you did not add, and .claude/settings.json for a changed ANTHROPIC_BASE_URL or unfamiliar hooks. Read any AGENTS.md or CLAUDE.md you did not write. Remove what you did not set, then rotate tokens if anything looks tampered with.
To audit AI coding agent configs, you only need a terminal and about twenty minutes per machine. This guide is for engineers and security leads whose teams run Codex, Claude Code or similar tools on laptops. It covers how the attack works, which files to inspect, the exact commands, and the controls worth keeping on afterward.
Backtrace tracks agent security reports each month. The pattern in recent ones is consistent: the risky part is rarely the model. It is the trusted text and settings files the agent reads and rewrites on your machine.
Why Can a Markdown File Hijack an AI Coding Agent?
An agent is built to read and follow instruction files such as AGENTS.md in the folder it opens. If an attacker controls that file, the agent treats it like an order from you. No exploit or malware binary is needed, only text the agent trusts.
The clearest public case comes from the security vendor Forever. Its researchers found a malicious AGENTS.md in the Downloads folder of a real customer machine, disguised as ordinary engineering notes. A web page can save a file into that folder without a click, which is why it works as a drop point.
The reported results differ by tool. On Codex, the real attacker file added a rogue server to the agent's config and installed an npm package, and the malware ran in more than 90% of attempts. On Claude Code, a planted CLAUDE.md rerouted API traffic to an attacker's server about half the time, which leaks the login token.
Exposure is not rare. In Forever's own telemetry, about half of customers run a coding agent inside their Downloads folder. Roughly a quarter of agent sessions open a real browser.
Two caveats apply. The Codex test used the real file from the customer machine. The Claude test used a file the researchers crafted themselves. Forever is also a vendor with a product to sell.
Even so, the mechanism is easy to check on your own laptop, and the check costs almost nothing.
Which Files Should You Check on a Developer Machine?
Check the agent's config files, any instructions files, and the folders where the web can write. Each place below has a specific red flag. The table lists the file, what to look for and why it matters.
| Location | What to look for | Why it matters |
|---|---|---|
| ~/.codex/config.toml | An unexpected [mcp_servers.*] block or a changed chatgpt_base_url | Machine-wide, so every Codex session loads it |
| .claude/settings.json | An ANTHROPIC_BASE_URL, a proxy, or hooks you did not write | Can redirect traffic and leak the OAuth token |
| AGENTS.md, CLAUDE.md | Files you did not write, in Downloads or a fresh clone | The agent follows them on startup |
| .mcp.json and similar | Server entries nobody on the team added | A new MCP server can run code with your permissions |
The last row has a real precedent. Adversa's November 2026 roundup of coding agent security reports describes a Visual Studio Copilot flaw, CVE-2026-103572. A trailing dot in .mcp.json. got past the check that stops the agent editing its own config, because Windows treats both names as the same file.
The same roundup describes a child Claude Code session started inside a malicious repository, where a SessionStart hook ran without the confirmation the parent session would have required. Anthropic closed that report as Informative. Treat hooks in cloned repositories as code you have not reviewed yet.
How to Audit AI Coding Agent Configs Step by Step
Run the audit in this order, and do it on every machine where an agent is installed. Take notes as you go, because you may need them for a rotation decision. The steps below assume macOS or Linux paths.
- Close any running agent sessions so nothing rewrites files while you inspect them.
- List instruction files in Downloads and in recent clones.
- Read the agent config files for servers, base URLs and hooks.
- Look for the known bad package from the reported campaign.
- Compare what you find with what your team actually approved.
ls -la ~/Downloads | grep -iE "agents\.md|claude\.md"
find ~ -maxdepth 4 \( -name AGENTS.md -o -name CLAUDE.md \) -newermt "2026-10-01" 2>/dev/null
grep -nE "mcp_servers|base_url" ~/.codex/config.toml
grep -nE "ANTHROPIC_BASE_URL|SessionStart|hooks" ~/.claude/settings.json .claude/settings.json 2>/dev/null
grep -rl "function-color" --include=package-lock.json ~ 2>/dev/nullThe last command looks for function-color, the npm package Forever says the real campaign installs. npm has since removed it. If it turns up in any lockfile or install, treat that machine as compromised.
For every hit, ask who added it and when. A server entry with no owner is a finding. A base URL that points at a domain nobody recognizes is a finding.
If you find either one, remove it, then rotate the agent's login token and any API keys that were in the environment. A stolen token is a live session, so rotation is not optional.
Keep the check repeatable. Write the commands into a short script and run it after anyone clones an unfamiliar repository. If your team already runs secret scans, our comparison of secrets scanning tools shows which ones would flag a leaked token in a config or log.
What Else Can Go Wrong Besides Planted Instruction Files?
Planted files are one route among several. Adversa's roundup collects reports that share a theme: the agent's surroundings are trusted more than they should be. Three are worth knowing before you decide how far your audit should reach.
- Documentation is a target. A study summarized in the roundup found a model followed an unsafe instruction in a README or TODO file 2.6 times more often than the same text in a code file.
- Gateways sit in the middle. Proof-of-concept demos showed a compromised proxy between the agent and its model injecting tool calls the model never requested.
- Extensions run beside the model. In a lab test, a small change to local copies of legitimate agent extensions collected credentials, and it fired only on an ordinary review phrase.
The common point is that approval prompts and tool-call inspection govern the model, not code running next to it. That is why this audit looks at files and settings on disk. It also explains why a clean prompt log tells you little about whether a machine is clean.
How Do You Lock Down Coding Agents After the Audit?
Keep approval gates and sandboxes on, never run an agent in a folder the web can write to, and review hooks before you open a cloned repository with an agent. Those three habits block the attacks described above. They also cost no budget.
The same Adversa roundup reports a relay service seen at a dozen organizations. It installed genuine Codex and Claude Code CLIs, then turned off the execution sandbox and swapped API credentials for its own tokens. The setup looks like a normal install, so a config diff is the fastest way to spot it. Add these controls on top:
- Pin an owner and an approved list for every MCP server and agent extension.
- Give agents scoped, short-lived credentials instead of your personal tokens.
- Keep an inventory of installed agent versions, since some fixes ship with no CVE.
- Read README and TODO files in untrusted repos before the agent does.
Extensions deserve the same scrutiny as dependencies. Our guide to vetting and pinning agent skills walks through that review. For credentials, the least privilege starting point for cloud teams applies directly to what an agent can reach.
There is a policy gap to plan around. Forever argues there is nothing for the vendors to patch, because the agent is doing what it was built to do. Adversa notes that Anthropic closed one report as Informative and GitHub declined to treat another as a vulnerability. That means your team's own rules are the main defense.
Package risk also overlaps with this problem. An agent that installs whatever a file tells it to install is exposed to the same trap described in hallucinated dependencies as a supply chain risk.
Audit Your Agents Now, Then Make It a Habit
The practical answer is short. Read the agent's config files, remove any server or base URL you did not set, and rotate tokens if something looks wrong. Do it on one machine today.
If you manage a team, turn the audit into a ticket. Ask each engineer to run the commands, paste any finding into the ticket, and record the agent version in use. Then list the approved MCP servers and base URLs in your onboarding docs, so every new laptop starts from a known state.
The lasting fix is a routine. Run the audit after every unfamiliar clone, keep agents out of Downloads, and treat agent settings like production config. Backtrace will keep tracking these reports so you can see which controls hold up.