AGENTS.md templates / Rust

AGENTS.md template for Rust

A ready AGENTS.md for a Rust project. It gives coding agents the Cargo commands that prove a change is sound and the shortcuts they take to get past the compiler.

Updated 3 December 2026 · 44 lines · 1.8 KB
AGENTS.md
# AGENTS.md

A Rust application built with Cargo on the stable toolchain.

## Commands

- `cargo check`: fast compile check while working
- `cargo test`: run unit, integration and doc tests
- `cargo clippy --all-targets -- -D warnings`: lint. Warnings fail
- `cargo fmt`: format
- `cargo run`: run the binary

## Project structure

- `src/main.rs`: binary entry point. Argument parsing and wiring only
- `src/lib.rs`: the crate's public surface
- `src/<module>.rs`: one module per area
- `tests/`: integration tests
- `Cargo.toml`: dependencies and features. Ask before changing

## Rules for agents

- No `.unwrap()` or `.expect()` outside tests. Return a `Result` and propagate with `?`.
- Do not add `.clone()`, `Rc` or `Arc<Mutex<...>>` only to satisfy the borrow checker. Restructure the code or ask.
- No `unsafe` and no `#[allow(...)]` without asking. Fix what Clippy reports.
- Prefer the standard library. Ask before adding a crate.

## Conventions

### Rust

- Reach for `Result<T, E>` over panics. `?` for propagation, `thiserror` for library errors, `anyhow` for applications.
- Derive `Debug`, `Clone`, `PartialEq` by default on data structs; add `Serialize`/`Deserialize` when they hit a boundary.
- Lifetimes: name them when they're load-bearing (`'a`, `'input`), elide when obvious.
- Prefer iterators over index-based loops. Collect lazily.
- Clippy-clean. Treat clippy warnings as errors in CI.

## Guardrails

- Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it.
- Do not invent dependencies. If a package is not already in the manifest, confirm before adding it.
- When a command fails, read the actual error. Do not retry blindly or bypass with `--force`.
- Prefer editing existing files over creating new ones.
- Run the tests and the linter before saying a task is done, and say what you ran.

The commands and folders are the common defaults for Rust. Change them to match your project before you commit the file: an agent will run exactly what is written here.

Make it yours in the generator Add your database, test runner and other tools, pick your coding style, and get matching CLAUDE.md, Cursor and Copilot files. Free, runs in your browser. Already have instruction files? Context Doctor scans your repo and shows which files each coding tool is silently not loading. $19.

How to use it

Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:

ToolWhat to do
Claude CodeReads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line.
CursorReads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there.
CodexReads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them.
GitHub CopilotReads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot.

Details and sources: the AGENTS.md compatibility matrix.

What agents get wrong in Rust projects

These are the reasons the “Rules for agents” section says what it says.

.unwrap() everywhere

It is the fastest way to make a type error go away, so agents use it on every Result and Option. Each one is a panic waiting for the wrong input.

Cloning past the borrow checker

When a borrow fails, agents add .clone() or wrap the value in Arc<Mutex<...>> until it compiles. The program then copies data it never needed to copy.

Silencing lints

Agents add #[allow(...)] or _ prefixes instead of fixing what Clippy found. The template says to fix the cause.

Adding a crate for a small job

A new dependency for something ten lines of standard library would do adds compile time and something else to audit.

Questions

Where does AGENTS.md go in a Rust project?

In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.

Does Claude Code read AGENTS.md?

Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.

How long should the file be?

Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.

Does this work for a workspace with several crates?

Yes. List each crate and what it is for in the Project structure section, and add --workspace to the test and Clippy commands so the agent checks everything it may have broken.

Templates for other stacks

Next.jsReactNode.js and TypeScriptExpressPythonFastAPIDjangoGoRuby on RailsLaravelVueSvelteKitAstroNestJSFastifyHonoFlaskElectronSupabase