Cursor Agent can run directly in a Rust project with cursor-agent and is most useful when it can edit code, run cargo commands, and read their output. This guide covers a practical setup and loop for cargo workspaces: what to put in AGENTS.md, example prompts, where the agent does well, and how to verify every change. See Cursor Agent for the agent itself.
Why compile-time feedback makes Cursor Agent effective
Rust’s compiler and tooling give the agent a tight feedback loop that many other languages lack. The agent can propose a change, run cargo check or cargo test, read the exact error, and then adjust the code. Borrow checker errors are often cross-file: a lifetime or ownership issue at one call site may require editing a struct definition in another crate. Cursor Agent can follow those threads because it operates on the entire workspace and can run commands itself.
Unit tests are first-class in Rust, so the agent can add or update tests in the same step as the implementation. Clippy and rustfmt provide clear, mechanical standards that fit an agent’s deterministic loop. Workspaces with multiple crates also benefit from having build and lint commands written once; the agent can apply the same rules across src/ and crates/* without guessing.
Configuring AGENTS.md with cargo commands and Rust conventions
Start Cursor Agent in the project root with cursor-agent (see How to use Cursor CLI: a step-by-step guide if you need the basics). The agent reads AGENTS.md in the repo root or rule files under .cursor/rules; use one of them consistently. A Rust project benefits from a file that says exactly how to build, test, lint, and format, plus ownership/style rules.
Here is a realistic short AGENTS.md for a cargo workspace:
# AGENTS.md
## Project layout
- src/ contains the binary crate entry point.
- crates/* contains workspace members; do not edit generated Cargo.lock by hand.
## Commands
- Build: `cargo build --workspace --all-targets`
- Test: `cargo test --workspace`
- Lint: `cargo clippy --workspace --all-targets -- -D warnings`
- Format check: `cargo fmt --all -- --check`
## Rust rules
- Prefer `Result` and `Option`; avoid `unwrap`/`expect` in library crates.
- Keep `unsafe` blocks minimal and document why they are safe.
- Do not add dependencies without explaining the reason in your summary.
- If a borrow error appears, first try restructuring ownership rather than adding `clone()`.
- Run `cargo clippy` and `cargo fmt` before reporting success.
Keep rules specific; avoid general advice like “write idiomatic Rust”. Prefer constraints the agent can act on: no unwrap in library code, no new dependencies without justification, run clippy -D warnings.
Working in small, tested increments with cargo test and git diff
Plan first with the agent: ask it to list the files it intends to change and the order of changes. Then have it make small, testable edits rather than a large refactor in one prompt. After each step, tell it to run the relevant cargo command, and review the diff yourself before moving on.
These prompts are useful starting points for typical Rust work:
- “Add a
--output jsonflag to the CLI insrc/main.rsusing clap and serde_json; add a unit test for the flag parsing.” - “Fix the borrow checker error in
crates/core/src/parser.rsby restructuring ownership, do not addclone()unless necessary; explain why.” - “Refactor
Configinto a builder pattern and update all call sites, then runcargo test --workspace.” - “Add unit tests for
parse_headercovering an empty string, a malformed input, and a valid header with CRLF.” - “Run
cargo clippy --workspace --all-targets -- -D warningsand fix every warning; then runcargo fmt --alland commit.”
A reliable loop: ask for a diff summary first, instruct the agent to run tests, inspect git diff, run the tests once yourself, then commit. Keep each commit scoped to one change so a bad fix is easy to revert.
Strengths to lean on and pitfalls to review in Rust code
Cursor Agent is strong at mechanical, well-scoped Rust tasks: deriving common traits (Debug, Clone, Serialize, Deserialize), converting error enums to thiserror, adding serde structures, fixing straightforward compiler errors, writing unit tests for pure functions, and updating module paths after a file move. It also does a decent job at small refactors like replacing a tuple with a named struct or splitting a large impl block.
Watch it closely in these areas:
- Borrow checker workarounds: it may add
clone(),Rc, orArc<Mutex<_>>too quickly. Review each ownership change and ask for an explanation if the diff looks like it is dodging the real issue. - Cargo.toml edits: it may add a new dependency for something that std or an existing crate already covers. Check every dependency change and keep
cargo treeoutput in mind. - Feature flags and conditional compilation: incomplete
#[cfg]edits or workspace feature unification can produce surprising builds. Test both--all-featuresand--no-default-featuresafter such changes. - Unsafe code: any suggested
unsafeblock needs a safety comment and should be avoided if a safe alternative exists. Do not let the agent add unsafe code without explicit review. - Public API changes: if the workspace publishes crates, watch for accidental breaking changes in
pubsignatures; the agent may not realize semver impact.
Verification: treating cargo check, clippy, and fmt as required gates
For Rust, verification is explicit and should be part of every prompt. Use cargo check for fast compile feedback, cargo test for behavior, cargo clippy for lints, and cargo fmt --check for formatting. The agent can run these commands itself, but you should still review the diff and run the same commands after it reports success.
| Verification step | Command | What it catches |
|---|---|---|
| Fast compile | cargo check --workspace | Type errors, missing imports, borrow errors |
| Unit/integration tests | cargo test --workspace | Behavioral regressions |
| Lints | cargo clippy --workspace --all-targets -- -D warnings | Style/performance issues, needless clones |
| Format | cargo fmt --all -- --check | Inconsistent formatting |
If your workspace has feature flags, also ask the agent to run cargo test --workspace --all-features and cargo check --workspace --no-default-features. Review Cargo.toml and Cargo.lock diffs carefully; they often reveal unintended changes to the dependency graph. Use git diff --stat first and git diff on files you care about.
Parallel Rust agents with AgentVera and git worktrees
AgentVera is a desktop app that runs coding agents’ real command line tools side by side, each in its own terminal panel. For Rust workspaces, three features matter most: agents can work in separate git worktrees, so parallel changes to different crates never overwrite each other; automatic code review by a second model flags suspicious clone() calls or unsafe blocks and links findings to file:line; token budgets stop runaway cargo test retry loops while preserving the conversation for your next instruction. Checkpoints also let you roll back a bad borrow checker refactor in one click. See Best tools to run AI coding agents in parallel (2026).
Recommended workflow for daily Cursor Agent use on Rust
Cursor Agent works well on Rust when it gets precise, verifiable instructions and a consistent cargo loop. Put the commands and rules in AGENTS.md, keep changes small, watch for ownership shortcuts, and always run the test suite and clippy before merging. For parallel work, use worktrees and a review step so multiple agents can help without stepping on each other’s crates.