2 min lesson
Scope an API validation instruction
Place one API instruction in a nested AGENTS.md, then test it inside and outside that directory.
Check your understanding
Complete the practice "Scope API validation with a nested AGENTS.md".
Outcome: The route test passes, only the expected files changed and the nested AGENTS.md is absent from the unrelated task's loaded instructions.
Scope API validation with a nested AGENTS.md
Directory instructions for every contributor
SayNew API route handlers keep skipping request validation. The instruction belongs to every contributor, but only under src/app/api.
DoChoose a nested AGENTS.md instead of a private User Rule or a repository-wide root instruction.
Type
src/app/api/AGENTS.md
Every route handler validates its request body with validate(schema, body) from src/server/validate.ts before any database call.SeeThe plain Markdown file is version-controlled. Cursor combines it with parent instructions when Agent works in src/app/api or its children.
DoStart a fresh Agent run that adds POST /api/feedback. Do not repeat the validation instruction.
SeeThe new handler calls validate(FeedbackSchema, body) before the insert, matching the nested instruction and its referenced helper.
DoRun the route test and inspect the changed files, then check a task outside src/app/api.
SeeThe route test passes, only the expected files changed and the nested AGENTS.md is absent from the unrelated task's loaded instructions.
Learn more
Optional practice
Test yourself on Scope an API validation instruction
QWhich result proves the durable instruction is in the right place?