2 rust rules available
Two Claude rules match rust: a substantive Rust developer rule centred on ownership and a short general rule. Claude Code can run cargo itself, so the file requires real fmt, clippy and test output rather than a claim that the code compiles.
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/rust.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: - "**/*.rs" - "**/Cargo.toml" --- # Rust instructions for Claude Code ## Focus for this project - When fixing a borrow-checker error, explain which borrow conflicts before changing code. - Run cargo clippy and cargo test in the shell and paste the actual output. - Do not raise the crate's MSRV or edition to make a fix compile. ## Rust conventions - Read the edition and rust-version fields in Cargo.toml and stay within them; do not raise either without being asked. - Return Result from fallible functions and propagate with ?. No unwrap() or expect() outside tests, examples and documented invariants. - Borrow (&str, &[T]) in parameters where ownership is not needed, and avoid clone() added only to satisfy the borrow checker; explain any clone that remains. - Every unsafe block needs a // SAFETY: comment stating the invariant it relies on. ## Before you finish - Run cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test 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 Rust 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 fix a borrow-checker error and want an explanation of the ownership problem rather than an added clone().
cargo build fails with E0502 (cannot borrow as mutable because it is also borrowed as immutable) in src/cache.rs. Fix it.
An explanation of the overlapping borrows, a fix that narrows a borrow's scope or restructures the lookup (no gratuitous clone), and the real clippy and test output.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Generate idiomatic Rust code