3 python rules available
Three Claude rules match python: a substantive Python developer rule (FastAPI and data science), a short best-practices rule and a short data-pipeline rule. In Claude Code, a paths-scoped Python rule lets you require the configured checks without loading Python guidance into every session.
Claude Code loads persistent project instructions from CLAUDE.md files and from Markdown rules in .claude/rules/. Rules can be scoped to file paths with a paths frontmatter field, and CLAUDE.md can import other files with @path syntax. The rules in this directory are written as plain instruction prompts: in Claude Code, save them as CLAUDE.md or .claude/rules/ content; in Claude.ai or the Claude API, use the same text as project instructions or a system prompt instead.
.claude/rules/python.mdStarting point, not a tested configuration for your repository. Loaded when Claude Code works with files matching paths. Review the instructions, adapt the file paths and run your project's existing checks.
--- paths: - "**/*.py" --- # Python instructions for Claude Code ## Focus for this project - Run the existing tests before refactoring and again afterwards, and report both results. - Keep pandas operations vectorized; do not introduce row-wise apply or iterrows loops in hot paths without saying why. - Do not change public function signatures without listing the callers you updated. ## Python conventions - Read requires-python in pyproject.toml first. Use built-in generics such as list[str] (3.9+) and X | None unions (3.10+) only when the minimum version allows them at runtime. - Annotate public functions and keep Any out of new signatures. - Raise specific exception types and never use a bare except:. - Use the formatter, linter and type checker already configured in pyproject.toml instead of introducing new ones. ## Before you finish - Run the configured linter and type checker (for example ruff check . and mypy) and pytest -q and report the actual output. If you cannot run them, say so and list the exact commands instead of saying they pass. - Summarize which of the rules above affected the change. - You have shell access: run the checks yourself instead of asking the user to, unless a command needs credentials or would deploy.
Create your own Claude rules for Python and share with the community.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Imports with @path can nest up to four hops deep, according to the docs. Claude Code can read AGENTS.md as project instructions without extra configuration, but by default only when there is no CLAUDE.md in the working directory or above it. The docs list this behavior for version 2.1.277 and later and describe a setting (claude-md-and-agents-md) that loads both files. If you maintain AGENTS.md for other tools, you can also import it from CLAUDE.md with @AGENTS.md.
Documentation checked 2026-11-05: Claude Code docs: Manage Claude's memory
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
You ask Claude Code to refactor a data-cleaning function and want type hints compatible with the project's minimum Python version and tests run before and after.
Refactor clean_orders(df) in pipeline/clean.py to drop rows with a negative quantity and normalize the currency column.
Typed function signatures valid for requires-python, vectorized filtering, a pytest case covering negative quantities, and the real before/after pytest output.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Design efficient data pipelines