Repository navigation
Description
Is your feature request related to a problem? Please describe.
More and more contributors work on MONAI with an AI coding assistant at their side (Claude Code, Codex, Copilot agent mode, Cursor, Gemini CLI, Jules, Aider, ...). Today these tools arrive in the repository with no project context: they do not know that PRs target dev, that every commit needs a DCO sign-off, that ./runtests.sh --autofix is the formatter, that optional dependencies go through monai.utils.optional_import, that a new public API must be added to docs/source/*.rst, that a slow test is marked with skip_if_quick, or that a test module needing an optional dependency is listed in exclude_cases of tests/min_tests.py. They rediscover (or miss) these rules on every session, which shows up in review as avoidable churn.
AGENTS.md has become the de facto, tool-agnostic convention for this: a plain Markdown "README for agents" that most coding assistants read automatically, with the file closest to the edited code taking precedence. It complements the AI contribution policy merged in #9106 (from #8914): the policy says what is acceptable, AGENTS.md tells the tool how this codebase works, so that what a human ends up reviewing and signing off is closer to mergeable from the start.
Describe the solution you'd like
A small, layered set of AGENTS.md files: one root file that routes, plus a short leaf file in each subpackage that carries real, package-specific traps. Detail lives next to the code it describes.
1. Layout
AGENTS.md # root: overview, map, commands, repo-wide rules, routing table
monai/transforms/AGENTS.md
monai/networks/AGENTS.md
monai/data/AGENTS.md
monai/losses/AGENTS.md # losses and metrics could share one file if preferred
monai/metrics/AGENTS.md
monai/bundle/AGENTS.md
monai/apps/AGENTS.md
monai/auto3dseg/AGENTS.md
monai/engines/AGENTS.md # engines + handlers
monai/csrc/AGENTS.md # C++/CUDA extensions
tests/AGENTS.md
docs/AGENTS.md
Not every folder needs one. A leaf file earns its place only if it says something an agent would otherwise learn the hard way; a file that is just a directory listing should be dropped. Do not add files to build output, caches or tests/testing_data.
2. Root AGENTS.md: suggested sections
Keep it short (ideally under ~200 lines). Suggested skeleton:
# AGENTS.md
## Project overview
One paragraph: what MONAI is, who uses it, supported Python/PyTorch range (link to setup.cfg/pyproject, do not copy versions).
## Repository map
| Path | Purpose |
|------|---------|
| monai/transforms | array/dict transforms, lazy resampling, invertibility |
| monai/networks | nets, blocks, layers |
| ... one line per top-level folder ... |
## Where the detail lives
| File | Covers |
|------|--------|
| monai/transforms/AGENTS.md | ... |
| tests/AGENTS.md | test layout, min_tests, skip decorators |
| ... |
## Setup and commands
./runtests.sh --setup # dev deps + pre-commit hooks
./runtests.sh --autofix # format (ruff/isort/black as configured)
./runtests.sh --codeformat # check only
./runtests.sh --quick --unittests # fast local verification
python -m pytest tests/<area>/test_x.py -k <name> # single test
(every command listed here must be one you have actually run)
## Repo-wide conventions
- PRs target `dev`; every commit signed off (`git commit -s`), by the human author.
- Line length 120, Google-style docstrings, type hints, Apache 2.0 header on new files.
- Optional deps only via `monai.utils.optional_import`; never a hard import at module top.
- New public API: export it in the package `__init__.py` and add it to `docs/source/<area>.rst`.
- Deprecations go through `monai.utils.deprecated` / `deprecated_arg` with since/removed versions.
- Tests mirror the source tree under `tests/`.
## AI-assisted contributions
Link to the policy section of CONTRIBUTING.md (#9106). Do not restate it here.
## Do not
- edit generated files (`monai/_version.py`, versioneer output)
- commit data, weights or large binaries
- touch CI workflows unless that is the task3. Leaf files: what goes in them
Each leaf file contains only its own tree: a short module to purpose table, commands run from/for that area, conventions, and traps first. Examples of the kind of content that is worth writing (contributors should verify each one against the code before writing it down):
monai/transforms: array vs dictionary (*d) vsRand*variants and how they relate;MetaTensormust be preserved through a transform; lazy resampling andInvertibleTransformcontracts; randomness must go throughself.R/set_random_state, not the global RNG; a new transform needs its dict and random variants plus an entry indocs/source/transforms.rst(andtransforms_idx.rstif applicable).monai/networks: support for both 2D and 3D viaspatial_dims; TorchScript/ONNX export expectations; where shared blocks/layers live so nets do not reimplement them.monai/data: dataset caching classes and their persistence/hashing behaviour; image readers depend on optional backends (ITK, nibabel, pydicom...).monai/losses/monai/metrics: shape conventions (B, C, spatial...), one-hot /include_background/ reduction semantics,ignore_indexbehaviour.monai/bundle: config syntax (@,%,$,#), link todocs/source/config_syntax.mdand the bundle spec rather than repeating them.monai/csrc: how extensions are built (BUILD_MONAI), and that a pure-Python fallback is expected.tests: file naming,tests/min_tests.pyexclude_casesfor modules needing optional deps (not for slow tests, which useskip_if_quick), theskip_if_*/SkipIfNoModuledecorators intests/test_utils.py,--nettests that download data, how to run one file.docs: building the docs locally, that every new public symbol needs an rst entry.
4. Cross-tool compatibility
AGENTS.md is the single source of truth. For tools that still look for their own filename, prefer pointers over copies so nothing drifts:
- Claude Code: add a one-line
CLAUDE.mdcontaining@AGENTS.mdat the root (only if maintainers want it; discuss below). - GitHub Copilot: optionally
.github/copilot-instructions.mdpointing toAGENTS.md. - Gemini CLI / others: can be configured to read
AGENTS.md; no extra file needed.
Personal, machine-specific instructions (local paths, preferred models, etc.) belong in the user's own config (~/.claude/, CLAUDE.local.md gitignored, etc.), never in the repository.
5. Writing guidelines (please read before opening the PR)
- Write what the code cannot say for itself. Surprising defaults, load-bearing ordering, deprecated paths and what replaces them, optional dependencies that only fail at runtime. Skip generic advice ("write clean code") and anything a config file already declares.
- Every command must be one you ran. No aspirational targets. Copy from
runtests.sh -h, CI workflows andCONTRIBUTING.md. - Verify every fact against the code, and enumerate names/counts programmatically rather than from memory. A confidently wrong table is worse than no table.
- Link, do not duplicate.
CONTRIBUTING.mdstays the canonical human guide;AGENTS.mdlinks to its sections. Do not copy version pins or dependency lists. - Keep it short and imperative. These files are loaded into a model's context on every session; every line costs tokens for every contributor.
- No secrets, tokens, internal URLs or personal paths.
- Add a line to
CONTRIBUTING.mdtelling contributors thatAGENTS.mdexists and must be updated when a convention it describes changes (treat it like docs).
6. Suggested sequencing (each step can be its own PR)
- Root
AGENTS.md+ theCONTRIBUTING.mdpointer. Small and easy to review; good first PR. tests/AGENTS.mdandmonai/transforms/AGENTS.md(highest-traffic areas).- Remaining leaf files, one or a few per PR, so domain owners can review their area.
- (Optional) tool pointer files from section 4 once maintainers agree.
Contributors picking this up: please comment here with which step / package you are taking to avoid duplicate work.
Acceptance criteria
- Root
AGENTS.mdexists, follows the skeleton above, and every command in it runs on a freshdevcheckout. - Root file's routing table links to every leaf
AGENTS.md, and every link resolves. - Each leaf file has at least one trap genuinely specific to its package (not just a listing).
- No content duplicated from
CONTRIBUTING.mdor the AI contribution policy; links instead. -
CONTRIBUTING.mdmentionsAGENTS.mdand the expectation to keep it current. - Sanity check: open an assistant of your choice on the branch, ask it to "add a new dictionary transform with tests and docs" (or similar for your package), and confirm it follows the documented conventions (
devtarget, sign-off,optional_import, rst entry,skip_if_quick/min_tests). Mention the result in the PR description.
Describe alternatives you've considered
- Tool-specific files only (
CLAUDE.md,.cursorrules,.github/copilot-instructions.md): fragments the guidance per vendor and drifts.AGENTS.mdis supported by most tools and is vendor-neutral. - A single large root file: easier to start, but it grows into a wall of text loaded on every session, and package experts have no natural place to own their section.
- Relying on
CONTRIBUTING.mdalone: written for humans, long, and not automatically loaded by agents.
Additional context
- Spec and tool support list: https://agents.md/
- Related: AI Contribution Policy For MONAI #8914 (AI contribution policy) and Add Tool-Assisted Contribution Policy #9106 (policy added to CONTRIBUTING.md).
Open questions for maintainers:
- Should a
CLAUDE.md/.github/copilot-instructions.mdpointer be committed, or shouldAGENTS.mdbe the only file? - Should losses and metrics (and engines and handlers) share leaf files?
- Should a lightweight CI check verify that the links in the routing table resolve?
This is a good first issue: it requires reading the codebase and CONTRIBUTING.md carefully but no changes to library code.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
arxh80 commentedon Oct 20, 2026
I'd like to take this. Plan: add a root-level
AGENTS.mdsummarizing the rules an AI assistant needs on every session — PRs targetdev, every commit needs DCO sign-off,./runtests.sh --autofixis the formatter, optional deps go throughmonai.utils.optional_import, new public API needs adocs/source/*.rstentry, slow tests go intests/min_tests.py. Will cross-reference the AI contribution policy from #9106 rather than duplicate it. Can follow up with nestedAGENTS.mdfiles for subdirectories in a later PR if that's wanted — happy to scope this one narrower or wider based on steer.ericspod commentedon Oct 23, 2026
We should also update the Coderabbit file to include new information, more specific instructions, and to check that changes to the code are reflected in the agent files that we're adding. This will keep things in line with the instructions that we give LLMs.
Add root-level AGENTS.md for AI coding assistants
luoli0621 commentedon Oct 27, 2026
I'd like to work on this
Add root-level AGENTS.md for AI coding assistants (#9212)
arxh80 commentedon Nov 4, 2026
Thanks for assigning me @garciadias. The root
AGENTS.md(step 1) landed in #9212. The leaf files are already in flight in #9200 (transforms, tests) and #9221 (every package, plus.coderabbit.yaml), so I don't want to duplicate them.Two pieces of the issue aren't on
devyet and I could take either:CONTRIBUTING.mdline pointing contributors atAGENTS.mdand asking them to keep it current (an acceptance item; docs: add AGENTS.md for the repository, monai/transforms and tests #9200 and Add AGENTS.md files to guide AI coding assistants #9221 both include a version of it, so it may be simplest to land it on its own).AGENTS.mdout of date.Which would be most useful? I'm also happy to review the open leaf-file PRs against the code instead.
(Drafted with AI assistance, per the tool-assisted contribution policy.)