Skip to content

docs: add AGENTS.md with repo guidelines for LLMs - #912

Merged
ormsbee merged 4 commits into
openedx:mainfrom
ormsbee:claude-md-guidelines
Oct 30, 2026
Merged

ormsbee merged 4 commits into
openedx:mainfrom
ormsbee:claude-md-guidelines

Conversation

@ormsbee

@ormsbee ormsbee commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a CLAUDE.md at the repo root so that Claude Code sessions start with the repo's commands, architecture, and constraints already in context, instead of rediscovering them each time.

What it covers:

  • Commands: install, running the suite and single tests, the MySQL tox env CI uses, the quality gate breakdown, migrations, make upgrade, and the edx-lint-generated files that must not be hand-edited.
  • Commits and releases: Conventional Commits via commitlint, and the fact that semantic-release on main turns the commit type into a PyPI release.
  • Databases: SQLite/MySQL/PostgreSQL compatibility, MySQL as the primary deployment database at READ COMMITTED, a preference for database constraints over select_for_update() to catch races, and the existing per-vendor patterns (collation helpers, upsert branching, InnoDB index key limits, NULL and uniqueness, ordering).
  • Architecture: the import-linter layering of the top-level packages, the api.py / models_api.py / data.py contract, how applets work inside openedx_content and openedx_learning and what to touch when adding one, the backcompat/ shells, the publishing model (learning packages, entities and versions, drafts, containers, change logs and side effects), extensibility via 1:1 models, django-rules setup pitfalls, and the two coexisting test styles.

Everything was checked against the config files, ADRs, and READMEs rather than written from memory, and the documented commands were run to confirm they behave as described.

Notes

  • make pii_check currently fails on main because openedx_content.Draft and openedx_content.PublishableEntityVersion are annotated inline and listed in .annotation_safe_list.yml. That check isn't in the CI matrix, so CI stays green. Not addressed here; just noting it since the doc describes the annotation rule.
  • The db_collations dicts in openedx_django_lib.fields have no postgresql entry, so "case-insensitive" fields fall back to PostgreSQL's default case-sensitive collation. The doc records that as a known gap rather than papering over it.

🤖 Generated with Claude Code

Documents the commands, package layering, per-app API conventions,
applet structure, publishing model, database compatibility rules
(SQLite/MySQL/PostgreSQL, READ COMMITTED, constraints over locks),
and test conventions so that Claude Code sessions start with the
repo's architecture and constraints already in context.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ormsbee
ormsbee marked this pull request as ready for review October 28, 2026 20:41
The API layer is called from views, tasks, management commands,
migrations, and other apps, so it must not use get_object_or_404,
Http404, DRF imports, or request parameters. Also correct the
permissions note: tagging's API enforces none, but some CBE API
functions take a user and raise PermissionDenied themselves.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ormsbee

ormsbee commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Note to reviewers: the api.py layer should generally not be called from migrations (because the model state may have changed). I removed the mention of that in the text, but the commit message still has it. I'll get rid of it in the squashed commit.

@bradenmacdonald

Copy link
Copy Markdown
Contributor

Should we call it AGENTS.md so it will work with other tools/models as well?

Comment thread CLAUDE.md Outdated
Comment on lines +155 to +157
`openedx_catalog` additionally has an `isolated_apps` import-linter contract
(`test_utils/isolated_apps_contract.py`): code outside it may import only its `api`,
`models_api`, `data` and `tests` modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say that this should be extended to other apps? (not just openedx_catalog)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Added a note that we want to work towards this with all our apps. I should move the isolated apps contract elsewhere and have the other apps to use it, but I don't want to yak shave on this right now. I'm mostly just trying to get in something mostly reasonable to help reduce the friction with some CBE reviews.

@ormsbee

ormsbee commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Should we call it AGENTS.md so it will work with other tools/models as well?

Ah, good point. I'll do that.

ormsbee and others added 2 commits October 28, 2026 18:50
The guidelines are tool-agnostic, so publish them under the generic
AGENTS.md name that other coding agents read. Claude Code reads
AGENTS.md natively from v2.1.277 when no CLAUDE.md exists, but a
CLAUDE.md or CLAUDE.local.md anywhere up the tree shadows it, and
older sessions read only CLAUDE.md. A one-line CLAUDE.md that imports
AGENTS.md covers both cases.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
I don't want to start enforcing this just yet, as it's outside the scope
of this pull request. But a small note to say that we want to work
towards this pattern for all apps, and it's not just an
openedx_catalog-specific thing.
@ormsbee ormsbee changed the title docs: add CLAUDE.md with repo guidelines for Claude Code docs: add AGENTS.md with repo guidelines for LLMs Oct 29, 2026
@ormsbee

