AI coding agents read configuration and instruction files from the repository they are opened in, so a cloned repository, a dependency or a pull request can change what the agent is told, which tools it starts and, in some cases, which commands run on the developer's machine before anyone approves anything. Rules files, CLAUDE.md, .mcp.json, .cursor/ and .vscode/ settings, hook definitions and per-project MCP configuration are effectively code, but they rarely get the review that CI pipeline files receive. This guide explains the attack class at concept level, where it shows up across tools, its impact, how to detect it and how to prevent it. It is written for application security, platform and endpoint teams. Product permission settings are covered in the AI IDE and Coding Agent Security Guide; this page focuses on the configuration files themselves as an attack surface.
Key takeaways
- Repository config is executable surface. Hook definitions, MCP server start commands, environment blocks and credential helpers in committed files can launch processes with the developer's privileges and credentials.
- Trust prompts are the main control, and they have gaps. Vendors gate most repository settings behind a workspace trust dialog, but headless runs, parent-folder trust and approval bound to a name rather than content have each let configuration take effect without a fresh decision.
- Instruction files can carry invisible text. Researchers showed in March 2025 that rules files can hide instructions in zero-width and bidirectional Unicode characters that reviewers do not see but models read.
- Review these files like CI configuration. Put agent config paths under CODEOWNERS, scan them for hidden Unicode and command strings, and alert when they change.
- Take credentials out of reach. A malicious config file is dangerous mainly because the processes it launches inherit cloud sessions, tokens and keys. Short-lived, scoped credentials limit what any of these attacks can steal.
How the attack works
Coding agents load project-level files so that teams can share conventions, tools and permissions. The same mechanism lets anyone who can get a file into the working tree influence the agent. The attack falls into three families.
| Family | What the attacker controls | Mechanism (concept level) | Typical goal |
|---|---|---|---|
| Execution through configuration | Hook definitions, MCP server start commands, env blocks, helper commands in project settings | The client starts a process or sets environment values defined in the repository, sometimes before or without a trust decision | Run code with the developer's privileges; read credentials from the environment |
| Instruction poisoning | Rules and memory files such as .cursorrules, .cursor/rules, CLAUDE.md and similar instruction files | Text, sometimes hidden in invisible Unicode, that the model treats as project guidance | Steer generated code towards backdoors, make the agent run a "scan" that collects secrets, or suppress mention of its actions |
| Trust drift | A configuration entry that was previously approved | The entry is changed after approval and the client does not ask again | Swap a benign command for a malicious one after a colleague approved it |
The common thread is that the agent client, not the model, is the component that reads and acts on these files. Model-level guardrails do not help when the client itself starts the process.
Where it shows up
Every major coding agent reads repository files. The table lists documented examples; check each tool's current documentation, because names and behaviour change.
| Tool | Repository files that change agent behaviour | Documented gating |
|---|---|---|
| Claude Code | .claude/settings.json (permissions, hooks, env, helpers), CLAUDE.md, .mcp.json, project skills and subagents | Workspace trust dialog in interactive sessions; separate approval prompt for .mcp.json servers; managed settings override project settings |
| Cursor | .cursor/rules, legacy .cursorrules, .cursor/mcp.json, .cursor/hooks.json, .cursor/ permissions and sandbox files | MCP configuration approval (re-prompt on change since version 1.3); team dashboard policy overrides local files |
| GitHub Copilot in VS Code | .vscode/settings.json, .vscode/mcp.json, repository custom instruction files | VS Code workspace trust; restricted mode disables agents; MCP servers inherit workspace trust |
| Amazon Q Developer | .amazonq/mcp.json in the repository root | Approval and trust check added after CVE-2026-12957 |
Documented cases
- Headless and parent-trust gaps in Claude Code: the Claude Code permissions documentation lists what a repository can still run when the folder itself has not been trusted. In a
claude -por SDK run the folder is never trusted, yet hooks in settings files, theenvblock and helper commands are used, and servers in.mcp.jsonare connected without asking. When only a parent folder was trusted, hooks and theenvblock are also used. Treat any automated agent run on untrusted code as running the repository's configuration. - Trust bound to a name (Cursor, CVE-2025-54136): Check Point Research reported in July 2025 that Cursor tied MCP approval to the entry's name rather than its contents, so a previously approved entry in a shared repository could later be changed without a new prompt. Cursor 1.3, released on 29 July 2025, requires approval for any MCP configuration change.
- Auto-start without trust (Amazon Q): in the Amazon Q MCP config vulnerability, opening a folder with
.amazonq/mcp.jsonlaunched the defined MCP servers without approval or a workspace trust check, and those processes inherited the developer's AWS credentials. AWS fixed it in Language Servers for AWS 1.65.0, with a related symlink flaw (CVE-2026-12958) covered in 1.69.0. - Hidden instructions in rules files: Pillar Security's "Rules File Backdoor" research (18 March 2025) showed instructions hidden with zero-width joiners and bidirectional markers in Cursor and GitHub Copilot rules files, invisible in pull request review. GitHub later added a warning on github.com for files containing hidden Unicode text.
- Instruction files as malware persistence: in the TrapDoor supply chain campaign, malicious npm packages wrote
.cursorrulesandCLAUDE.mdfiles with zero-width instructions aimed at getting the agent to find and send out secrets, and the operator opened pull requests proposing similar files to open-source AI projects.
Impact
- Credential theft: processes launched from configuration inherit environment variables, cloud CLI sessions, Git credentials and files such as
~/.aws/credentials. This maps to ATT&CK Credentials In Files (T1552.001). - Code execution on developer machines and CI runners: hooks and MCP start commands are a shell or interpreter execution path (Unix Shell, T1059.004), reached through a malicious file in a dependency or repository (Malicious File, T1204.002; Compromise Software Dependencies and Development Tools, T1195.001).
- Supply chain poisoning: steered code generation can insert subtle vulnerabilities or backdoors into products, and poisoned rules files spread through forks and templates.
- Persistent agent manipulation: instruction files are re-read every session. MITRE ATLAS describes the model-facing part as LLM Prompt Injection: Indirect (AML.T0051.001) and AI Agent Context Poisoning (AML.T0080), leading to AI Agent Tool Invocation (AML.T0053).
- Exfiltration through allowed channels: data leaves through permitted web requests, MCP tools or Git pushes (Exfiltration Over Web Service, T1567), which look like normal agent activity.
Detection
| Signal | Where to look | What to alert on |
|---|---|---|
| Changes to agent config paths | Pull requests, commit history, repository rules | Any change to .claude/, .cursor/, .vscode/, .amazonq/, .mcp.json, CLAUDE.md, rules and instruction files, especially from first-time contributors or dependency bots |
| Hidden or bidirectional Unicode | Pre-commit hooks, CI linters, code host warnings | Zero-width characters (U+200B to U+200D, U+2060, U+FEFF) and bidirectional controls (U+202A to U+202E, U+2066 to U+2069) in instruction and config files |
| Command strings in config | Static scan of hook and MCP definitions | Network tools, shell pipes, encoded payloads, references to credential paths, or package runners fetching unpinned versions |
| Files written by packages | Endpoint telemetry, package install logs | Package install scripts creating agent instruction or config files outside the package directory |
| Process lineage | EDR on developer endpoints and CI runners | Shells, interpreters or network tools spawned by the agent client or IDE language server shortly after a folder is opened |
| Agent telemetry | OpenTelemetry or vendor audit logs; Claude Code ConfigChange hooks | MCP servers connected that are not on the managed allowlist; settings changed during a session; tool calls reading secrets |
Metrics that show the programme is working:
- Percentage of repositories with agent config paths covered by CODEOWNERS (target 100% of active repositories).
- Number of agent config changes merged without security review per month (target zero).
- Hidden Unicode findings in instruction files, trending to zero after clean-up.
- Percentage of developer endpoints where managed settings restrict MCP servers and hooks to approved sources.
- Percentage of headless agent jobs that run with project settings disabled or in an isolated container.
Prevention and hardening
- Inventory and own the paths: list every agent config and instruction file pattern your tools read, add them to CODEOWNERS with security or platform reviewers, and protect them with branch rules.
- Scan before merge: add a CI check that fails on hidden or bidirectional Unicode and flags command strings, network calls and credential paths in hooks and MCP definitions. Start in report-only mode for two weeks to find legitimate uses, then enforce.
- Prefer managed over repository settings: set MCP allowlists, hook policy and permission rules in managed or team settings, which override repository files in the main tools. In Claude Code, managed MCP configuration and
disabledMcpjsonServersreject named servers in every session type. - Harden headless runs: for automated runs on code you did not write, the Claude Code documentation recommends
--setting-sources useror--bareso project settings and.mcp.jsonare not read, and--settings '{"disableAllHooks": true}'passed on the command line, because project settings take precedence over user settings. Note that--barestill applies the project'senvblock, so run such jobs in a disposable container without long-lived credentials. - Trust deliberately: open unfamiliar repositories in restricted or read-only modes, read what the trust dialog lists before accepting, and keep agent clients updated so fixes such as Cursor 1.3 and Amazon Q 1.69.0 are in place.
- Remove ambient credentials: no long-lived keys in shell profiles or
.envfiles on machines that run agents; use short-lived, scoped tokens and credential masking where the client supports it. See the Secrets Management Guide. - Isolate: run agents on untrusted code in dev containers or VMs with egress limited to required domains. See the AI Agent Sandboxing and Code Execution Guide.
- Plan rollback: if enforcement blocks legitimate team tooling, move that configuration into managed settings rather than disabling the check for the repository.
Small teams can get most of the value from CODEOWNERS, a Unicode linter and managed settings on laptops. Large organisations should add endpoint process-lineage detections, central MCP allowlists and a standard container image for headless agent jobs.
| Control | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | Other mapping |
|---|---|---|---|
| Review and approval of config changes | CM-3, CM-5 | PR.PS-04 | OWASP LLM01 Prompt Injection |
| Allowlisted MCP servers and hooks via managed settings | CM-7, CM-11 | PR.AA-05 | OWASP LLM06 Excessive Agency |
| Dependency and file provenance checks | SR-3, SR-11 | GV.SC-06 | OWASP LLM03 Supply Chain; ATT&CK T1195.001 |
| Endpoint and agent telemetry | SI-4, AU-12 | DE.CM-09 | ATT&CK T1059.004, T1552.001 |
| Least privilege for developer credentials | AC-6, IA-5 | PR.AA-05 | See the API Key Management Guide |
Lessons from incidents
- Auto-start is the failure: the Amazon Q case needed no prompt injection at all. A file in the repository root started processes that inherited AWS credentials. Ask of every agent client: what does it start when a folder is opened, and does it check trust first?
- Persistence moves into instruction files: TrapDoor wrote agent instruction files alongside Git hooks, shell hooks and scheduled tasks. Incident responders should now check agent config paths when cleaning a compromised developer machine.
- Agents with credentials amplify supply chain malware: in the Nx s1ngularity attack, a compromised build tool package ran AI CLIs already installed on developer machines, with flags that skip permission checks, to help search for credential files. Malicious code does not need its own capability when the agent already has it.
- Review is necessary but not sufficient: hidden Unicode defeated human review in pull requests until code hosts added warnings. Automate the check.
Practitioner checklist
- List every agent config and instruction file pattern used by your approved tools.
- Put those paths under CODEOWNERS and branch protection.
- Add a CI and pre-commit check for hidden and bidirectional Unicode and suspicious commands.
- Enforce MCP server and hook allowlists through managed or team settings.
- Run headless agent jobs on untrusted code with project settings disabled, inside disposable containers.
- Keep agent clients and language servers at versions that include trust fixes.
- Remove long-lived credentials from shells and workspaces on agent machines.
- Alert on agent clients spawning shells or network tools right after a folder is opened.
- Include agent config paths in developer endpoint incident response and clean-up.
Standards and references
- Anthropic: Claude Code Security
- Anthropic: Claude Code Configure Permissions (What runs before you trust a folder)
- Check Point Research: Cursor IDE MCPoison (CVE-2025-54136)
- Pillar Security: Rules File Backdoor
- Model Context Protocol: Security Best Practices (Local MCP Server Compromise)
- OWASP: Top 10 for LLM Applications 2025
- MITRE ATLAS: LLM Prompt Injection
- MITRE ATT&CK: Compromise Software Dependencies and Development Tools
Related NHI Mgmt Group resources: AI IDE and Coding Agent Security Guide · Claude Code Security Guide · Cursor Security Guide · AI Coding Agents Security Guide · Prompt Injection Guide