rust-lean-refactor
Reorganize Elph Rust code to be lean, clean, and non-bloated: detect oversized files, functions, or modules and split them safely across existing crate/module…
by riipandi★ 34 GitHub stars
Install rust-lean-refactor in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Rust Lean Refactor
Language
Split by destination:
- In-chat responses, plans, summaries — follow the language the user is currently using (Indonesian, English, etc). Code, paths, identifiers, crate/lint names stay literal English.
- Any documentation edits written to files (
docs/**, permanent code comments) — always English, regardless of chat language.
Purpose
Make Rust code lean and readable through pure structural refactoring — splitting bloated files/functions/modules, isolating cohesive responsibilities, and deduplicating genuinely identical private logic — while preserving observable behavior, public API, error contracts, feature behavior, and platform behavior. Split is not delete: removing actual dead or legacy code follows a stricter, separate rule.
Relationship to rust-verify-harden: this skill owns structure (what lives where, how big things are); rust-verify-harden owns hardening (memory/deadlock/race/perf, quality gates). Don't duplicate the concurrency/memory audit here — if the user also wants that, run rust-verify-harden after this skill's structure settles, not interleaved with it.
Elph architecture baseline
Confirm the dependency direction before choosing a boundary:
elph (coding-agent app, CLI, TUI)
├── elph-agent (agent orchestration, sessions, tools)
│ └── elph-ai (LLM types, catalogs, provider adapters)
├── elph-tui (reusable iocraft components)
├── floppy (memory/storage)
└── rendown (terminal/Markdown rendering)
elph-ai and elph-agent are publishable libraries. Their crate roots are
preludes; domain APIs remain under documented modules. Do not flatten a module
or make an item public solely to make an integration test compile. Unit tests
for pub(crate) behavior belong beside the implementation.
Scope
- Default scope: the crate(s)/module(s) the user names, or the crate(s) touched by their last few messages. Do not silently expand to the whole workspace unless asked.
- Intra-module split (functions/types moved within the same crate) is the default operating mode — low risk, no
Cargo.tomlchanges. - Cross-crate split (moving code so it now lives in a different crate,
e.g.
elph-agent→elph-ai) is a bigger change: it touchesCargo.toml, may create new public surface, changes publish packaging, and risks a crate-level circular dependency. Flag it explicitly, propose the dependency/API diff, and get a go-ahead before executing.
Safety Rules
- No behavior change. Pure structural refactor: move, split, rename, dedupe, reorder. If a "clean" idea changes logic, output, or a public API contract, flag it separately instead of doing it here.
- Use repository wrappers for gates:
make fmt,make check,make lint, andmake test. Forward package selectors after--(for examplemake check -- -p elph-agent). UseSCCACHE_DISABLE=1only when the cache is unavailable and record it in the final report. - No new circular mod dependencies. After each split, confirm the new module graph is still acyclic — see Phase 4.3.
- Codegen/generated files are out of scope. Skip anything under a
generated/,*.gen.rs,build.rs-producedOUT_DIRoutput,bindings.rs,vendor/iocraft/,crates/elph-ai/models/**/*.json,schemas/, or files carrying a generated header. Use the owning generator ormake generate-modelsinstead of editing generated output. - Small, verifiable increments — one bloated unit at a time, re-verify before the next.
- Legacy/back-compat code is out of scope for silent deletion —
#[deprecated],_v1/_old/_legacysuffixes, compat shims, retired#[cfg(feature = ...)]paths. Splitting these out into their own module is fine; deleting them needs the same ask-before-remove checkpoint asrust-verify-hardenPhase 4. - Respect existing module conventions — mirror how the crate already organizes
mod.rs/file-per-module/pub(crate)boundaries rather than importing a generic style. - No unprompted new deps/tools. Use what's already available (
clippy,tokei,cargo-modules,rg,ast-grep). If a tool is absent, fall back towc -l,rg,cargo metadata, and manual inspection rather than installing it. - Do not destroy parallel work. Never use
git reset --hardor broadgit checkout --rollback commands. Preserve unrelated edits and ask when file ownership is unclear. - Git is opt-in: do not commit or push unless explicitly instructed.
- Cross-platform is part of behavior: inspect
#[cfg]branches and target-specific dependencies; do not move Unix-only helpers into code that must compile on Windows.
Workflow
Phase 1 — Baseline
- Confirm scope (crate/module) with the user's request; don't assume workspace-wide unless stated.
git status --shortandgit diff --stat; identify external or unrelated edits before planning.- Run baseline gates through
make
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the rust-lean-refactor skill do?
Reorganize Elph Rust code to be lean, clean, and non-bloated: detect oversized files, functions, or modules and split them safely across existing crate/module boundaries without changing behavior. Guards against new circular dependencies, public API drift, feature/target regressions, and generated-file churn, then verifies the repository's make check/lint/test gates. Use when user asks to clean up, declutter, slim down, de-bloat, restructure, or split up Rust code, or complains a file/module/function is "gemuk"/too big/doing too much. Pair with rust-verify-harden for the hardening pass after structure is settled.
How do I install the rust-lean-refactor skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the rust-lean-refactor skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…