Omniscio

OmniscioGuidesCLAUDE.md examplesDjango

CLAUDE.md for a Django project

Two places cause most agent mistakes in Django: the settings module and the migration history. A session that has not been told which settings are live will edit the wrong file, and one that has not been told what a migration is will rewrite a file the database has already run.

The file below settles both, and each block is explained underneath. The examples hub has the same page for eight other stacks if you want the shape first.

Checked against Anthropic's Claude Code documentation and Django's own documentation on November 25, 2026. By the Omniscio team. Updated .

The file

This one describes a room-booking site with two apps, settings split by environment, and uv managing the Python side. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md beside manage.py.

# bookings

Django site for room bookings: one project, two apps.
Python and the virtualenv are managed by uv; settings live in config/settings/.

## Commands

uv run python manage.py runserver
uv run python manage.py makemigrations
uv run python manage.py migrate
uv run python manage.py test
uv run python manage.py test bookings.tests.test_refunds -v 2
uv run python manage.py check --deploy --settings=config.settings.prod

## Layout

- config/settings/   base.py, dev.py, prod.py; prod reads from the environment
- config/urls.py     the only root URLconf
- bookings/         models.py, services.py, views.py, urls.py, migrations/, tests/
- accounts/         the same shape
- templates/         project-wide templates only
- tests              live inside each app, named test_*.py

## Rules

- A model is the single source of truth for its data; no second copy of a field
  in a form, a serializer and a template.
- A view parses the request, calls a service and returns a response. Business
  rules live in services.py, not in a view or a model method.
- A migration and the model change it describes go in one commit.
- A migration that has been applied is history. Change the schema with a new
  migration; never rewrite one the database has already run.
- Read every makemigrations output before committing it; its detection is not
  perfect.
- Raw SQL is parameterized or it is a bug. The ORM is the default, not a style.
- DEBUG is never True outside a developer's machine.
- A new app goes into INSTALLED_APPS in the same change that creates it, then
  gets its first migration.

## Testing

- Anything that touches the database subclasses django.test.TestCase, not
  unittest.TestCase.
- A test file is named test*.py, or the runner never finds it.
- A test asserts the status code and the body a user receives, not an internal
  call.
- A bug fix starts with a test that fails before the fix.

## Traps

- startproject writes DEBUG = True. Shipping that file is the classic mistake.
- An app missing from INSTALLED_APPS has no visible models and no migrations.
- runserver is development only, and it will not notice a file you just added;
  restart it after creating a module.
- makemigrations can miss what you expect on a complex change. Read it.

That is 55 lines. Everything discoverable from a model or a settings file was left out on purpose.

Why each block is there

The opening lines

The opening says which project and which apps, because Django's own tutorial describes a project as a collection of configuration and apps, and an app as one thing that does something. It also names the settings module's home, because the docs say you have to tell Django which settings you are using, through DJANGO_SETTINGS_MODULE, and that manage.py is what sets it for you.

The command block

Anthropic asks for commands concrete enough to verify. The migration pair is the core of the block: Django's documentation describes makemigrations as packaging model changes into migration files, analogous to commits, and migrate as applying them, and describes migrations themselves as a version control system for the database schema.

Most projects never run the last command at all. Django's command reference describes check as inspecting the project for common problems, and --deploy as activating additional checks that only matter in a deployment, which is exactly the check an agent should run before it believes a settings change is safe. It needs the production environment variables exported, because the prod settings module reads them; a bare local run stops at import.

The layout

Six lines, each with a rule that the name does not carry. The one that matters is where tests live: inside the app, next to the code they exercise. Django's discovery walks the working directory and finds test*.py wherever it sits, so a parallel tree works too; it just drifts from the app.

Anthropic's size target keeps the list short. A full tree of a Django project is dozens of lines and adds nothing a session could not read.

The rules

The first two rules use Django's own vocabulary. The model documentation calls a model the single, definitive source of information about your data, and the view documentation says a view is a function that takes a web request and returns a web response. Putting the business rules in a service is this page's convention, and it follows from both: a rule that lives in a view is a rule a second view will reimplement.

The commit rule and the read-the-output rule are Django's, almost word for word. The documentation says to commit the migration and the models change as a single commit, and to read makemigrations output because it is not perfect and may not detect what you expect on a complex change.

