How to structure AGENTS.md files in a monorepo for better AI agent context
In a monorepo, a single root AGENTS.md file often either becomes too bloated or too generic to serve individual packages effectively. A hierarchical approach solves this by placing multiple smaller AGENTS.md files close to the code they describe, with the nearest file up the directory tree taking precedence when an agent edits a file. The root file should capture workspace-wide conventions, while package-level files handle only package-specific commands and rules. Shared rules should be defined once at the root and inherited by packages, which override only what genuinely differs, avoiding duplication and configuration drift. In practice, two levels — one root file plus one per top-level package — is sufficient for most monorepos, with OpenAI's main repo reportedly using around 88 such files as an example of larger-scale usage.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in