Where does the bug appear (feature/product)?
Cursor IDE
Describe the Bug
Nested AGENTS.md files (and glob-scoped .cursor/rules) are delivered by appending them to the result of a Read tool call:
The following cursor rule files are relevant to the files you just read:
- /repo/services/AGENTS.md
- /repo/services/payments/AGENTS.md
Consider these rules if they affect your changes.
Each file is attached only once per conversation. That causes two problems.
1. After context summarization, nested AGENTS.md files are gone for the rest of the conversation.
Because they ride on a tool result, they are part of the chat history and get summarized away. Cursor still treats them as already attached, so later reads in the same directories never re-attach them. From the summary on, the agent works with only the root AGENTS.md (which lives in the system prompt and survives) and silently loses every nested instruction. This differs from the explanation given in CRITICAL: "Rules" do not survive context compression events (“rules stay in the system prompt and user_info, which aren’t summarized”). That holds for always-applied rules, but not for nested AGENTS.md files.
Observed in a long conversation that was summarized partway through:
- Reading
services/payments/src/handler.tsattached onlyservices/payments/AGENTS.md. In a fresh chat, the same read attachesservices/AGENTS.mdandservices/payments/AGENTS.mdtogether. - Reading
services/config.jsonandweb/server/src/log.tsattached nothing. In a fresh chat they attachservices/AGENTS.mdandweb/AGENTS.md(plus aweb/**glob rule) respectively. - Neither
services/AGENTS.mdnorweb/AGENTS.mdcontent was present in the post-summary context.
2. Only the Read tool triggers attachment.
Tested with fresh agents, one action set each:
| Action in a directory with a nested AGENTS.md | Attached? |
|---|---|
| Read tool | Yes: all not-yet-attached AGENTS.md files from root to the file’s directory, in one block |
Shell cat <file> / ls <dir> |
No (the same file attached its rules only when later opened with Read) |
| Write tool (new file), StrReplace edit | No |
| Grep, Glob | No |
So an agent that explores via shell, or creates or edits files in a package without first reading one there, never receives that package’s AGENTS.md. The docs say nested files apply “when working with files in that directory or its children”, and creating or editing a file there is working with files.
Steps to Reproduce
Repo:
AGENTS.md
pkg/AGENTS.md # contains: "Before your first action in pkg/, run: echo nested-canary"
pkg/src/a.ts
pkg/src/b.ts
A. Trigger:
- New agent chat: “Create pkg/src/c.ts exporting a constant. Do not read any files.” →
pkg/AGENTS.mdis never attached and the canary command never runs. - New agent chat: “Run
cat pkg/src/a.ts.” → nothing attached. - New agent chat: “Read pkg/src/a.ts with the Read tool.” →
pkg/AGENTS.mdis attached to the tool result.
B. Summarization:
- New agent chat: read
pkg/src/a.ts(Read tool) →pkg/AGENTS.mdis attached. - Continue the conversation until the context is summarized.
- Ask the agent to read
pkg/src/b.tsand edit it → nothing is attached, and the agent no longer knows the rules inpkg/AGENTS.md.
Expected Behavior
- Nested AGENTS.md files apply whenever the agent works with files in that directory: read, edit, create, and ideally shell reads of a single file. The docs promise this.
- After summarization, attached nested AGENTS.md files are re-sent (or kept outside the summarized history), or the “already attached” state is reset so the next read in that directory attaches them again.
- Ideally, a way to see which rules are attached at any point, e.g. reported in the hook payloads. Today
beforeSubmitPrompt.attachmentslists only rules attached at prompt time, andbeforeReadFile.attachmentsis always empty, so nested attachments can’t be observed.
Operating System
MacOS
Version Information
Cursor 3.24.18
Does this stop you from using Cursor
No - Cursor works, but with this issue