Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

code-simplifier — Claude Code skill: what it does, how to install

Reviews Rust code in RTK to remove over-engineering and needless allocations. It applies idiomatic simplifications without altering runtime behavior.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add rtk-ai/rtk --skill code-simplifier -a claude-code
Open on GitHub

What code-simplifier does

The skill inspects Rust source files in RTK using Read, Grep, Glob, and Edit. It replaces manual loops with iterator chains and turns nested match statements into Option and Result method chains. Redundant .clone() calls are pruned. It also simplifies string construction into direct .join() calls.

Specific project constraints remain untouched. The skill keeps LazyLock regex statics in place, preserves mandatory .context() annotations on the ? operator, and retains raw fallback commands. After edits, code is validated with cargo clippy and cargo test.

Because the rules enforce RTK architectural conventions, applying this skill to arbitrary Rust repositories will enforce unwanted error-handling patterns.

What it helps with

  • convert manual for loops into iterator chains
  • replace nested match blocks with Option and Result combinators
  • remove redundant string allocations and clones
  • simplify manual string push loops with .join()
  • flatten deep nesting using early returns

Example prompts for the agent

  • Make this Rust code idiomatic and simplify the loops
  • Review src/filter.rs for redundant allocations and over-engineering
  • Simplify nested match blocks in this function while keeping RTK constraints

How to install code-simplifier

1Skills CLI (Vercel)

npx skills add rtk-ai/rtk --skill code-simplifier -a claude-code

2Manually: put the files in place

~/.claude/skills/code-simplifier/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/code-simplifier/

From the same set4

The whole set →

Similar

update-implementation-plan official github Updates an existing implementation plan for new requirements, refactoring, package upgrades, or architecture changes. Use it when a plan needs actionable tasks and checks. GitHub Copilot 11,107installs review-and-refactor official github Reviews project code against local instructions and refactors parts that need changes. Use it before review or when cleaning up an existing codebase. GitHub Copilot 11,056installs github-triage code-yeongyu Reads every open issue and PR in a repo and writes evidence-backed reports. It never comments, merges or closes anything. Claude Code CX Codex Cursor +1 2,700installs cookbook-audit official anthropics A skill that audits Anthropic Cookbook notebooks against the style guide: checks structure, code quality, security, and learning objectives. Use it when writing or reviewing notebooks with examples. Claude Code CX Codex Cursor +1 776installs csharp-async official github This skill guides Copilot through C# async best practices and flags common mistakes. Use it when reviewing async methods, tasks, and public APIs. GitHub Copilot 10,883installs postgresql-table-design Seth Hobson Helps design and review PostgreSQL schemas with guidance on data types, keys, constraints, indexes, and table partitioning. Claude Code CX Codex Cursor 27,780installs improve-codebase-architecture Matt Pocock This skill scans a codebase for architectural friction, then builds a visual HTML report with refactoring candidates. Use it before a deeper architecture review. Claude Code 1,163,035installs tdd Matt Pocock Guides the red-green TDD loop: ensures tests are written first, keep them at public interfaces, and avoid coupling to implementation details. Claude Code 1,141,062installs

Questions about code-simplifier

How do I install code-simplifier in Claude Code?

Run npx skills add rtk-ai/rtk --skill code-simplifier -a claude-code in your terminal.

What does the code-simplifier skill do?

It inspects Rust code in RTK to spot verbose patterns, unnecessary allocations, and over-engineered logic, refactoring them into idiomatic Rust.

Which patterns does code-simplifier explicitly keep intact?

It preserves LazyLock regex statics, .context() calls on ? operators, fallback error handlers in Err arms, and #[cfg(test)] test modules.

Source text

SKILL.md · Apache-2.0
---
name: code-simplifier
description: Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior.
triggers:
  - "simplify"
  - "too verbose"
  - "over-engineered"
  - "refactor this"
  - "make this idiomatic"
allowed-tools:
  - Read
  - Grep
  - Glob
  - Edit
effort: low
tags: [rust, simplify, refactor, idioms, rtk]
---

