The open source coding agent.
TypeScript
Explain usage of external references in AGENTS.md (#965)
Almir Sarajčić1f4de75348a4
diff --git a/packages/web/src/content/docs/docs/rules.mdx b/packages/web/src/content/docs/docs/rules.mdxindex 96b1b3938fe..aa5590bb5f4 100644--- a/packages/web/src/content/docs/docs/rules.mdx+++ b/packages/web/src/content/docs/docs/rules.mdx@@ -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.+:::