type-driven-design

type-driven-design is a skill for Claude Code, Codex from rewrite-rs/skills. It costs 82 tokens per session (1,246 once invoked), scanned A, original, BSD-3-Clause.

A way to design Rust types so invalid combinations of data cannot be created. It uses distinct types and enums to represent only valid states.

In plain words
What is it for?
Use it when structs contain conflicting flags, values need validation in many places, or an operation must follow a specific order.
Why use it?
It removes repeated checks and prevents bugs caused by impossible or incomplete states reaching the rest of the program.

Skill for Claude CodeCodex

Part of the rewrite-rs-skills plugin — 28 skills 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 skills/rewrite-rs/skills/type-driven-design
Any agent
npx skills add rewrite-rs/skills --skill type-driven-design
Clone the repo
git clone --depth 1 https://github.com/rewrite-rs/skills

Made for: Claude Code, Codex.

Or install rewrite-rs-skills, the plugin that ships this one along with the rest of its 28 skills.

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 type-driven-design

README.md
[![agentmods](https://agentmods.dev/badge/skills/rewrite-rs/skills/type-driven-design.svg)](https://agentmods.dev/skills/rewrite-rs/skills/type-driven-design)
Your own site
<a href="https://agentmods.dev/skills/rewrite-rs/skills/type-driven-design"><img src="https://agentmods.dev/badge/skills/rewrite-rs/skills/type-driven-design.svg" alt="Measured on agentmods" height="20"></a>
Per session 82 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,246 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.00082 $0.01246
Opus 5 $0.00041 $0.00623
Sonnet 5 $0.00016 $0.00249
Haiku 4.5 $0.00008 $0.00125

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

Security

Grade A, and why

type-driven-design 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.

skills/rust/type-driven-design/SKILL.md · 124 lines

How it starts

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

Type-Driven Design

A type is a promise about which states exist. This skill changes what the types allow — it is the only skill in the Rust bucket that restructures a domain model, and it does so with a stopping rule: encode an invariant in a type when violating it is a real bug class in this codebase, not when it is merely expressible. How a rejection is reported is /rust-errors; what a change to a published type costs is /rust-api-design.

The principle

A type that cannot represent the bad state removes the runtime check, the test for it, and the bug report about it. Ask of every struct: how many field combinations are constructible, and how many are valid? The gap between those two numbers is the surface where bugs live.

Enums over flag soup

Two booleans make four states; if only three are valid, the fourth is a latent bug:

// Four states, three valid: is_draft && is_published is nonsense.
struct Post {
    is_draft: bool,
    is_published: bool,
    published_at: Option<DateTime<Utc>>,
}

// Three states, three valid, and published_at cannot go missing.
enum Post {
    Draft { body: String },
    Scheduled { body: String, at: DateTime<Utc> },
    Published { body: String, at: DateTime<Utc> },
}

The same move covers the Option<T> pair smell: two Option fields where exactly one is always Some is an enum with two variants, and the impossible combination — both None — stops being constructible.

Parse, do not validate

A function that takes &str and checks it is a valid email address checks again at the next call site, and the next, because the type carries no proof. A function that takes Email — constructible only through Email::parse(&str) -> Result<Email, EmailError> — checks once at the boundary and never again. The type is the proof the check ran.

struct Email(String); // private field: the constructor is the only way in

impl Email {
    fn parse(input: &str) -> Result<Self, EmailError> {
        // the check, exactly once
    }
}

fn deliver(to: &Email) { /* no validation possible here — none needed */ }

Read the full file on GitHub · 124 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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 · 124 lines · 82 tokens per session scan A 995ddddd7b6b

Subscribe to this mod's changes

type-driven-design is a skill published in the GitHub repository rewrite-rs/skills (1 stars, last pushed 19d ago), licensed BSD-3-Clause. It adds 82 tokens to every session and 1,246 once invoked, about $0.0004 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.

Related

Other skills, from other repositories

design-patterns

Rust design patterns for RTK. Newtype, Builder, RAII, Trait Objects, State Machine. Applied to CLI filter modules. Use when designing new modules or refactoring existing ones.

rtk-ai/rtk · 42 tokens

tdd-rust

TDD workflow for RTK filter development. Red-Green-Refactor with Rust idioms. Real fixtures, token savings assertions, snapshot tests with insta. Auto-triggers on new filter implementation.

rtk-ai/rtk · 45 tokens

code-simplifier

Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior.

rtk-ai/rtk · 36 tokens

rtk-tdd

Enforces TDD (Red-Green-Refactor) for Rust development. Auto-triggers on implementation, testing, refactoring, and bug fixing tasks. Provides Rust-idiomatic testing patterns with anyhow/thiserror, cfg(test), and Arrange-Act-Assert workflow.

rtk-ai/rtk · 61 tokens

polars

High-performance DataFrame library for Python ETL, analytics, and pandas migration. Use for expression-based data manipulation with lazy query optimization, parallel execution, streaming out-of-core processing, Arrow interoperability, and optional GPU execution.

K-Dense-AI/scientific-agent-skills · 47 tokens

rust-engineer

Writes, reviews, and debugs idiomatic Rust code with memory safety and zero-cost abstractions. Implements ownership patterns, manages lifetimes, designs trait hierarchies, builds async applications with tokio, and structures error handling with Result/Option. Use when building Rust applications, solving ownership or…

Jeffallan/claude-skills · 120 tokens