rust-harden

rust-harden is a command for coding agents from mathisk2095/jko-claude-plugins. It costs 34 tokens per session (797 once invoked), scanned A, original, MIT.

A defensive review pass for Rust code that replaces avoidable crashes with error handling, documents unsafe code, checks arithmetic overflow, and validates input at boundaries.

In plain words
What is it for?
Use it to harden a Rust application or library by finding panic-prone code, undocumented unsafe blocks, unchecked arithmetic, and unvalidated inputs.
Why use it?
It helps reduce failures that might otherwise appear only when the program is running in production.

Command

Part of the rust plugin — 1 skill, 5 commands shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/mathisk2095/jko-claude-plugins/rust-harden
Clone the repo
git clone --depth 1 https://github.com/mathisk2095/jko-claude-plugins

Or install rust, the plugin that ships this one along with the rest of its 1 skill, 5 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rust-harden

README.md
[![agentmods](https://agentmods.dev/badge/commands/mathisk2095/jko-claude-plugins/rust-harden.svg)](https://agentmods.dev/commands/mathisk2095/jko-claude-plugins/rust-harden)
Your own site
<a href="https://agentmods.dev/commands/mathisk2095/jko-claude-plugins/rust-harden"><img src="https://agentmods.dev/badge/commands/mathisk2095/jko-claude-plugins/rust-harden.svg" alt="Measured on agentmods" height="20"></a>
Per session 34 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 797 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00034 $0.00797
Opus 5 $0.00017 $0.00398
Sonnet 5 $0.00007 $0.00159
Haiku 4.5 $0.00003 $0.00080

Measured 4d ago against content hash bc1483dfda5b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rust-harden scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/rust/commands/rust-harden.md · 91 lines

How it starts

The opening of the file, as written. The whole thing — 91 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rust Harden

Systematically harden the target Rust code against production failures. This is the defensive pass — every change reduces crash risk.

Preparation

  1. Find the workspace root: run cargo locate-project --workspace --message-format plain 2>/dev/null | xargs dirname.
  2. Identify the target: use the target argument, or default to the workspace's src/.
  3. Determine if this is a library or application crate (check for lib.rs vs main.rs).

Hardening Steps

Execute these in order. For each finding, make the fix directly — don't just report it.

Step 1: Eliminate Panic Sources

Run in the shell:

rg --type rust '\.(unwrap|expect)\(' src/ --glob '!*test*' -n

For each match:

  • If the unwrap is on a Result: replace with ? and add .context("description") if anyhow is available
  • If the unwrap is on an Option: replace with .ok_or_else(|| Error::...) then ?
  • If it's genuinely an invariant (e.g., after a length check): change to .expect("reason: invariant X holds because Y") with a clear explanation

Step 2: Document Unsafe Blocks

Run in the shell:

rg --type rust -B1 'unsafe \{' src/ -n | head -50

For each unsafe block without a preceding // SAFETY: comment, add one explaining:

  • What invariant is being upheld
  • Why it is safe in this context
  • Under what conditions it would become unsound

Step 3: Check Overflow Protection

Read Cargo.toml and check if [profile.release] has overflow-checks = true. If not, add it:

[profile.release]
overflow-checks = true

Evidence: CVE-2018-1000810 (std str::repeat) — silent integer overflow in release build. Debug builds panic, release builds silently wrap.

Step 4: Replace Indexing with Safe Access

Run in the shell:

rg --type rust '\[\w+\]' src/ --glob '!*test*' -n | head -30

For array/slice indexing x[i] in non-test code, evaluate whether .get(i) with proper error handling is safer. Slice indexing is potentially the main source of panics in non-trivial Rust programs.

Read the full file on GitHub · 91 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 91 lines · 34 tokens per session scan A bc1483dfda5b

Subscribe to this mod's changes

rust-harden is a command published in the GitHub repository mathisk2095/jko-claude-plugins (3 stars, last pushed 6d ago), licensed MIT. It adds 34 tokens to every session and 797 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.