The SQL and DEBUG rules are the two security sentences the documentation states most plainly: querysets are protected from injection because queries are parameterised, while raw SQL is yours to escape, with any user-controlled parameter bound; and a site must never go to production with DEBUG turned on.

Testing

Two test rules are documented behaviour, not preference. The testing overview says tests that rely on database access should subclass django.test.TestCase rather than unittest.TestCase, and that discovery finds tests in any file named test*.py under the working directory, which is why a differently named file is silently never run.

The third rule is the concreteness rule applied to tests: a status code and a body are checkable, an internal call is not.

Traps

DEBUG is the trap most likely to reach production. The settings reference says the file created by startproject sets DEBUG = True for convenience, which means the default project an agent scaffolds is one that must not ship.

The second trap is INSTALLED_APPS: the model documentation says that once models exist you add the module to INSTALLED_APPS, and that after adding an app you run migrate, optionally making its migrations first. The runserver line is the development server's own warning, that it reloads Python code but not files you add.

What was left out, and why

  • The settings themselves. They are in config/settings/ and change per environment. A copy here would be a second source of truth, and Anthropic warns that contradicting instructions may be followed arbitrarily.
  • The full model list. It changes with every feature, and a session reads a model faster than a stale summary of it.
  • Custom management commands. Django registers one for every module in a management/commands directory, so the list grows; naming five core commands is enough.
  • The deployment runbook. A multi-step procedure belongs in a skill, not in every session's context.
  • A local database URL or a superuser password. Those belong in CLAUDE.local.md or the environment, never in a committed file.
  • "Follow Django's conventions." Uncheckable in a diff, and paid for on every turn.

Adapting it

Four swaps cover the common variations.

  • One app. Collapse the layout and keep the rules. The migration and test habits do not change with the number of apps.
  • Django REST Framework. Replace the view line with your serializer and viewset vocabulary, and keep the rule that business rules do not live in a serializer.
  • pip or Poetry instead of uv. Replace every uv run python manage.py with python manage.py or poetry run python manage.py. Nothing else changes.
  • A single settings file. Replace the layout line with its path and keep the rule that DEBUG is never on in production. If you split settings later, the command line changes; nothing else does.

Then prove it loaded. /context all lists the memory files read at launch, and a file missing from that list is not being ignored; it is not being seen.

How this page was written

The guidance on what belongs in a CLAUDE.md, how long it should be and how Claude treats it was read from Anthropic's Claude Code memory documentation on November 25, 2026. The statements about Django were read from its own documentation, Django 6.1, the same day, and each one is linked in the Sources below.

The example file was written for this page and has not been run against a live project. Its rules are recommendations, and one of them is deliberately narrower than the documentation: Django does not forbid editing a migration by hand, while this page asks that an applied one be left alone.

Sources

Common questions

What should a CLAUDE.md for a Django project contain?

The manage.py commands you actually run, which settings module is live, where business rules live, and the traps: DEBUG left on by startproject, an app missing from INSTALLED_APPS, and makemigrations output that has to be read because its detection is not perfect. Anthropic's target is under 200 lines, so anything Claude can read from a model stays out.

Should the file list every manage.py command?

No, only the ones a change normally needs: runserver, makemigrations, migrate, test, and the check command. Django registers a management command for every Python module in a management/commands directory whose name does not begin with an underscore, so the list grows with the project and a long copy here is stale. Name the five and let the rest be discovered.

Can Claude edit a migration file?

Django's documentation says you should rarely, if ever, need to edit a migration by hand, but that writing one manually is possible. The practice this page recommends is narrower: read what makemigrations generated, and once a migration has been applied to a shared database, change the schema with a new migration rather than editing history.

Why are my new app's models invisible?

Because the app is not in INSTALLED_APPS. Django's model documentation says that once models are defined you must add the module to INSTALLED_APPS, and that after adding an app you should run migrate, optionally making its migrations first with makemigrations. Without the setting, Django does not see the app's models or its migrations.

Write CLAUDE.md once, and every agent reads it

Omniscio keeps your canonical CLAUDE.md or AGENTS.md mirrored to the filenames Codex, Gemini, Cursor and Copilot look for, and flags a copy that was edited outside it. Any model, any harness.

The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.