ormsbee commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@bradenmacdonald: updated with changes

Comment thread AGENTS.md
`pylintrc_tweaks` and run `edx_lint write pylintrc`; do not edit the generated files.
Likewise `constraint-dependencies` in `pyproject.toml` is overwritten by `make upgrade`;
repo-specific constraints go in `[tool.edx_lint].uv_constraints`.
- `pii_check` is not in the CI matrix, but every model needs either a `.. no_pii:` (or `.. pii:`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not blocking for this PR:) Is this just an oversight, or why do we not have pii_check in the CI matrix? I've actually been bitten by this before, when the .annotation_safe_list.yml for this repo and the one for openedx-platform got out of sync.

Comment thread AGENTS.md
Comment on lines +237 to +243
- Permissions use django-rules, always checked through `user.has_perm(...)` rather than by
calling a predicate directly, because openedx-platform swaps in org-aware rules via
`rules.set_perm` and a direct call skips them. Tagging's `api.py` enforces no permissions (its
views do); some CBE API functions take a `user` and raise Django's `PermissionDenied`
themselves. A consuming project needs `rules.apps.AutodiscoverRulesConfig` in `INSTALLED_APPS`
and `rules.permissions.ObjectPermissionBackend` in `AUTHENTICATION_BACKENDS`; without them every
non-superuser gets 403 with nothing in the logs, and testing as a superuser hides the problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a blocker:) Just noting that OEP 66 recommends bridgekeeper over django-rules, although bridgekeeper hasn't been updated in the last 5 years. I guess either one works.

@ormsbee
ormsbee merged commit 1af7362 into openedx:main Oct 30, 2026
7 checks passed
@ormsbee
ormsbee deleted the claude-md-guidelines branch October 30, 2026 02:24
@mgwozdz-unicon

Copy link
Copy Markdown
Contributor

Thanks for writing this up, Dave. Apologies for my slow response here. I read through it and it looked fine to me, so I don't have corrections. Since Unicon works from our own Claude Code config for this repo, I asked Claude to diff that config against AGENTS.md and list rules we rely on that AGENTS.md doesn't state yet. The list below is that output, lightly edited. Feel free to take or leave any of it.

Never silence a check to make it pass. # noqa, # pylint: disable, # type: ignore, and loosening .importlinter need an explicit human decision, not a green build. AGENTS.md lists the quality tools but doesn't say suppressions are off limits, and agents reach for them first when a linter complains.

Comments and docstrings. Comment why, not what, and no change narration ("updated X", "as requested"). Public functions, classes, and models get RST docstrings that describe the contract rather than the implementation. Treat a stale comment as a bug and fix or delete it in the same change. pydocstyle already enforces docstring shape on src, but nothing says what goes in them, and agents default to narration comments.

max_length is enforced in CI, not locally. SQLite ignores CharField.max_length, while MySQL 8's default sql_mode includes STRICT_TRANS_TABLES, so an over-long value errors there. Any value built from other fields and stored in a bounded column should have its inputs' maximum lengths compared against the column's. This is the same "passes on SQLite, fails in CI" class as the collation and ordering items already in the Databases section.

Smallest correct change. No unrequested abstractions, flexibility, or error handling for impossible cases. Don't refactor or reformat code the task doesn't touch, and don't extract shared code until three callers need it. This is generic agent hygiene, but in our experience it's the biggest single source of review churn on agent-written PRs.

Consumers and companion changes. A change here often does nothing until openedx-platform picks up a new release, and migrations actually run there, not in this repo. The PR should name the companion platform change when one is needed. The SIMPLE_HISTORY_DATE_INDEX note already hints at this, but the general rule isn't stated.

New model fields surface through generic code. An admin registration without an explicit fields list, a serializer using fields = "__all__", and model_to_dict all pick up a new field with nothing naming it. When adding a field, check each of those against what the change is supposed to expose. ReadOnlyModelAdmin covers part of the admin side already; serializers are not covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants