Copy this file into the root of your project as CLAUDE.md.
CLAUDE.md
Project
A Python 3.12+ application. Dependencies managed by uv. Linting and formatting via ruff. Tests with pytest. Type-checked with mypy --strict.
Commands
uv sync— install dependenciesuv run <command>— run inside the project venvuv run pytestuv run pytest -k <pattern>uv run ruff check .uv run ruff format .uv run mypy <pkg>/
After any edit, run ruff check, mypy, and pytest. Do not declare work complete with a failing check.
Code style
- Type-annotate every function signature. No untyped
*args/**kwargs. - Use modern syntax:
list[str],dict[str, int],str | None. - Prefer
dataclass(frozen=True, slots=True)orpydantic.BaseModelfor structured data. Never bare dicts for domain objects. - Module layout: prefer flat packages with a clear
__init__.pythat exposes the public API. - Logging via
structlog(if available) orlogging— neverprint()in library code.
Stack rules
Dependencies
- All deps go in
pyproject.toml. Neverpip installad-hoc. - Pin major versions for runtime deps. Loose for dev deps.
- After adding a dep, run
uv syncand commituv.lock.
Testing
- pytest with
tmp_pathandmonkeypatchover manualos.environmanipulation. - Fixtures live in
conftest.pyat the appropriate scope. - Mark slow/integration tests with
@pytest.mark.slowso they can be excluded. - Use
pytest-asyncio(mode = "auto") for async code.
Errors
- Define domain-specific exceptions in
<pkg>/exceptions.py. Never raise bareException. - Never
except:without a type. Catch the narrowest exception. - Re-raise with
fromto preserve traceback context.
Before editing
- Read
pyproject.tomlto understand declared deps and entry points. - Look at sibling modules for the project's idioms.
- Run the test suite to know the baseline state before you change things.
Constraints
- No new dependency without a reason. Prefer stdlib.
- No
Any. If you can't type it, useobjectand narrow withisinstance. - No mutable default arguments.
- Don't introduce a new packaging tool —
uvis the standard here.