# RTK Code Simplifier

Review and simplify Rust code in RTK while respecting the project's constraints.

## Constraints (never simplify away)

- `LazyLock` regex — cannot be moved inside functions even if "simpler"
- `.context()` on every `?` — verbose but mandatory
- Fallback to raw command — never remove even if it looks like dead code
- Exit code propagation — never simplify to `Ok(())`
- `#[cfg(test)] mod tests` — never remove test modules

## Simplification Patterns

### 1. Iterator chains over manual loops

```rust
// ❌ Verbose
let mut result = Vec::new();
for line in input.lines() {
    let trimmed = line.trim();
    if !trimmed.is_empty() && trimmed.starts_with("error") {
        result.push(trimmed.to_string());
    }
}

// ✅ Idiomatic
let result: Vec<String> = input.lines()
    .map(|l| l.trim())
    .filter(|l| !l.is_empty() && l.starts_with("error"))
    .map(str::to_string)
    .collect();
```

### 2. String building

```rust
// ❌ Verbose push loop
let mut out = String::new();
for (i, line) in lines.iter().enumerate() {
    out.push_str(line);
    if i < lines.len() - 1 {
        out.push('\n');
    }
}

// ✅ join
let out = lines.join("\n");
```

### 3. Option/Result chaining

```rust
// ❌ Nested match
let result = match maybe_value {
    Some(v) => match transform(v) {
        Ok(r) => r,
        Err(_) => default,
    },
    None => default,
};

// ✅ Chained
let result = maybe_value
    .and_then(|v| transform(v).ok())
    .unwrap_or(default);
```

### 4. Struct destructuring

```rust
// ❌ Repeated field access
fn process(args: &MyArgs) -> String {
    format!("{} {}", args.command, args.subcommand)
}

// ✅ Destructure
fn process(&MyArgs { ref command, ref subcommand, .. }: &MyArgs) -> String {
    format!("{} {}", command, subcommand)
}
```

### 5. Early returns over nesting

```rust
// ❌ Deeply nested
fn filter(input: &str) -> Option<String> {
    if !input.is_empty() {
        if let Some(line) = input.lines().next() {
            if line.starts_with("error") {
                return Some(line.to_string());
            }
        }
    }
    None
}

// ✅ Early return
fn filter(input: &str) -> Option<String> {
    if input.is_empty() { return None; }
    let line = input.lines().next()?;
    if !line.starts_with("error") { return None; }
    Some(line.to_string())
}
```

### 6. Avoid redundant clones

```rust
// ❌ Unnecessary clone
fn filter_output(input: &str) -> String {
    let s = input.to_string();  // Pointless clone
    s.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n")
}

// ✅ Work with &str
fn filter_output(input: &str) -> String {
    input.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n")
}
```

### 7. Use `if let` for single-variant match

```rust
// ❌ Full match for one variant
match output {
    Ok(s) => process(&s),
    Err(_) => {},
}

// ✅ if let (but still handle errors in RTK — don't silently drop)
if let Ok(s) = output {
    process(&s);
}
// Note: in RTK filters, always handle Err with eprintln! + fallback
```

## RTK-Specific Checks

Run these after simplification:

```bash
# Verify no regressions
cargo fmt --all && cargo clippy --all-targets && cargo test

# Verify no new regex in functions
grep -n "Regex::new" src/<file>.rs
# Fixed, reused patterns should be in `LazyLock<Regex>` statics

# Verify no new unwrap in production
grep -n "\.unwrap()" src/<file>.rs
# Should only appear inside #[cfg(test)] blocks
```

## What NOT to Simplify

- `static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(...).unwrap());` — the `.unwrap()` here is acceptable, it's init-time
- `.context("description")?` chains — verbose but required
- The fallback match arm `Err(e) => { eprintln!(...); raw_output }` — looks redundant but is the safety net
- `std::process::exit(code)` at end of run() — looks like it could be `Ok(())`but it isn't

© rtk-ai · Apache-2.0 · rtk-ai/rtk

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor