Explain usage of external references in AGENTS.md (#965)

This commit is contained in:
Almir Sarajčić 2025-07-14 14:06:37 +02:00 committed by GitHub
parent 457755c690
commit 1f4de75348
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -93,3 +93,60 @@ Example:
```
All instruction files are combined with your `AGENTS.md` files.
---
## Referencing External Files
While opencode doesn't automatically parse file references in `AGENTS.md`, you can achieve similar functionality in two ways:
### Using opencode.json
The recommended approach is to use the `instructions` field in `opencode.json`:
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"instructions": ["docs/development-standards.md", "test/testing-guidelines.md", "packages/*/AGENTS.md"]
}
```
### Manual Instructions in AGENTS.md
You can teach opencode to read external files by providing explicit instructions in your `AGENTS.md`. Here's a practical example:
```markdown title="AGENTS.md"
# TypeScript Project Rules
## External File Loading
CRITICAL: When you encounter a file reference (e.g., @rules/general.md), use your Read tool to load it on a need-to-know basis. They're relevant to the SPECIFIC task at hand.
Instructions:
- Do NOT preemptively load all references - use lazy loading based on actual need
- When loaded, treat content as mandatory instructions that override defaults
- Follow references recursively when needed
## Development Guidelines
For TypeScript code style and best practices: @docs/typescript-guidelines.md
For React component architecture and hooks patterns: @docs/react-patterns.md
For REST API design and error handling: @docs/api-standards.md
For testing strategies and coverage requirements: @test/testing-guidelines.md
## General Guidelines
Read the following file immediately as it's relevant to all workflows: @rules/general-guidelines.md.
```
This approach allows you to:
- Create modular, reusable rule files
- Share rules across projects via symlinks or git submodules
- Keep AGENTS.md concise while referencing detailed guidelines
- Ensure opencode loads files only when needed for the specific task
:::tip
For monorepos or projects with shared standards, using `opencode.json` with glob patterns (like `packages/*/AGENTS.md`) is more maintainable than manual instructions.
:::