
RTK Code Simplifier
FreeStreamline your Rust code with idiomatic simplifications.
Free · Opens the source repo
What RTK Code Simplifier does
The RTK Code Simplifier is a specialized tool designed for developers working with Rust code in the RTK project. Its primary function is to review and simplify Rust code while adhering to specific project constraints. By detecting over-engineered patterns, unnecessary allocations, and verbose constructs, the tool applies idiomatic Rust practices without altering the intended behavior of the code. This ensures that the code remains efficient and maintainable, aligning with Rust's best practices.
The skill operates under a set of defined constraints that prevent it from simplifying certain constructs that are critical to the RTK project. For instance, it respects the requirement to use LazyLock regex patterns outside of functions and mandates the use of .context() on every ? operator, even if it appears verbose. This careful consideration of project-specific rules allows developers to enhance code quality without risking functionality or compliance with the project's coding standards.
Developers will find the RTK Code Simplifier particularly useful when refactoring existing codebases or when onboarding new team members who need guidance on idiomatic Rust practices. By streamlining code through various simplification patterns, such as replacing manual loops with iterator chains or optimizing string building, the tool helps maintain a clean and efficient codebase. It also includes post-simplification checks to ensure that no regressions are introduced, making it a reliable companion for Rust development in the RTK environment.
In summary, the RTK Code Simplifier is an essential tool for Rust developers looking to improve code readability and efficiency while adhering to the specific constraints of their project. Its focus on idiomatic practices and careful consideration of project rules makes it a valuable addition to any Rust development workflow.
When to use it
Use this tool when you want to refactor Rust code in the RTK project to follow idiomatic practices without changing its behavior.
When not to use it
This skill is not suitable for projects outside of RTK or for code that doesn't require adherence to the specified constraints.
What you can build with it
Refactoring Legacy Code
Use the RTK Code Simplifier to modernize and simplify legacy Rust code, making it more idiomatic and easier to maintain.
Onboarding New Developers
Leverage the tool to guide new team members in writing idiomatic Rust code while adhering to RTK's specific coding standards.
Code Review Process
Integrate the simplifier into your code review process to ensure that all contributions meet the project's idiomatic standards.
How to install RTK Code Simplifier
View source1. Install with the skills CLI
npx skills add rtk-ai/rtk/code-simplifier --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by rtk-aiRTK Code Simplifier
Review and simplify Rust code in RTK while respecting the project's constraints.
Constraints (never simplify away)
LazyLockregex — 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
// ❌ 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
// ❌ 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
// ❌ 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
// ❌ 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
// ❌ 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
// ❌ 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
// ❌ 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:
# 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 beOk(())but it isn't
Frequently asked questions about RTK Code Simplifier
Similar skills
React Composition Patterns
Streamline your React component architecture with proven patterns.
Pester Should Migration
Easily convert Pester v5 assertions to v6 syntax.
Radix to Base UI Migration
Seamlessly migrate React components from Radix UI to Base UI.
Migrate Next.js to Vinext
Seamlessly transition your Next.js projects to Vinext.
WinUI 3 Migration Guide
Streamline your UWP to WinUI 3 migration process.
Refactor
Enhance code maintainability without altering behavior.
