claudegoodies
Skill

code-simplifier

From rtk-ai

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

Facts

Repository
rtk-ai/rtk
Status
Actively maintained
Last commit
Declared tools

Source preview

The instructions Claude Code reads when this skill runs.

# RTK Code Simplifier

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

## Constraints (never simplify away)

- `lazy_static!` 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
View full source on GitHub →

Other skills