Omniscio

OmniscioGuidesCLAUDE.md examplesPython

CLAUDE.md for a Python project

Python projects hide their conventions in three places a new reader has to find: the package manager, the layout, and whichever linter the team settled on. The file below writes all three down once, so a session does not have to guess from the first file it opens.

Every block is explained underneath it, with the reason it earns a line and the reason some obvious lines were left out. If you would rather start from the shape than from a stack, the examples hub compares this file with the Java, TypeScript and Go ones.

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

The file

This one describes an async FastAPI service with a SQL database. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md in the repository root, where it is committed and read by everyone on the team.

# orders-api

FastAPI service that owns orders, payments and refunds.
Python 3.15, dependencies and the virtualenv managed by uv.

## Commands

uv sync                                  # create .venv from uv.lock
uv run fastapi dev app/main.py           # dev server on :8000
uv run pytest                            # whole suite
uv run pytest tests/api/test_orders.py -k refund -x
uv run ruff check . && uv run ruff format .
uv run mypy --strict app
uv run alembic upgrade head

## Layout

- app/main.py       the FastAPI app; routers are mounted here and nowhere else
- app/api/          one router per resource; HTTP only
- app/services/     business rules; no FastAPI or SQLAlchemy imports
- app/models/       SQLAlchemy models
- app/schemas/      Pydantic request and response models
- app/errors.py     the domain exceptions
- migrations/       Alembic; append only
- tests/            mirrors app/

## Rules

- Type every function signature, including -> None.
- Anything that touches the network or the disk is async. Never call requests,
  time.sleep or a blocking open() inside a request; push a blocking call you
  cannot avoid to a threadpool.
- HTTPException is raised only in app/api/. Services raise the exceptions in
  app/errors.py and the handlers translate them.
- Dependencies arrive through FastAPI's Depends. No module-level clients.
- Never catch Exception. Catch the class you expect and re-raise with `from`.
- Money is Decimal. Never float, never a formatted string.
- Database access goes through a repository in app/services/, not in a router.

## Testing

- pytest only. One test file per module, named test_<module>.py.
- Build the app with the `client` fixture in tests/conftest.py. Never start a
  real server, never hit a real network.
- A bug fix starts with a test that fails before the fix.
- Use pytest.mark.parametrize for the same rule over many inputs.

## Traps

- uv.lock is generated. Run `uv lock`, never edit the file.
- Alembic autogenerate can miss index and constraint changes. Read the generated
  revision before committing it, and write the ones it skipped by hand.
- app/schemas/ is the public contract. Renaming a field there is an API change,
  not a refactor.

That is 54 lines. It is short because every line had to survive a question: could Claude find this out by reading the repository? If the answer was yes, the line is gone.

Why each block is there

The first two lines

We put the project's job and its toolchain in the opening lines because a session opening a file has to decide what kind of project this is. The version is there too: it decides which syntax is legal, and a session that guesses wrong writes code that does not run.

The command block

Anthropic's guidance is that build commands are exactly the kind of fact a CLAUDE.md exists to hold, and that they should be concrete enough to verify. uv sync and uv run pytest are checkable in a way that "set up the environment" is not.

The two uv commands are the whole install story here. uv writes a cross-platform lockfile called uv.lock, and its documentation says that before every uv run it verifies the lockfile is up to date with the project, so a stale environment is corrected rather than used.

The lint line runs both halves of ruff, which its own documentation describes as an extremely fast Python linter and code formatter. Naming both matters: a session that runs only the linter leaves the formatting for a reviewer to fix.

The test line gives both the whole suite and the narrowed form. The second is there because "run the tests" on a large suite is the instruction a session quietly skips, while -k refund -x is one it can actually run while it works.

The layout

The directory list is the part people over-write. It carries only the directories whose names do not explain themselves, plus the one rule that is invisible from the tree: app/services/ may not import FastAPI. Without that line a session will happily put a database call in a router because that is where it found one.

Anthropic's size guidance is what keeps this list honest. A tree of the whole repository is the fastest way to spend the 200-line budget on something Claude could have read for itself.

The rules

Each rule here is one a reviewer has already had to write in a pull request. That is the test for a rule: if nobody has ever flagged it, it is a preference, and a preference is what a later reader deletes.

