Wink Pings

AI Writing Rust Tends to Settle: A 500-Line Skill Takes 30 Checks from 24 to 29

An Agent Skill called BeautifulRust compresses five Rust specifications into about 500 lines, so agents such as Claude Code, Codex, and Cursor automatically follow the rules when writing Rust. In testing, it raised 30 checks from 24 passing to 29 passing, at the cost of about one-third more tokens.

Morgan compressed five Rust specifications into an approximately 500-line Agent Skill called BeautifulRust. It is installed in a coding agent's skills directory and loads automatically when a task involves Rust, cargo, crates, the borrow checker, clippy, or .rs files. The goal is straightforward: make the Rust that agents write more idiomatic, more robust, and easier to maintain.

BeautifulRust project banner

In the tweet, Morgan wrote that he wrote C for about ten years, then moved to Python, but always missed C a little. After discovering Rust, he liked Rust even more. Now that agents are starting to write a lot of code, his judgment is that writing better code matters even more. Code can be beautiful—at least to him.

What It Actually Is

The BeautifulRust repository is named BeautifulRust, and its core is skills/rust-best-practices/. It is compatible with Claude Code, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, and other agents that read the Agent Skills format. The guidance is distilled from five sources: the Google Rust Style Guide, the Rust API Guidelines, David Drysdale's Effective Rust, Rust Design Patterns, and Microsoft's Pragmatic Rust Guidelines. Each source has a summary in references/ that the agent can consult when needed. When sources conflict, the skill picks a side and explains why.

What It Changes

The repository provides a comparison using a semver parsing library. Without the skill, the agent generated code that ran: the Version fields were all public, the documentation had only one sentence about parsing a version string, and the example called unwrap() directly. With the skill installed, the same agent made the fields private, added # Errors documentation explaining failure modes such as empty strings, leading zeros in numbers, overflow, and invalid characters, and changed the example to a form that can be safely copied. The difference between the two pieces of code is not functionality; it is delivery quality.

/// 没有技能时
/// A semantic version. The fields are public for convenience.
pub struct Version {
    pub major: u64,
    pub minor: u64,
    pub patch: u64,
}
/// 有技能后
/// Equality, hashing, and ordering ignore build metadata.
pub struct Version {
    major: u64,
    minor: u64,
    patch: u64,
}
/// # Errors
/// Returns ParseVersionError if ...

The repository ran three tasks: one library API design, one application CLI, and one refactor of a messy module. Across 30 checks, it passed 24 without the skill and 29 with the skill. The cost is about one-third more tokens per task. This number is very real. It does not guarantee correctness every time, but it pushes down many common pitfalls.

Coverage

SKILL.md is about 500 lines and is divided into 13 sections: mindset, pre-delivery checklist, ownership and borrowing, types and API design, errors and panic, everyday idioms, concurrency and async, unsafe and FFI, crate/module dependencies, documentation and comments, testing, performance, and the final checklist. It does not teach the agent to produce works of art; it first lays out the baseline clearly: fmt, clippy with -D warnings, tests, and documentation. First, do not let unwrap() appear in documentation examples.

How to Install

One-line install; requires Node 22.20 or higher:

npx skills add morganlinton/BeautifulRust

Claude Code can be installed as a plugin:

claude plugin install beautiful-rust --marketplace morganlinton/BeautifulRust

Copilot, Gemini CLI, and manual copying also have corresponding commands. The project is on GitHub: BeautifulRust.

A Question in the Comments

Someone asked whether this skill only guides while editing in Claude Code or whether it also hooks into cargo's save and build flows. According to the project description, it loads when an agent handles a Rust task, and the installation method is to put it in the agent's skills directory. It is not a cargo plugin. This question is quite important, because prompt-layer rules and compiler checks are two different things. The former governs the generation process; the latter governs the result. Only when both sides are strict is the code robust.

When agents write code, it is easy to relax standards for code quality. It runs, after all. But once the amount of code grows, the quality floor becomes conspicuous. Morgan's approach is not complicated: compress standards that the industry has already written clearly into short documents that agents can actually read, so the agent takes a look before starting. BeautifulRust is not a panacea—even its own tests pass only 29/30. But it demonstrates one thing: setting rules for agents is more useful than scolding them afterward for writing bad code.

发布时间: 2026-10-25 17:41