/code-refiner
Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Targets complexity, anti-patterns, readability debt. Triggers on: "simplify this code", "refactor for clarity", "reduce complexity", "make this more readable", "tech debt cleanup",
$ npx -y skills add Mathews-Tom/armory --skill code-refiner --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/code-refiner
Context preview
The summary Claude sees to decide when to auto-load this skill.
Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Targets complexity, anti-patterns, readability debt. Triggers on: "simplify this code", "refactor for clarity", "reduce complexity", "make this more readable", "tech debt cleanup",
SKILL.md
code-refiner.SKILL.mdname: code-refiner
description: 'Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Targets complexity, anti-patterns, readability debt. Triggers on: "simplify this code", "refactor for clarity", "reduce complexity", "make this more readable", "tech debt cleanup", "too much nesting".'
metadata:
version: 1.1.1
category: review
tags: [refactoring, code-quality, simplification, readability]
difficulty: intermediate
phase: review
Code Refiner
A structured, multi-pass code refinement skill that transforms complex, verbose, or tangled code into clean, idiomatic, maintainable implementations — without changing what the code does.
Philosophy
The goal is **not** fewer lines. The goal is code that a tired engineer at 2am can read, understand, and safely modify. Every change must pass three tests:
1. **Behavioral equivalence** — identical inputs produce identical outputs, side effects, and errors 2. **Cognitive load reduction** — a reader unfamiliar with the code understands it faster after the change 3. **Maintenance leverage** — the change makes future modifications easier, not harder
When clarity and brevity conflict, clarity wins. When idiom and explicitness conflict, consider the team's experience level. When DRY and locality conflict, prefer locality for code read more than modified.
Prerequisites
- **git** — used in Phase 1 for scope detection (`git diff`) when the user doesn't specify target files
- **Python 3.10+** — required to run `scripts/complexity_report.py` for quantitative complexity metrics
Workflow
Follow this sequence. Each phase builds on the previous one. Do not skip phases, but adapt depth to the scope of the request (a single function gets a lighter pass than a full module).
Phase 1: Reconnaissance
Before touching anything, build a mental model:
1. **Identify scope** — What files/functions are in play? If the user hasn't specified, check recent git modifications: `git diff --name-only HEAD~5` or `git diff --staged --name-only` 2. **Detect language and ecosystem** — Read file extensions, imports, config files (package.json, pyproject.toml, go.mod, Cargo.toml). Load the appropriate language reference from `references/` if needed for idiom-specific guidance 3. **Read project conventions** — Check for CLAUDE.md, .editorconfig, linter configs (eslint, ruff, golangci-lint, clippy). These override generic idiom preferences 4. **Understand test coverage** — Locate test files. If tests exist, note the test runner so you can verify behavioral equivalence after changes 5. **Baseline complexity snapshot** — For each target function/method, mentally note:
- Nesting depth (max indentation levels)
- Number of branches (if/else/match/switch arms)
- Number of early returns vs single-exit
- Parameter count
- Lines of code
- Number of responsibilities (does it do more than one thing?)
Phase 2: Structural Analysis
Identify what's actually wrong before reaching for solutions. Categorize issues by severity:
**Critical** (always fix):
- Dead code (unreachable branches, unused variables/imports)
- Redundant operations (double-checking the same condition, re-computing cached values)
- Logic that can be replaced by a stdlib/language built-in
- Mutation of shared state that could be avoided
**High** (fix unless there's a clear reason not to):
- Functions with >3 levels of nesting
- Functions with >5 parameters
- God functions (>40 lines or >3 responsibilities)
- Repeated code blocks (3+ occurrences of similar logic)
- Inverted or confusing boolean logic
- Stringly-typed enumerations
**Medium** (fix when it improves clarity without adding risk):
- Unclear variable/function names
- Missing or misleading type annotations
- Unnecessary intermediate variables
- Over-abstraction (wrappers that add no value)
- Comments that restate the code instead of explaining _why_
**Low** (fix only in a dedicated cleanup pass):
- Inconsistent formatting (defer to linter)
- Import ordering
- Trailing whitespace, line length
Phase 3: Refactoring Execution
Apply changes using these tactics, ordered by impact-to-risk ratio:
3a. Eliminate Dead Weight
Remove before restructuring. Less code = less to think about.
- Delete unused imports, variables, functions
- Remove unreachable branches (but verify they're truly unreachable)
- Strip comments that restate the obvious (keep comments that explain _why_)
- Remove no-op wrapper functions that just forward calls
3b. Flatten Structure
Reduce nesting and cognitive load:
- **Guard clauses**: Convert deep `if` nesting to early returns
- **Extract conditions**: Name complex boolean expressions (`is_valid_order = ...`)
- **Decompose loops**: If a loop does filter + transform + accumulate, break it apart
(or use language-appropriate constructs: list comprehensions, iterators, streams)
- **Invert conditionals**: When the `else` branch is the "happy path", flip it
3c. Consolidate and Name
Make the code's intent visible:
- **Extract functions** for repeated logic or distinct responsibilities
- Name by _what it accomplishes_, not _how it works_
- Functions should do one thing at one level of abstraction
- **Replace magic values** with named constants
- **Rename for intent**: `data` → `user_records`, `process` → `validate_and_enqueue`
- **Group related parameters** into a config/options struct when count > 3
3d. Leverage Language Idioms
Apply language-specific patterns (consult `references/<language>.md` for details):
- Python: comprehensions, context managers, dataclasses, structural pattern matching
- Go: table-driven tests, error wrapping, functional options, interface satisfaction
- TypeScript: discriminated unions, branded types, const assertions, satisfies
- Rust: iterator chains, `?` operator, From/Into, newtype pattern
3e. Tighten Types
Types are documentation that the compiler checks:
- Add return
Read more
name: code-refiner description: 'Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Targets complexity, anti-patterns, readability debt. Triggers on: "simplify this code", "refactor for clarity", "reduce complexity", "make this more readable", "tech debt cleanup", "too much nesting".' metadata: version: 1.1.1 category: review tags: [refactoring, code-quality, simplification, readability] difficulty: intermediate phase: review
Code Refiner
A structured, multi-pass code refinement skill that transforms complex, verbose, or tangled code into clean, idiomatic, maintainable implementations — without changing what the code does.
Philosophy
The goal is **not** fewer lines. The goal is code that a tired engineer at 2am can read, understand, and safely modify. Every change must pass three tests:
1. **Behavioral equivalence** — identical inputs produce identical outputs, side effects, and errors 2. **Cognitive load reduction** — a reader unfamiliar with the code understands it faster after the change 3. **Maintenance leverage** — the change makes future modifications easier, not harder
When clarity and brevity conflict, clarity wins. When idiom and explicitness conflict, consider the team's experience level. When DRY and locality conflict, prefer locality for code read more than modified.
Prerequisites
- **git** — used in Phase 1 for scope detection (`git diff`) when the user doesn't specify target files
- **Python 3.10+** — required to run `scripts/complexity_report.py` for quantitative complexity metrics
Workflow
Follow this sequence. Each phase builds on the previous one. Do not skip phases, but adapt depth to the scope of the request (a single function gets a lighter pass than a full module).
Phase 1: Reconnaissance
Before touching anything, build a mental model:
1. **Identify scope** — What files/functions are in play? If the user hasn't specified, check recent git modifications: `git diff --name-only HEAD~5` or `git diff --staged --name-only` 2. **Detect language and ecosystem** — Read file extensions, imports, config files (package.json, pyproject.toml, go.mod, Cargo.toml). Load the appropriate language reference from `references/` if needed for idiom-specific guidance 3. **Read project conventions** — Check for CLAUDE.md, .editorconfig, linter configs (eslint, ruff, golangci-lint, clippy). These override generic idiom preferences 4. **Understand test coverage** — Locate test files. If tests exist, note the test runner so you can verify behavioral equivalence after changes 5. **Baseline complexity snapshot** — For each target function/method, mentally note:
- Nesting depth (max indentation levels)
- Number of branches (if/else/match/switch arms)
- Number of early returns vs single-exit
- Parameter count
- Lines of code
- Number of responsibilities (does it do more than one thing?)
Phase 2: Structural Analysis
Identify what's actually wrong before reaching for solutions. Categorize issues by severity:
**Critical** (always fix):
- Dead code (unreachable branches, unused variables/imports)
- Redundant operations (double-checking the same condition, re-computing cached values)
- Logic that can be replaced by a stdlib/language built-in
- Mutation of shared state that could be avoided
**High** (fix unless there's a clear reason not to):
- Functions with >3 levels of nesting
- Functions with >5 parameters
- God functions (>40 lines or >3 responsibilities)
- Repeated code blocks (3+ occurrences of similar logic)
- Inverted or confusing boolean logic
- Stringly-typed enumerations
**Medium** (fix when it improves clarity without adding risk):
- Unclear variable/function names
- Missing or misleading type annotations
- Unnecessary intermediate variables
- Over-abstraction (wrappers that add no value)
- Comments that restate the code instead of explaining _why_
**Low** (fix only in a dedicated cleanup pass):
- Inconsistent formatting (defer to linter)
- Import ordering
- Trailing whitespace, line length
Phase 3: Refactoring Execution
Apply changes using these tactics, ordered by impact-to-risk ratio:
3a. Eliminate Dead Weight
Remove before restructuring. Less code = less to think about.
- Delete unused imports, variables, functions
- Remove unreachable branches (but verify they're truly unreachable)
- Strip comments that restate the obvious (keep comments that explain _why_)
- Remove no-op wrapper functions that just forward calls
3b. Flatten Structure
Reduce nesting and cognitive load:
- **Guard clauses**: Convert deep `if` nesting to early returns
- **Extract conditions**: Name complex boolean expressions (`is_valid_order = ...`)
- **Decompose loops**: If a loop does filter + transform + accumulate, break it apart
(or use language-appropriate constructs: list comprehensions, iterators, streams)
- **Invert conditionals**: When the `else` branch is the "happy path", flip it
3c. Consolidate and Name
Make the code's intent visible:
- **Extract functions** for repeated logic or distinct responsibilities
- Name by _what it accomplishes_, not _how it works_
- Functions should do one thing at one level of abstraction
- **Replace magic values** with named constants
- **Rename for intent**: `data` → `user_records`, `process` → `validate_and_enqueue`
- **Group related parameters** into a config/options struct when count > 3
3d. Leverage Language Idioms
Apply language-specific patterns (consult `references/<language>.md` for details):
- Python: comprehensions, context managers, dataclasses, structural pattern matching
- Go: table-driven tests, error wrapping, functional options, interface satisfaction
- TypeScript: discriminated unions, branded types, const assertions, satisfies
- Rust: iterator chains, `?` operator, From/Into, newtype pattern
3e. Tighten Types
Types are documentation that the compiler checks:
- Add return
Curated, production-grade skills, agents, hooks, rules, commands, utilities, and presets for AI coding agents. No magic, no demos — battle-tested workflows built for developers who use AI seriously.
Repo: Mathews-Tom/armory
Other skills on armory.
- /adr-writer
Generates Architecture Decision Records capturing context, rationale, alternatives, and consequences in numbered status-tracked format. Triggers on: "write an ADR", "document this decision", "architecture decision record", "decision record", "design decision", "ADR for".
Open skill - /agent-builder
Build AI agents and automate Claude Code programmatically via the Claude Agent SDK and headless CLI mode. Covers Python SDK, claude -p, SDK MCP servers, hooks, sessions. Triggers on: "build an agent", "agent SDK", "headless mode", "automate Claude", "programmatic agent".
Open skill - /api-docs-generator
Audits and enhances FastAPI and REST API documentation: missing descriptions, response codes, examples, docstrings, Pydantic models, OpenAPI spec. Triggers on: "generate API docs", "document this API", "OpenAPI for", "FastAPI docs", "document endpoints", "swagger docs".
Open skill - /architecture-diagram
Generate layered architecture diagrams as self-contained HTML with inline SVG icons, CSS Grid containers, and connection overlays. Triggers on: "architecture diagram", "infra diagram", "system diagram", "deployment diagram", "topology", "draw architecture". NOT for architecture
Open skill - /architecture-reviewer
Architecture reviews across 7 dimensions (structural, scalability, enterprise readiness, performance, security, ops, data) with scored reports. Triggers on: "review architecture", "critique design", "audit system", "assess scalability", "enterprise readiness", "technical due
Open skill - /arxiv-figures
Optimize and prepare figures for arXiv submission: format conversion (EPS/PDF/PNG/JPG), size reduction, metadata stripping, processor compatibility (DVI vs PDFLaTeX). Triggers on: "optimize figures for arXiv", "reduce figure size", "convert figures for arXiv", "fix arXiv
Open skill

