Agent skill

Code Refiner

by Mathews-Tom in Mathews-Tom/armory

Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust.

MITAuto-check passedDevelopment

Install Code Refiner

skills CLI
$ npx skills add Mathews-Tom/armory --skill code-refiner -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Mathews-Tom/armory code-refiner --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Mathews-Tom/armory.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/code-refiner .claude/skills/code-refiner && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
code-refiner
GitHub stars
327
Token cost
~3.1k tokens
SKILL.md length
1,479 words
Files
7 (incl. scripts, references)
Skills in repo
80
Repo updated
First seen
Licence
MIT

At a glance

Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust.

  • Works in 5 steps: Reconnaissance → Structural Analysis → Refactoring Execution → …
  • : simplify this code
  • SKILL.md covers Philosophy, Prerequisites, Workflow and Behavioral Constraints, plus 6 more sections
  • Runs Python scripts from its folder; calls git, ruff and mypy

What it does

Code Refiner is an agent skill from Mathews-Tom/armory. 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".

Its SKILL.md is about 3.1k tokens, which your agent loads only when the skill is triggered. The skill folder holds 9 other files, including scripts and reference files (for example `evals/cases.yaml`, `references/go.md` and `references/python.md`).

It sits in Development, covering Code simplification, Refactoring and Technical debt. It works with Python, Rust, TypeScript and Git. The repository describes itself as: Curated, production-grade skills for AI coding agents. Battle-tested workflows for developers who use AI seriously. The licence is MIT.

When your agent uses it

  • : simplify this code
  • Refactor for clarity
  • Reduce complexity
  • Make this more readable

Example prompts

  • “simplify this code”
  • “refactor for clarity”
  • “reduce complexity”
  • “/code-refiner”

Requirements

  • Python 3

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Reconnaissance
  2. Structural Analysis
  3. Refactoring Execution
  4. Verification
  5. Report

What it can do on your machine

Read from SKILL.md and the folder at commit 4594fb7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • git
    • ruff
    • mypy
    • tsc

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Code Refiner loads about 3.1k tokens when it runs, and up to ~8.5k if it reads all its reference files. Until then it costs about 78 tokens; SKILL.md has 1,479 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~78
When it runs · the whole SKILL.md, loaded when a task matches
~3.1k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~8.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from Mathews-Tom/armory at commit 4594fb7, republished under its MIT licence (© Mathews-Tom). 1,479 words, ~3,115 tokens.

