Hidden instructions in rules files: how to find them
Run one search command for zero-width and bidi Unicode characters in every rules file. Remove any hit that you cannot explain. Require a code-owner review for each change to those files. A rules file can hold instructions that a human cannot see. The model still reads them.
This guide gives a working command, a list of file locations, and the steps to lower the risk.
What is a hidden instruction in a rules file?
A rules file is a text file that tells an AI coding agent how to work. Examples are AGENTS.md, CLAUDE.md, .cursorrules, and .cursor/rules/*.mdc. The agent reads the file at the start of a session. It treats the text as trusted guidance.
Unicode has characters that take no visible space. Examples are the zero-width space, the zero-width joiner, and the bidirectional (bidi) control characters. Unicode also has a block of “tag” characters. Each tag character maps to a plain ASCII letter. A string of tag characters can spell a full sentence that no one sees.
An attacker writes a normal rule, and adds the hidden text inside it. A human reviewer sees a normal rule. The model reads all of it.
Pillar Security named this attack the Rules File Backdoor. In their Cursor demo, a rule for simple HTML pages led the agent to add a script tag from an attacker site. The agent did not mention the change in its answer. The hidden text told it to hide the change. The hidden characters were also invisible in GitHub pull request reviews.
The vendor replies in that report were different. Cursor said that the risk falls under user responsibility. GitHub also said that users must review Copilot suggestions. GitHub added a warning for files with hidden Unicode on github.com on May 1, 2025.
Why does this matter for vibe coders?
Vibe coders copy rules files. They take them from GitHub repos, from directories of “best cursor rules”, and from blog posts. The file looks like plain text, so it feels safe.
The risk grows with time. A rules file stays in the repo. It affects every later session. It survives forks. Each team member who clones the repo gets the same hidden text.
A Cloud Security Alliance (CSA) note from October 2026 covers poisoned instruction files. It reports a case where a planted AGENTS.md file in a Downloads folder tried to make Codex install a malicious npm package. The note states that the researchers say there is nothing for OpenAI or Anthropic to patch in that case. The file is the attack, and the agent follows its input as designed.
This case does not need hidden Unicode. It shows the same root problem. The agent trusts text files that sit near the work.
How do I find zero-width and bidi characters?
Use one of these commands. They all search for the same set of characters:
- Zero-width and direction marks: U+200B to U+200F.
- Bidi embedding and override marks: U+202A to U+202E.
- Word joiner and invisible operators: U+2060 to U+2064.
- Bidi isolates: U+2066 to U+2069.
- Byte order mark inside a file: U+FEFF.
- Tag characters: U+E0000 to U+E007F.
With ripgrep
rg --hidden -n -P '[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{2066}-\x{2069}\x{FEFF}\x{E0000}-\x{E007F}]' .
The --hidden flag is important. Rules files live in folders such as .cursor and .claude. Ripgrep skips hidden folders by default. If your .gitignore hides a file, add -uu.
With GNU grep
grep -rnP '[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{2066}-\x{2069}\x{FEFF}\x{E0000}-\x{E007F}]' .
This works with a grep that supports Perl patterns and a UTF-8 locale. On macOS, some grep builds lack -P. Use ripgrep or the Python script in that case.
With Python
This script reports every format character. Unicode category Cf covers all the characters above. It does not depend on a grep build:
python3 -c "
import sys, unicodedata
for p in sys.argv[1:]:
for n, l in enumerate(open(p, encoding='utf-8', errors='replace'), 1):
bad = [f'U+{ord(c):04X}' for c in l if unicodedata.category(c) == 'Cf']
if bad: print(f'{p}:{n}: {\" \".join(bad)}')
" AGENTS.md CLAUDE.md .cursorrules .cursor/rules/*.mdc .github/copilot-instructions.md
Each hit shows the file, the line, and the code points. The output is empty when the files are clean.
Caution: A hit is not always an attack. A BOM at the start of a file is common. Emoji sequences and some languages use the zero-width joiner, too. Check each hit. A hit in the middle of an English rule is a red flag.
How do I see what the hidden text says?
Print the file with the characters made visible. This command shows tag characters as ASCII letters:
python3 -c "
import sys
t = open(sys.argv[1], encoding='utf-8').read()
print(''.join(chr(ord(c) - 0xE0000) if 0xE0000 < ord(c) < 0xE007F else c for c in t if c.isprintable() or c in '\n\t' or 0xE0000 < ord(c) < 0xE007F))
" AGENTS.md
Read the decoded text. Instructions to hide changes, send data, or add a script are a clear sign of an attack.
Where do rules files live?
Search all these places. Each tool has its own paths:
- Cursor:
.cursor/rules/*.mdc, and the older.cursorrulesfile. - Claude Code:
CLAUDE.mdin the repo, in subfolders, and in~/.claude/. - Codex and many other agents:
AGENTS.md. - GitHub Copilot:
.github/copilot-instructions.md. - Windsurf and others:
.windsurfrulesand tool-specific folders. - Agent skills and prompts: any Markdown file that the agent loads.
The CSA note names AGENTS.md, CLAUDE.md, .cursor/rules/*.mdc, and .github/copilot-instructions.md as common instruction files. It also warns about agent settings files such as .claude/settings.json and .mcp.json. These files can start commands directly. The guide on cloned repos covers them.
Also check your home folder. An agent that starts in ~/Downloads or in a parent folder can load a file that you forgot. Do not run agents from broad folders. Start them in the project folder.
How do I fix a file that holds hidden text?
Follow these steps.
-
Stop the agent session. Close the tool.
-
Run the search command and write down each hit.
-
Decode the hidden text with the script above.
-
Delete the file, or delete the bad lines. Do not keep text that you cannot explain.
-
Run the search again. The output must be empty.
-
Review the code that the agent wrote since you added the file. Check
git logandgit difffor new scripts, new packages, and new network calls. -
Search the app for new external URLs:
git diff <old-commit>..HEAD | grep -nE '^\+.*(https?://|<script|eval\(|fetch\()' -
Rotate any key that the agent could read, if the diff shows data sent to an unknown host.
Warning: Do not ask the same agent to check the file. The agent already follows the file. A hidden instruction can tell it to say that the file is clean.
How do I treat rules files like auth code?
A rules file changes how the agent writes code. It has the same weight as a security config. Review it the same way.
Add a CODEOWNERS entry. GitHub then requires a review from the named owner for each change:
# .github/CODEOWNERS
AGENTS.md @your-org/security
CLAUDE.md @your-org/security
.cursorrules @your-org/security
.cursor/rules/ @your-org/security
.github/copilot-instructions.md @your-org/security
.claude/ @your-org/security
.mcp.json @your-org/security
Turn on “Require review from Code Owners” in the branch protection rule for your main branch. A solo developer can name themselves, but must then read each change.
Add a CI check that fails on hidden characters. This GitHub Actions step uses ripgrep:
- name: Block hidden Unicode in agent files
run: |
sudo apt-get install -y ripgrep
if rg --hidden -n -P '[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{2066}-\x{2069}\x{E0000}-\x{E007F}]' \
AGENTS.md CLAUDE.md .cursorrules .cursor .github/copilot-instructions.md 2>/dev/null; then
echo "Hidden Unicode found"
exit 1
fi
The command omits U+FEFF to avoid false alarms from a BOM. The CSA note also advises that you scan for hidden Unicode in pre-commit hooks and in CI. A pre-commit hook gives the same result on the local machine.
How do I check a pull request that changes a rules file?
A diff view can hide the attack. The hidden characters have no width. A changed line can look the same as before.
-
Fetch the pull request branch. Do not open the folder with an agent.
-
Run the Unicode search on the changed files only:
git diff --name-only main...HEAD | xargs rg --hidden -n -P '[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{2066}-\x{2069}\x{E0000}-\x{E007F}]' -
Check the byte size of each changed rule. A short visible rule with a large byte size is a red flag.
-
Read the rule again as a stranger. Ask what each line makes the agent do.
-
Reject the pull request if a rule asks the agent to hide its work or to fetch a remote URL.
A rule must be short, visible, and clear. Merge only rules that meet all three tests.
Must I stop installing community rules files?
Do not install a community rules file blind. Follow these rules:
- Read the whole file in a text editor, line by line.
- Run the Unicode search on it.
- Copy only the rules that you need. Do not copy the entire file.
- Write the file again in your own words when you can.
- Pin the version. A link to a file on the
mainbranch can change later. - Do not run an install script from a rules directory.
A rule that tells the agent to fetch a URL, run a shell command, or hide its work is a warning sign. A normal style rule does not need any of these.
Are rules a security control?
No. A rule is text that the model reads. The model may follow it, or may not. An attacker can write a rule too.
The CSA note makes the same point. It cites a study that found only 4 to 16 percent of security rules in public CLAUDE.md files had a matching enforcement control. It calls CLAUDE.md a write-only channel. Use the rules file for style and team habits. Do not use it as the only guard for secrets or data.
Enforce the important limits outside the model:
- Permissions: Deny reads of
.envfiles and key folders. Allow only the commands that you need. - Sandbox: Run the agent in a container with no production keys.
- Network: Block outbound traffic that the task does not need.
- Review: Read every diff before you merge it.
- Approvals: Keep the approval prompts on. Treat an instruction to turn them off as a sign of compromise.
The agentic coding risks guide lists the main risks. The pattern page on indirect prompt injection explains why text in a file can act as an instruction. The malicious agent skill guide and the untrusted MCP server guide cover two related inputs.
When should I get help?
Ask for help in these cases:
- You find hidden text that asks the agent to send data or hide changes.
- The agent already ran with that file on a machine that held production keys.
- Your code history shows scripts or packages that no one on the team added.
- You cannot tell which of your keys the agent could read.
Rotate the keys first. Then ask a security person to review the repo history. After that, run a scan of your live app. The scan finds open routes, exposed keys, and open data that an injected change could have created.
Common questions
Can I see hidden Unicode in my editor?
Does the model really follow hidden text?
Is a rules file a security control?
Are all rules files from GitHub unsafe?
What must I do if I find a hidden character?
Check the app behind it
A poisoned rules file can steer an agent to weaken your code. A VibeEval scan tests the live web app and API from outside, for open routes, exposed keys, and open data.
14-day free trial · Cancel anytime