TIL : one AGENTS.md per subdirectory replaces repeated instructions
workflowcontext
OpenCode (and most agents) reads CLAUDE.md or AGENTS.md files
by walking up the directory tree from the active file. A file at src/Service/AGENTS.md
is read on top of the root file when the agent works in that directory.
myproject/
├── AGENTS.md ← project-wide conventions
├── src/
│ ├── Service/
│ │ └── AGENTS.md ← Symfony service-specific conventions
│ └── ApiResource/
│ └── AGENTS.md ← API Platform conventions
└── tests/
└── AGENTS.md ← PHPUnit test conventions
# src/Service/AGENTS.md
- Services are final by default
- Constructor injection only (no setter injection)
- No business logic in the constructor
- Public methods over 20 lines should be split
In practice, this avoids repeating each layer’s conventions in every prompt. The agent knows them as soon as it opens a file in that directory.
Further reading