Download SKILL.mdSave it as .claude/skills/code-refiner/SKILL.md (or your agent's skills folder). This skill also uses 6 other files; get the full folder from GitHub.
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
metadata.category
review
metadata.tags
refactoring, code-quality, simplification, readability
metadata.difficulty
intermediate
metadata.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 type annotations to public functions
  • Replace stringly-typed parameters with enums/unions
  • Narrow any/interface{} to specific types where possible
  • Use branded/newtype patterns for identifiers that shouldn't be confused
Phase 4: Verification

Never skip this phase. Simplification that breaks behavior is not simplification.

  1. Run existing tests — If a test suite exists, run it. Report pass/fail.
  2. Run linter/type checker — If configured, run it. Fix new violations your changes introduced.
  3. Manual trace — For each refactored function, mentally trace one happy-path and one error-path input through the old and new code. Confirm identical behavior.
  4. Side effect audit — If the original code had side effects (I/O, mutation, logging), verify the new code preserves them in the same order and conditions.

If tests fail or behavior diverges: revert the specific change, don't try to fix the test.

Phase 5: Report

Present changes as a structured summary. This is important — the developer needs to understand and trust what changed before committing.

For each file modified, provide:

text
## <filename>

### Changes
- [Critical] Removed unreachable error branch in `parse_config` (dead code after L42 guard)
- [High] Extracted `validate_credentials()` from 60-line `handle_login()` (was 3 responsibilities)
- [Medium] Renamed `d` → `document`, `proc` → `process_batch`

### Complexity Delta
- `handle_login`: 4 levels nesting → 2, 8 branches → 5
- `parse_config`: removed 12 lines of dead code

### Risk Assessment
- Low risk: all changes are structural, no logic modifications
- Tests: 47/47 passing

Adjust verbosity to scope. Single-function cleanup gets a one-liner. Multi-file refactor gets the full report.

Show full SKILL.md (597 more words)Show less

Behavioral Constraints

These are hard rules. Do not violate them regardless of how much cleaner the code would look:

  1. Never change observable behavior — This includes error messages, log output, return values, side effect ordering, and exception types
  2. Never remove error handling — Even if it looks redundant. Defensive code often exists for a reason you can't see from the code alone
  3. Never introduce new dependencies — Simplification adds nothing to the dependency tree
  4. Never refactor code outside the specified scope — Unless the user explicitly asks for a broader pass. Resist the urge to "fix one more thing"
  5. Preserve public API surfaces — Function signatures, export names, and type definitions visible to consumers do not change without explicit user approval
  6. Respect existing tests — If a test asserts specific behavior, that behavior is a requirement, even if it seems wrong. Flag it in the report, don't change it

Configuring Scope and Aggressiveness

The user may specify different modes. If they don't, default to standard.

ModeScopeSeverity ThresholdTest Requirement
quickSingle file or functionCritical + High onlyTests recommended
standardRecent git changesCritical + High + MediumTests required if they exist
deepEntire module/packageAll severitiesTests mandatory
surgicalUser-specified lines/functionsAll severitiesManual trace sufficient

The user can specify mode by saying things like "just do a quick pass" or "deep clean this module".

When NOT to Refine

Push back (politely) if:

  • The code has no tests and the user wants a deep refactor → suggest writing tests first
  • The code is auto-generated (protobuf, OpenAPI, ORM models) → suggest modifying the generator
  • The request is really a feature change disguised as "cleanup" → clarify intent
  • The code is in a hot path and "simplification" would introduce allocation/copies → flag the tradeoff

Language References

For language-specific idiom guidance, read the appropriate reference file:

  • references/python.md — Python-specific patterns, anti-patterns, and stdlib alternatives
  • references/go.md — Go idioms, error handling patterns, and interface design
  • references/typescript.md — TypeScript/JavaScript patterns, type narrowing, and module design
  • references/rust.md — Rust idioms, ownership patterns, and iterator usage

Only load the reference file for the language(s) in the current scope. These provide detailed pattern catalogs that supplement the general methodology above.

Rationalizations

RationalizationReality
"It's readable enough""Enough" is not a standard — if the next developer needs to re-read a function 3 times, it's not readable
"Refactoring risks regressions"Not refactoring risks accumulating debt — run the test suite before and after, that's what tests are for
"This is how the codebase has always done it"Consistency with a bad pattern is still bad — improve incrementally, don't preserve anti-patterns
"The performance might get worse"Benchmark before and after — most readability refactors have zero performance impact; premature optimization is the root of all evil
"It's not broken, don't fix it"Refining isn't fixing — it's making working code maintainable, testable, and understandable for the next person
"I'll refactor the whole module later"Incremental refinement works; big-bang rewrites fail — improve what you touch now

Red Flags

  • Changing behavior while claiming "just a refactor" — refining must preserve all existing behavior
  • Touching code outside the declared scope without justification
  • Removing error handling or validation during simplification
  • Introducing new abstractions for one-time operations
  • Refactoring without running the test suite before and after
  • Making style changes to code that wasn't part of the original task

Verification

  • All existing tests pass before and after refinement
  • No behavioral changes — output/side-effects identical for all inputs
  • Changes stay within declared scope — no drive-by edits to unrelated code
  • Cyclomatic complexity reduced or unchanged — never increased
  • No new abstractions introduced for single-use cases
  • Linter and type checker pass: ruff check + mypy --strict or tsc --noEmit + eslint

© Mathews-Tom, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 6 other files (scripts, references) in skills/code-refiner of Mathews-Tom/armory.

  • SKILL.md
  • evals/cases.yaml
  • references/go.md
  • references/python.md
  • references/rust.md
  • references/typescript.md
  • scripts/complexity_report.py

Open the folder on GitHubat commit 4594fb7

Compare with similar skills

Code Refiner next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Code Refiner compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Code Refiner this skillMathews-Tom/armory327—~3.1kAutomated safety check: PassMIT
DRY Refactoring With jscpdkucherenko/jscpd6.3k—~2.1kAutomated safety check: PassMIT
Coding Agentmastra-ai/mastra29k—~2.3kAutomated safety check: PassCustom licence
Dead Code Removal with Knipshift-editor/shift343—~1.8kAutomated safety check: PassApache-2.0
Project Initathola/claude-night-market342—~1.2kAutomated safety check: PassMIT
Worklog Designregisx001/Worklog258—~3.3kAutomated safety check: PassMIT

Similar skills

  • Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.

    6.3k GitHub stars~2.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Coding Agent

    mastra-ai/mastra

    Authoring playbook for building agents that write, edit, review, or refactor code.

    29k GitHub stars~2.3k tokensUpdated today
    DevelopmentAuto-check passed
  • Dead Code Removal with Knip

    shift-editor/shift

    Finds unused files, exports and class members with Knip, then verifies each candidate through reference tracing before removing anything, never using knip --fix.

    343 GitHub stars~1.8k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Project Init

    athola/claude-night-market

    Scaffolds new projects with git, CI/CD workflows, pre-commit hooks, and build config.

    342 GitHub stars~1.2k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Worklog Design

    regisx001/Worklog

    Design and UI skill for the Worklog desktop project manager.

    258 GitHub stars~3.3k tokensUpdated 1 mo ago
    Frontend & DesignAuto-check passed
  • Code Review Checklist

    shareAI-lab/learn-claude-code

    Reviews code against a five-part checklist covering security, correctness, performance, maintainability and testing, and reports findings in a fixed format.

    78k GitHub starsUsed in 5 repos~1.1k tokens
    DevelopmentAuto-check passed

More from Mathews-Tom/armory

All 80 skills in this repo
  • Architecture Reviewer

    Mathews-Tom/armory

    Architecture reviews across 7 dimensions (structural, scalability, enterprise readiness, performance, security, ops, data) with scored reports.

    327 GitHub stars~4.6k tokensUpdated yesterday
    Auto-check passed
  • Concept To Image

    Mathews-Tom/armory

    Turn concepts into static HTML visuals exported as PNG or SVG files via HTML/CSS/SVG.

    327 GitHub stars~2.6k tokensUpdated yesterday
    Auto-check passed
  • Watch

    Mathews-Tom/armory

    A skill your agent uses when analyzing an existing video URL or local recording: "watch this video", "analyze youtube video", "summarize this video", "youtube transcript", "find this moment", "what…

    327 GitHub stars~2.8k tokensUpdated yesterday
    Auto-check passed
  • Concept To Video

    Mathews-Tom/armory

    Turn concepts into animated explainer videos using Manim (Python) with MP4/GIF output, audio overlay, multi-scene composition.

    327 GitHub stars~4.9k tokensUpdated yesterday
    Auto-check passed
  • Decision Map

    Mathews-Tom/armory

    Maps the unresolved architecture, policy, and scope decisions that must be answered before planning can start: one durable decision ticket per question on the issue tracker, typed and blocker-linked…

    327 GitHub stars~2.7k tokensUpdated yesterday
    Auto-check passed
  • Handoff

    Mathews-Tom/armory

    Produces and refreshes .docs/handoff.md, a 200-line session-continuity runbook for coding agents.

    327 GitHub stars~1.7k tokensUpdated yesterday
    Auto-check passed

Categories

Questions about Code Refiner

What does Code Refiner do?

Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Code Refiner is an agent skill from Mathews-Tom/armory. Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust.

When should I use Code Refiner?

Code Refiner fits situations like: : simplify this code; refactor for clarity; reduce complexity; make this more readable.

How do I install Code Refiner in Claude Code?

Run `npx skills add Mathews-Tom/armory --skill code-refiner -a claude-code`. Or copy the skill folder (skills/code-refiner in Mathews-Tom/armory) into .claude/skills/code-refiner in your project. Claude Code loads it when a task matches its description.

How do I install Code Refiner in Codex?

Run `npx skills add Mathews-Tom/armory --skill code-refiner -a codex`. Or copy the skill folder (skills/code-refiner in Mathews-Tom/armory) into .agents/skills/code-refiner in your project. Codex loads it when a task matches its description.

Can I use Code Refiner in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Mathews-Tom/armory --skill code-refiner -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/code-refiner, .gemini/skills/code-refiner, .github/skills/code-refiner and .opencode/skills/code-refiner in your project.

What does Code Refiner need to run?

Going by SKILL.md and its folder, Code Refiner needs Python for the scripts in its folder and the command-line tools its instructions call (git, ruff, mypy and tsc). Our summary lists: Python 3.

Does Code Refiner access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Code Refiner safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Code Refiner use?

Code Refiner is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Code Refiner use?

About 3.1k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 5.3k tokens, read only when the agent opens those files.

What are the alternatives to Code Refiner?

Skills that share tags, products or a category with Code Refiner: DRY Refactoring With jscpd (kucherenko/jscpd, 6.3k stars), Coding Agent (mastra-ai/mastra, 29k stars), Dead Code Removal with Knip (shift-editor/shift, 343 stars) and Project Init (athola/claude-night-market, 342 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Code Refiner?

Mathews-Tom (a GitHub user) maintains it in Mathews-Tom/armory, which has 327 GitHub stars. The repository holds 80 skills in this directory. The repository was last updated on October 6, 2026.

Source: Mathews-Tom/armory on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.