We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Rule Precedence

In a large project, you might store agent rules in several places:

  • A repo-root AGENTS.md
  • A nested AGENTS.md in a subdirectory for a specific package
  • A global ~/.config/opencode/AGENTS.md on your machine

Those rules are all combined into your agent's context window. OpenCode doesn't throw out one set of rules just because another exists.

Nested AGENTS.md Files

You can put AGENTS.md files in subdirectories within your project, and they'll be loaded dynamically when the agent reads files in that directory. Say you have a monorepo with the following rules files:

AGENTS.md               # root-level rules
packages/api/AGENTS.md  # API-specific rules
packages/web/AGENTS.md  # web-specific rules

The root AGENTS.md is always part of the initial instructions, but OpenCode only loads packages/api/AGENTS.md once the agent successfully reads a file or lists a directory inside packages/api/. It then adds those rules to the session once and keeps them for the rest of the conversation.

We have a monorepo at Boot.dev, and we use nested AGENTS.md files for our frontend, backend, and course content directories. No sense injecting a bunch of frontend-specific rules into context when a session only cares about backend code.

Assignment

Give OpenCode parser-specific instructions.

    • Use one method per grammar rule
    • Make syntax errors describe what token was found

Tell OpenCode to run and submit the CLI tests from the project root.