The Depends rule points at a real mechanism rather than a style. FastAPI's documentation describes its dependency injection system as the way a path operation declares what it needs, which is why a module-level client is not just untidy but untestable: it cannot be swapped in a test fixture.

We put the Exception rule in because a bare catch is the shape a session reaches for when it wants a test to pass. Naming the class you expect, and re-raising with from, keeps the original traceback in the message a human reads later.

Testing

The naming rule is not arbitrary: pytest's documentation says it runs every file whose name follows the form test_*.py or *_test.py, so a file named anything else is silently never run. That is worth one line in a file an agent reads.

"Never start a real server, never hit a real network" is the test-side version of concrete. It tells a session what not to build, which is the failure mode: a test that passes on the author's machine because a service happened to be running.

Traps

The lockfile line is the highest-value sentence in the file. uv's documentation says uv.lock is managed by uv and should not be edited by hand, and an agent that does not know that will try to fix a dependency conflict by editing it.

The Alembic line and the schema line are the same kind of fact: a rule about this codebase that no amount of reading the code will reveal. Anthropic's test is whether a new teammate would need the same context to be productive, and both pass it.

What was left out, and why

  • A rule that only matters in one folder. That belongs in a path-scoped rule under .claude/rules/, which loads only when Claude touches a matching file.
  • The dependency list. It is in pyproject.toml, it changes weekly, and a copy in the CLAUDE.md goes stale the first time somebody runs uv add.
  • PEP 8 and the line length. ruff enforces whatever your configuration selects, style rules and line length among them, and a rule copied from that configuration is a second source of truth that can disagree with the first.
  • How to deploy. That is a multi-step procedure, and Anthropic's guidance is to put those in a skill rather than in context every session.
  • Personal hosts and test accounts. Those belong in CLAUDE.local.md, which stays out of git.
  • "Write clean, idiomatic Python." Nobody can check it, and it spends context on every turn.

Adapting it

Three swaps cover most Python repositories. Change these and keep everything else.

  • Django or another web framework. Replace the dev-server line with the one your framework ships, replace the layout with your apps, and replace the framework-specific rules with yours. The command block's install and test lines usually survive unchanged, because they belong to uv and pytest rather than to FastAPI.
  • Poetry or pip. Replace every uv command with the equivalent your tool uses, and rewrite the lockfile trap for the file that tool generates. The rest of the file does not care which tool installs the dependencies, only that one of them is named.
  • A library rather than a service. Drop the async rule, the HTTP rule and the FastAPI line, and add the one that matters for a library: what counts as a breaking change, and where the public surface lives.

Then prove it loaded before you trust it. /context all lists the memory files that were read at launch, and a file that is 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 uv, ruff, pytest and FastAPI were read from each tool's own documentation the same day, and every claim about them is quoted from those pages.

The example file was written for this page and has not been run against a live repository. It is a starting point whose every line you are expected to check against your own project, which is why the adaptation steps below are worth working through before you keep it.

Sources

Common questions

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

The commands you actually run (install, dev server, test, lint, type check), the directories that are not self-explanatory, the conventions a reviewer enforces, and the traps: the generated lockfile, the migration tool that misses index changes, the schema that is a public contract. Anthropic's target is under 200 lines, so anything Claude can read from pyproject.toml stays out.

Should the CLAUDE.md name a Python version?

Yes, one line is enough. The version decides which syntax and library features are available, and Claude will otherwise guess from the code it happens to read first. Put it next to the package manager, because the two together settle which install and run commands are real.

Does this file work for Django or FastAPI?

The skeleton does; three parts change. Replace the dev-server line, replace the layout with your apps or routers, and replace the request and response rules with your framework's. The rest of the command block, the testing block and the traps carry over unchanged.

Should I tell Claude to run ruff and mypy in the CLAUDE.md?

Name them in the command block so Claude knows the checks exist and how to run them, and keep the rules themselves in your tool configuration. A rule copied into the CLAUDE.md and also enforced by ruff is two sources of truth, and Anthropic warns that conflicting instructions may be followed arbitrarily.

One instructions file, every agent that reads one

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.